From 4135080b802064a0c09de4389c041141d1ece45f Mon Sep 17 00:00:00 2001 From: FanisNgv Date: Wed, 11 Sep 2024 15:09:40 +0300 Subject: [PATCH 1/2] routing stuff --- frontend/src/app/components/MessageList.tsx | 2 +- frontend/src/app/components/Sidebar.tsx | 132 +++++---- frontend/src/app/page.tsx | 285 +------------------- 3 files changed, 94 insertions(+), 325 deletions(-) diff --git a/frontend/src/app/components/MessageList.tsx b/frontend/src/app/components/MessageList.tsx index 0b19a71..99f9dcc 100644 --- a/frontend/src/app/components/MessageList.tsx +++ b/frontend/src/app/components/MessageList.tsx @@ -14,7 +14,7 @@ type MessageListProps = { export default function MessageList({ messages }: MessageListProps) { return ( - + {messages.map((msg) => ( }; + messages: Array<{ id: number; text: string; sender: string }>; +}; type SidebarProps = { conversations: Conversation[]; @@ -19,9 +19,79 @@ type SidebarProps = { onCloseSidebar: () => void; }; +type ConversationItemProps = { + conversation: Conversation; + isActive: boolean; + onConversationChange: (id: number) => void; + onDeleteConversation: (id: number) => void; +}; + +const ConversationItem = React.memo(({ conversation, isActive, onConversationChange, onDeleteConversation }: ConversationItemProps) => { + return ( + + { + e.preventDefault(); + onConversationChange(conversation.id); + }} + > + + + + ); +}); + export default function Sidebar({ conversations, currentConversationId, onConversationChange, onAddConversation, onDeleteConversation, isSidebarOpen, onCloseSidebar }: SidebarProps) { const menuRef = useRef(null); + const handleConversationChange = useCallback((id: number) => { + onConversationChange(id); + }, [onConversationChange]); + + const handleDeleteConversation = useCallback((id: number) => { + onDeleteConversation(id); + }, [onDeleteConversation]); + return (