import { type MessageWithState, useDevice } from "@core/stores/deviceStore.ts"; import { Message } from "@components/PageComponents/Messages/Message.tsx"; import { MessageInput } from "@components/PageComponents/Messages/MessageInput.tsx"; import type { Types } from "@meshtastic/core"; import { InboxIcon } from "lucide-react"; import { useCallback, useEffect, useRef } from "react"; export interface ChannelChatProps { messages?: MessageWithState[]; channel: Types.ChannelNumber; to: Types.Destination; } const EmptyState = () => (
No Messages
); export const ChannelChat = ({ messages, channel, to, }: ChannelChatProps) => { const { nodes } = useDevice(); const messagesEndRef = useRef(null); const scrollContainerRef = useRef(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) { return (
); } return (
{messages.map((message, index) => { return ( 0 && messages[index - 1].from === message.from} /> ); })}
); };