From 3ec1efb6e05bfd764e0cb435ac2703a21e247308 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 15 Sep 2025 18:33:57 -0500 Subject: [PATCH] refac: folders --- .../components/chat/Messages/CodeBlock.svelte | 24 +- .../Messages/Markdown/MarkdownTokens.svelte | 2 +- src/lib/components/chat/Navbar.svelte | 2 +- src/lib/components/common/Folder.svelte | 15 +- src/lib/components/layout/Sidebar.svelte | 214 +++++++++--------- .../layout/Sidebar/RecursiveFolder.svelte | 12 +- 6 files changed, 138 insertions(+), 131 deletions(-) diff --git a/src/lib/components/chat/Messages/CodeBlock.svelte b/src/lib/components/chat/Messages/CodeBlock.svelte index 05f698b787..08ce93ecea 100644 --- a/src/lib/components/chat/Messages/CodeBlock.svelte +++ b/src/lib/components/chat/Messages/CodeBlock.svelte @@ -432,15 +432,17 @@ {/if} {:else}
-
- {lang} -
+ {lang} +
+
{#if preview && ['html', 'svg'].includes(lang)} diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 3e72f0a23e..bbb8c501fa 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -871,14 +871,42 @@ {/if} + {#if folders} + { + showCreateFolderModal = true; + }} + onAddLabel={$i18n.t('New Folder')} + > + { + selectedFolder.set(null); + initChatList(); + }} + on:update={() => { + initChatList(); + }} + on:import={(e) => { + const { folderId, items } = e.detail; + importChatHandler(items, false, folderId); + }} + on:change={async () => { + initChatList(); + }} + /> + + {/if} + { - showCreateFolderModal = true; - }} - onAddLabel={$i18n.t('New Folder')} on:change={async (e) => { selectedFolder.set(null); await goto('/'); @@ -940,115 +968,89 @@ } }} > - {#if folders || $pinnedChats.length > 0} + {#if $pinnedChats.length > 0}
- {#if folders} - { - selectedFolder.set(null); - initChatList(); - }} - on:update={() => { - initChatList(); +
+ { + localStorage.setItem('showPinnedChat', e.detail); + console.log(e.detail); }} on:import={(e) => { - const { folderId, items } = e.detail; - importChatHandler(items, false, folderId); + importChatHandler(e.detail, true); }} - on:change={async () => { - initChatList(); - }} - /> - {/if} + on:drop={async (e) => { + const { type, id, item } = e.detail; - {#if $pinnedChats.length > 0} -
- { - localStorage.setItem('showPinnedChat', e.detail); - console.log(e.detail); - }} - on:import={(e) => { - importChatHandler(e.detail, true); - }} - on:drop={async (e) => { - const { type, id, item } = e.detail; - - if (type === 'chat') { - let chat = await getChatById(localStorage.token, id).catch((error) => { - return null; - }); - if (!chat && item) { - chat = await importChat( - localStorage.token, - item.chat, - item?.meta ?? {}, - false, - null, - item?.created_at ?? null, - item?.updated_at ?? null - ); - } - - if (chat) { - console.log(chat); - if (chat.folder_id) { - const res = await updateChatFolderIdById( - localStorage.token, - chat.id, - null - ).catch((error) => { - toast.error(`${error}`); - return null; - }); - } - - if (!chat.pinned) { - const res = await toggleChatPinnedStatusById( - localStorage.token, - chat.id - ); - } - - initChatList(); - } + if (type === 'chat') { + let chat = await getChatById(localStorage.token, id).catch((error) => { + return null; + }); + if (!chat && item) { + chat = await importChat( + localStorage.token, + item.chat, + item?.meta ?? {}, + false, + null, + item?.created_at ?? null, + item?.updated_at ?? null + ); } - }} - name={$i18n.t('Pinned')} + + if (chat) { + console.log(chat); + if (chat.folder_id) { + const res = await updateChatFolderIdById( + localStorage.token, + chat.id, + null + ).catch((error) => { + toast.error(`${error}`); + return null; + }); + } + + if (!chat.pinned) { + const res = await toggleChatPinnedStatusById(localStorage.token, chat.id); + } + + initChatList(); + } + } + }} + name={$i18n.t('Pinned')} + > +
-
- {#each $pinnedChats as chat, idx (`pinned-chat-${chat?.id ?? idx}`)} - { - selectedChatId = chat.id; - }} - on:unselect={() => { - selectedChatId = null; - }} - on:change={async () => { - initChatList(); - }} - on:tag={(e) => { - const { type, name } = e.detail; - tagEventHandler(type, name, chat.id); - }} - /> - {/each} -
- -
- {/if} + {#each $pinnedChats as chat, idx (`pinned-chat-${chat?.id ?? idx}`)} + { + selectedChatId = chat.id; + }} + on:unselect={() => { + selectedChatId = null; + }} + on:change={async () => { + initChatList(); + }} + on:tag={(e) => { + const { type, name } = e.detail; + tagEventHandler(type, name, chat.id); + }} + /> + {/each} +
+
+
{/if} diff --git a/src/lib/components/layout/Sidebar/RecursiveFolder.svelte b/src/lib/components/layout/Sidebar/RecursiveFolder.svelte index a169998f20..2bb9eab791 100644 --- a/src/lib/components/layout/Sidebar/RecursiveFolder.svelte +++ b/src/lib/components/layout/Sidebar/RecursiveFolder.svelte @@ -464,7 +464,7 @@ }} >