diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 74abba32d..aadf542ea 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -150,7 +150,12 @@ - + { + await chats.set(await getChatList(localStorage.token)); + }} +/>
import { toast } from 'svelte-sonner'; import dayjs from 'dayjs'; - import { onMount, getContext } from 'svelte'; + import { getContext, createEventDispatcher } from 'svelte'; + + const dispatch = createEventDispatcher(); import Modal from '$lib/components/common/Modal.svelte'; - import { getArchivedChatList } from '$lib/apis/chats'; + import { archiveChatById, deleteChatById, getArchivedChatList } from '$lib/apis/chats'; + import Tooltip from '$lib/components/common/Tooltip.svelte'; const i18n = getContext('i18n'); @@ -12,9 +15,29 @@ let chats = []; - onMount(async () => { + const unarchiveChatHandler = async (chatId) => { + const res = await archiveChatById(localStorage.token, chatId).catch((error) => { + toast.error(error); + }); + chats = await getArchivedChatList(localStorage.token); - }); + + dispatch('change'); + }; + + const deleteChatHandler = async (chatId) => { + const res = await deleteChatById(localStorage.token, chatId).catch((error) => { + toast.error(error); + }); + + chats = await getArchivedChatList(localStorage.token); + }; + + $: if (show) { + (async () => { + chats = await getArchivedChatList(localStorage.token); + })(); + } @@ -45,11 +68,91 @@
{#if chats.length > 0}
- {#each chats as chat} +
+ + + + + + + + + {#each chats as chat} + + + + + + + + {/each} + +
{$i18n.t('Name')} {$i18n.t('Created At')} +
+
+ {chat.title} +
+
+ {dayjs(chat.created_at * 1000).format($i18n.t('MMMM DD, YYYY HH:mm'))} + +
+ + + + + + + +
+
+
+
{:else}
You have no archived conversations.