Browse Source

fix: styling fixes from code review

pull/390/head
Dan Ditomaso 1 year ago
parent
commit
1c7b466e64
  1. 15
      src/components/PageComponents/Messages/ChannelChat.tsx
  2. 143
      src/components/PageComponents/Messages/Message.tsx
  3. 2
      src/components/PageLayout.tsx

15
src/components/PageComponents/Messages/ChannelChat.tsx

@ -39,7 +39,6 @@ export const ChannelChat = ({
scrollContainer.scrollTop - scrollContainer.scrollTop -
scrollContainer.clientHeight < scrollContainer.clientHeight <
100; 100;
if (isNearBottom) { if (isNearBottom) {
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
} }
@ -52,8 +51,8 @@ export const ChannelChat = ({
if (!messages?.length) { if (!messages?.length) {
return ( return (
<div className="flex flex-col h-full"> <div className="flex flex-col h-full w-full">
<div className="flex-1 flex items-center justify-center overflow-y-auto"> <div className="flex-1 flex items-center justify-center">
<EmptyState /> <EmptyState />
</div> </div>
<div className="flex-shrink-0 p-4 w-full bg-gray-900"> <div className="flex-shrink-0 p-4 w-full bg-gray-900">
@ -64,9 +63,9 @@ export const ChannelChat = ({
} }
return ( return (
<div className="flex flex-col h-full"> <div className="flex flex-col h-full w-full">
<div className="flex-1 overflow-y-auto" ref={scrollContainerRef}> <div className="flex-1 overflow-y-scroll w-full" ref={scrollContainerRef}>
<div className="w-full min-h-full flex flex-col justify-end"> <div className="w-full h-full flex flex-col justify-end">
{messages.map((message, index) => ( {messages.map((message, index) => (
<Message <Message
key={message.id} key={message.id}
@ -77,10 +76,10 @@ export const ChannelChat = ({
sender={nodes.get(message.from)} sender={nodes.get(message.from)}
/> />
))} ))}
<div ref={messagesEndRef} /> <div ref={messagesEndRef} className="w-full" />
</div> </div>
</div> </div>
<div className="flex-shrink-0 p-4 w-full bg-gray-900"> <div className="flex-shrink-0 mt-2 p-4 w-full bg-gray-900">
<MessageInput to={to} channel={channel} /> <MessageInput to={to} channel={channel} />
</div> </div>
</div> </div>

143
src/components/PageComponents/Messages/Message.tsx

@ -4,28 +4,45 @@ 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";
import { AlertCircle, CheckCircle2, CircleEllipsis } from "lucide-react"; import { AlertCircle, CheckCircle2, CircleEllipsis } from "lucide-react";
import type { LucideIcon } from "lucide-react";
export interface MessageProps { const MESSAGE_STATES = {
ACK: "ack",
WAITING: "waiting",
FAILED: "failed",
} as const;
type MessageState = MessageWithState["state"];
interface MessageProps {
lastMsgSameUser: boolean; lastMsgSameUser: boolean;
message: MessageWithState; message: MessageWithState;
sender?: Protobuf.Mesh.NodeInfo; sender?: Protobuf.Mesh.NodeInfo;
} }
interface StatusTooltipProps { interface StatusTooltipProps {
state: MessageWithState["state"]; state: MessageState;
children: React.ReactNode; children: React.ReactNode;
} }
const getStatusText = (state: MessageWithState["state"]): string => { interface StatusIconProps {
switch (state) { state: MessageState;
case "ack": className?: string;
return "Message delivered"; }
case "waiting":
return "Waiting for delivery"; const STATUS_TEXT_MAP: Record<MessageState, string> = {
default: [MESSAGE_STATES.ACK]: "Message delivered",
return "Delivery failed"; [MESSAGE_STATES.WAITING]: "Waiting for delivery",
} [MESSAGE_STATES.FAILED]: "Delivery failed",
}; } as const;
const STATUS_ICON_MAP: Record<MessageState, LucideIcon> = {
[MESSAGE_STATES.ACK]: CheckCircle2,
[MESSAGE_STATES.WAITING]: CircleEllipsis,
[MESSAGE_STATES.FAILED]: AlertCircle,
} as const;
const getStatusText = (state: MessageState): string => STATUS_TEXT_MAP[state];
const StatusTooltip = ({ state, children }: StatusTooltipProps) => ( const StatusTooltip = ({ state, children }: StatusTooltipProps) => (
<Tooltip.Provider> <Tooltip.Provider>
@ -46,78 +63,92 @@ const StatusTooltip = ({ state, children }: StatusTooltipProps) => (
</Tooltip.Provider> </Tooltip.Provider>
); );
const StatusIcon = ({ const StatusIcon = ({ state, className, ...otherProps }: StatusIconProps) => {
state, const isFailed = state === MESSAGE_STATES.FAILED;
className,
}: { state: MessageWithState["state"]; className?: string }) => {
const iconClass = cn( const iconClass = cn(
className, className,
"text-gray-500 dark:text-gray-400 w-4 h-4 flex-shrink-0", "text-gray-500 dark:text-gray-400 w-4 h-4 flex-shrink-0",
); );
const Icon = (() => {
switch (state) { const Icon = STATUS_ICON_MAP[state];
case "ack":
return CheckCircle2;
case "waiting":
return CircleEllipsis;
default:
return AlertCircle;
}
})();
return ( return (
<StatusTooltip state={state}> <StatusTooltip state={state}>
<Icon className={iconClass} /> <Icon
className={iconClass}
{...otherProps}
color={isFailed ? "red" : "currentColor"}
/>
</StatusTooltip> </StatusTooltip>
); );
}; };
export const Message = ({ lastMsgSameUser, message, sender }: MessageProps) => { const getMessageTextStyles = (state: MessageState) => {
const messageTextClass = cn( const isAcknowledged = state === MESSAGE_STATES.ACK;
"border-l-2 pl-4 break-words min-w-0", const isFailed = state === MESSAGE_STATES.FAILED;
message.state === "ack" const isWaiting = state === MESSAGE_STATES.WAITING;
? "text-gray-900 dark:text-white"
: "text-gray-500 dark:text-gray-400", return cn(
lastMsgSameUser "pl-2 break-words overflow-hidden",
? "border-gray-600 dark:border-gray-700" isAcknowledged
: "border-gray-200 dark:border-gray-600", ? "text-black dark:text-white"
: "text-black dark:text-gray-400",
isFailed && "text-red-500 dark:text-red-500",
); );
};
const TimeDisplay = ({ date }: { date: Date }) => (
<div className="flex items-center gap-2 flex-shrink-0">
<span className="text-xs text-gray-500 dark:text-gray-400 font-mono">
{date.toLocaleDateString()}
</span>
<span className="text-xs text-gray-500 dark:text-gray-400 font-mono">
{date.toLocaleTimeString(undefined, {
hour: "2-digit",
minute: "2-digit",
})}
</span>
</div>
);
export const Message = ({ lastMsgSameUser, message, sender }: MessageProps) => {
const messageTextClass = getMessageTextStyles(message.state);
const isFailed = message.state === MESSAGE_STATES.ACK;
const baseMessageWrapper = cn( const baseMessageWrapper = cn(
"ml-12 flex items-start gap-2 w-full max-w-full", "flex items-center gap-2 w-full max-w-full pl-11",
lastMsgSameUser ? "mt-1" : "mt-4",
!lastMsgSameUser && "flex-wrap flex-grow", !lastMsgSameUser && "flex-wrap flex-grow",
); );
const containerClass = cn( const containerClass = cn(
"px-4 relative", "w-full px-4 relative",
lastMsgSameUser ? "mt-0" : "mt-2", lastMsgSameUser ? "mt-1" : "mt-2",
!lastMsgSameUser && "pt-2", !lastMsgSameUser && "pt-2",
); );
return ( return (
<div className={containerClass}> <div className={containerClass}>
{!lastMsgSameUser && ( {!lastMsgSameUser && (
<div className="flex items-center gap-2 mb-2"> <div className="flex flex-wrap items-center gap-x-2 gap-y-1">
<Avatar text={sender?.user?.shortName ?? "UNK"} /> <div className="flex items-center gap-2 min-w-0">
<span className="font-medium text-gray-900 dark:text-white"> <Avatar
{sender?.user?.longName ?? "UNK"} text={sender?.user?.shortName ?? "UNK"}
</span> className="flex-shrink-0"
<span className="text-xs text-gray-500 dark:text-gray-400 font-mono"> />
{message.rxTime.toLocaleDateString()} <span className="font-medium text-gray-900 dark:text-white truncate">
</span> {sender?.user?.longName ?? "UNK"}
<span className="text-xs text-gray-500 dark:text-gray-400 font-mono"> </span>
{message.rxTime.toLocaleTimeString(undefined, { </div>
hour: "2-digit", <TimeDisplay date={message.rxTime} />
minute: "2-digit",
})}
</span>
</div> </div>
)} )}
<div className={baseMessageWrapper}> <div className={baseMessageWrapper}>
<div className="flex-1 min-w-0"> <div className="flex-1 min-w-0 max-w-full">
<div className={messageTextClass}>{message.data}</div> <div className={messageTextClass}>{message.data}</div>
</div> </div>
<StatusIcon state={message.state} className="ml-auto" /> <StatusIcon
state={message.state}
className="ml-auto mr-6 flex-shrink-0"
/>
</div> </div>
</div> </div>
); );

2
src/components/PageLayout.tsx

@ -49,7 +49,7 @@ export const PageLayout = ({
</div> </div>
<div <div
className={cn( className={cn(
"flex h-full w-full flex-col overflow-y-auto", "flex h-full w-full flex-col",
!noPadding && "pl-3 pr-3 ", !noPadding && "pl-3 pr-3 ",
)} )}
> >

Loading…
Cancel
Save