From 7a36e7b7aa38cfc7f898b8827c527ae396b34f2c Mon Sep 17 00:00:00 2001 From: Zacharias-Brohn Date: Wed, 14 Jan 2026 22:56:58 +0100 Subject: [PATCH] changes --- components/Chat/ChatLayout.tsx | 120 +++++++++++++++++++++++++++++---- 1 file changed, 108 insertions(+), 12 deletions(-) diff --git a/components/Chat/ChatLayout.tsx b/components/Chat/ChatLayout.tsx index e8eafa1..485cfa4 100644 --- a/components/Chat/ChatLayout.tsx +++ b/components/Chat/ChatLayout.tsx @@ -65,6 +65,77 @@ interface Chat { pinned?: boolean; } +type TimeGroup = 'Today' | 'Yesterday' | 'This Week' | 'This Month' | 'Older'; + +interface GroupedChats { + pinned: Chat[]; + groups: { label: TimeGroup; chats: Chat[] }[]; +} + +/** + * Group chats by time period (Today, Yesterday, This Week, This Month, Older) + * Pinned chats are separated into their own section + */ +function groupChatsByTime(chats: Chat[]): GroupedChats { + const now = new Date(); + const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()); + const yesterday = new Date(today); + yesterday.setDate(yesterday.getDate() - 1); + const weekAgo = new Date(today); + weekAgo.setDate(weekAgo.getDate() - 7); + const monthAgo = new Date(today); + monthAgo.setMonth(monthAgo.getMonth() - 1); + + const pinned: Chat[] = []; + const todayChats: Chat[] = []; + const yesterdayChats: Chat[] = []; + const weekChats: Chat[] = []; + const monthChats: Chat[] = []; + const olderChats: Chat[] = []; + + for (const chat of chats) { + if (chat.pinned) { + pinned.push(chat); + continue; + } + + const chatDate = new Date(chat.updatedAt); + + if (chatDate >= today) { + todayChats.push(chat); + } else if (chatDate >= yesterday) { + yesterdayChats.push(chat); + } else if (chatDate >= weekAgo) { + weekChats.push(chat); + } else if (chatDate >= monthAgo) { + monthChats.push(chat); + } else { + olderChats.push(chat); + } + } + + // Build groups array, only including non-empty groups + const groups: { label: TimeGroup; chats: Chat[] }[] = []; + + if (todayChats.length > 0) { + groups.push({ label: 'Today', chats: todayChats }); + } + if (yesterdayChats.length > 0) { + groups.push({ label: 'Yesterday', chats: yesterdayChats }); + } + if (weekChats.length > 0) { + groups.push({ label: 'This Week', chats: weekChats }); + } + if (monthChats.length > 0) { + groups.push({ label: 'This Month', chats: monthChats }); + } + if (olderChats.length > 0) { + groups.push({ label: 'Older', chats: olderChats }); + } + + return { pinned, groups }; +} + export function InputWithButton(props: TextInputProps) { const theme = useMantineTheme(); @@ -609,7 +680,7 @@ export default function ChatLayout() { - History + Chats @@ -619,9 +690,11 @@ export default function ChatLayout() { - - {chats.length > 0 ? ( - chats.map((chat) => + {chats.length > 0 ? ( + (() => { + const { pinned, groups } = groupChatsByTime(chats); + + const renderChatItem = (chat: Chat) => editingChatId === chat.id ? ( // Inline editing mode - ) - ) - ) : ( - - {isLoadingChats ? 'Loading...' : 'No saved chats'} - - )} - + ); + + return ( + + {/* Pinned Section */} + {pinned.length > 0 && ( + + + Pinned + + {pinned.map(renderChatItem)} + + )} + + {/* Time-grouped History Sections */} + {groups.map((group) => ( + + + {group.label} + + {group.chats.map(renderChatItem)} + + ))} + + ); + })() + ) : ( + + {isLoadingChats ? 'Loading...' : 'No saved chats'} + + )}