diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index fbdd61b9..9f41e80e 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -11,6 +11,7 @@ import { deleteChatById, getChatList, + getChatById, getChatListByTagName, updateChatById } from '$lib/apis/chats'; @@ -31,16 +32,24 @@ if (window.innerWidth > 1280) { show = true; } - await chats.set(await getChatList(localStorage.token)); - - tags.subscribe(async (value) => { - if (value.length === 0) { - await chats.set(await getChatList(localStorage.token)); - } - }); }); + // Helper function to fetch and add chat content to each chat + const enrichChatsWithContent = async (chatList) => { + const enrichedChats = await Promise.all( + chatList.map(async (chat) => { + const chatDetails = await getChatById(localStorage.token, chat.id).catch((error) => null); // Handle error or non-existent chat gracefully + if (chatDetails) { + chat.chat = chatDetails.chat; // Assuming chatDetails.chat contains the chat content + } + return chat; + }) + ); + + await chats.set(enrichedChats); + }; + const loadChat = async (id) => { goto(`/c/${id}`); }; @@ -271,6 +280,9 @@ class="w-full rounded-r py-1.5 pl-2.5 pr-4 text-sm text-gray-300 bg-gray-950 outline-none" placeholder="Search" bind:value={search} + on:focus={() => { + enrichChatsWithContent($chats); + }} />