fix: styling updates, chat conversation moved to bottom of chat window.
This commit is contained in:
@@ -6,6 +6,7 @@ import { Message } from "@components/PageComponents/Messages/Message.tsx";
|
|||||||
import { MessageInput } from "@components/PageComponents/Messages/MessageInput.tsx";
|
import { MessageInput } from "@components/PageComponents/Messages/MessageInput.tsx";
|
||||||
import type { Types } from "@meshtastic/js";
|
import type { Types } from "@meshtastic/js";
|
||||||
import { InboxIcon } from "lucide-react";
|
import { InboxIcon } from "lucide-react";
|
||||||
|
import { useCallback, useEffect, useRef } from "react";
|
||||||
import type { JSX } from "react";
|
import type { JSX } from "react";
|
||||||
|
|
||||||
export interface ChannelChatProps {
|
export interface ChannelChatProps {
|
||||||
@@ -27,24 +28,45 @@ export const ChannelChat = ({
|
|||||||
to,
|
to,
|
||||||
}: ChannelChatProps): JSX.Element => {
|
}: ChannelChatProps): JSX.Element => {
|
||||||
const { nodes } = useDevice();
|
const { nodes } = useDevice();
|
||||||
|
const messagesEndRef = useRef<HTMLDivElement>(null);
|
||||||
|
const scrollContainerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
const scrollToBottom = useCallback(() => {
|
||||||
|
const scrollContainer = scrollContainerRef.current;
|
||||||
|
if (scrollContainer) {
|
||||||
|
const isNearBottom =
|
||||||
|
scrollContainer.scrollHeight -
|
||||||
|
scrollContainer.scrollTop -
|
||||||
|
scrollContainer.clientHeight <
|
||||||
|
100;
|
||||||
|
|
||||||
|
if (isNearBottom) {
|
||||||
|
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
scrollToBottom();
|
||||||
|
}, [scrollToBottom]);
|
||||||
|
|
||||||
if (!messages?.length) {
|
if (!messages?.length) {
|
||||||
return (
|
return (
|
||||||
<>
|
<div className="flex flex-col h-full">
|
||||||
<div className="flex place-content-center place-items-center h-full">
|
<div className="flex-1 flex items-center justify-center overflow-y-auto">
|
||||||
<EmptyState />
|
<EmptyState />
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-auto pb-4 w-full">
|
<div className="flex-shrink-0 p-4 w-full bg-gray-900">
|
||||||
<MessageInput to={to} channel={channel} />
|
<MessageInput to={to} channel={channel} />
|
||||||
</div>
|
</div>
|
||||||
</>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div className="flex flex-col h-full">
|
||||||
<div className="flex flex-col h-full">
|
<div className="flex-1 overflow-y-auto" ref={scrollContainerRef}>
|
||||||
<div className="w-full">
|
<div className="w-full min-h-full flex flex-col justify-end">
|
||||||
{messages.map((message, index) => (
|
{messages.map((message, index) => (
|
||||||
<Message
|
<Message
|
||||||
key={message.id}
|
key={message.id}
|
||||||
@@ -55,11 +77,12 @@ export const ChannelChat = ({
|
|||||||
sender={nodes.get(message.from)}
|
sender={nodes.get(message.from)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
<div ref={messagesEndRef} />
|
||||||
<div className="mt-auto pb-4 w-full">
|
|
||||||
<MessageInput to={to} channel={channel} />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
<div className="flex-shrink-0 p-4 w-full bg-gray-900">
|
||||||
|
<MessageInput to={to} channel={channel} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { MessageWithState } from "@app/core/stores/deviceStore.ts";
|
import type { MessageWithState } from "@app/core/stores/deviceStore.ts";
|
||||||
|
import { cn } from "@app/core/utils/cn";
|
||||||
import { Avatar } from "@components/UI/Avatar";
|
import { Avatar } from "@components/UI/Avatar";
|
||||||
import type { Protobuf } from "@meshtastic/js";
|
import type { Protobuf } from "@meshtastic/js";
|
||||||
import * as Tooltip from "@radix-ui/react-tooltip";
|
import * as Tooltip from "@radix-ui/react-tooltip";
|
||||||
@@ -45,8 +46,14 @@ const StatusTooltip = ({ state, children }: StatusTooltipProps) => (
|
|||||||
</Tooltip.Provider>
|
</Tooltip.Provider>
|
||||||
);
|
);
|
||||||
|
|
||||||
const StatusIcon = ({ state }: { state: MessageWithState["state"] }) => {
|
const StatusIcon = ({
|
||||||
const iconClass = "text-gray-500 dark:text-gray-400 w-4 h-4";
|
state,
|
||||||
|
className,
|
||||||
|
}: { state: MessageWithState["state"]; className?: string }) => {
|
||||||
|
const iconClass = cn(
|
||||||
|
className,
|
||||||
|
"text-gray-500 dark:text-gray-400 w-4 h-4 flex-shrink-0",
|
||||||
|
);
|
||||||
const Icon = (() => {
|
const Icon = (() => {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case "ack":
|
case "ack":
|
||||||
@@ -57,7 +64,6 @@ const StatusIcon = ({ state }: { state: MessageWithState["state"] }) => {
|
|||||||
return AlertCircle;
|
return AlertCircle;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StatusTooltip state={state}>
|
<StatusTooltip state={state}>
|
||||||
<Icon className={iconClass} />
|
<Icon className={iconClass} />
|
||||||
@@ -66,50 +72,52 @@ const StatusIcon = ({ state }: { state: MessageWithState["state"] }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const Message = ({ lastMsgSameUser, message, sender }: MessageProps) => {
|
export const Message = ({ lastMsgSameUser, message, sender }: MessageProps) => {
|
||||||
const messageTextClass =
|
const messageTextClass = cn(
|
||||||
|
"border-l-2 pl-4 break-words min-w-0",
|
||||||
message.state === "ack"
|
message.state === "ack"
|
||||||
? "text-gray-900 dark:text-white"
|
? "text-gray-900 dark:text-white"
|
||||||
: "text-gray-500 dark:text-gray-400";
|
: "text-gray-500 dark:text-gray-400",
|
||||||
|
lastMsgSameUser
|
||||||
|
? "border-gray-600 dark:border-gray-700"
|
||||||
|
: "border-gray-200 dark:border-gray-600",
|
||||||
|
);
|
||||||
|
|
||||||
if (lastMsgSameUser) {
|
const baseMessageWrapper = cn(
|
||||||
return (
|
"ml-12 flex items-start gap-2 w-full max-w-full",
|
||||||
<div className="mx-4 mt-2">
|
lastMsgSameUser ? "mt-1" : "mt-4",
|
||||||
<div className="ml-12 flex items-start gap-2">
|
!lastMsgSameUser && "flex-wrap flex-grow",
|
||||||
<div
|
);
|
||||||
className={`${messageTextClass} border-l-2 border-gray-200 dark:border-gray-700 pl-4 flex-grow`}
|
|
||||||
>
|
const containerClass = cn(
|
||||||
{message.data}
|
"px-4 relative",
|
||||||
</div>
|
lastMsgSameUser ? "mt-0" : "mt-2",
|
||||||
<StatusIcon state={message.state} />
|
!lastMsgSameUser && "pt-2",
|
||||||
</div>
|
);
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-4 mt-2 space-y-2">
|
<div className={containerClass}>
|
||||||
<div className="flex items-center gap-2">
|
{!lastMsgSameUser && (
|
||||||
<Avatar text={sender?.user?.shortName ?? "UNK"} />
|
<div className="flex items-center gap-2 mb-2">
|
||||||
<span className="font-medium text-gray-900 dark:text-white">
|
<Avatar text={sender?.user?.shortName ?? "UNK"} />
|
||||||
{sender?.user?.longName ?? "UNK"}
|
<span className="font-medium text-gray-900 dark:text-white">
|
||||||
</span>
|
{sender?.user?.longName ?? "UNK"}
|
||||||
<span className="text-xs text-gray-500 dark:text-gray-400 font-mono">
|
</span>
|
||||||
{message.rxTime.toLocaleDateString()}
|
<span className="text-xs text-gray-500 dark:text-gray-400 font-mono">
|
||||||
</span>
|
{message.rxTime.toLocaleDateString()}
|
||||||
<span className="text-xs text-gray-500 dark:text-gray-400 font-mono">
|
</span>
|
||||||
{message.rxTime.toLocaleTimeString(undefined, {
|
<span className="text-xs text-gray-500 dark:text-gray-400 font-mono">
|
||||||
hour: "2-digit",
|
{message.rxTime.toLocaleTimeString(undefined, {
|
||||||
minute: "2-digit",
|
hour: "2-digit",
|
||||||
})}
|
minute: "2-digit",
|
||||||
</span>
|
})}
|
||||||
</div>
|
</span>
|
||||||
<div className="ml-12 flex items-start gap-2">
|
|
||||||
<div
|
|
||||||
className={`${messageTextClass} border-l-2 border-gray-200 dark:border-gray-700 pl-4 flex-grow`}
|
|
||||||
>
|
|
||||||
{message.data}
|
|
||||||
</div>
|
</div>
|
||||||
<StatusIcon state={message.state} />
|
)}
|
||||||
|
<div className={baseMessageWrapper}>
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
<div className={messageTextClass}>{message.data}</div>
|
||||||
|
</div>
|
||||||
|
<StatusIcon state={message.state} className="ml-auto" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user