diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index a4e2829f82..d7374f898f 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -2632,12 +2632,8 @@ currentChatPage.set(1); initNewChat(); await goto('/'); - getChatList(localStorage.token, $currentChatPage).then((chats) => { - chats.set(chats); - }); - getPinnedChatList(localStorage.token).then((pinnedChats) => { - pinnedChats.set(pinnedChats); - }); + chats.set(await getChatList(localStorage.token, $currentChatPage)); + pinnedChats.set(await getPinnedChatList(localStorage.token)); toast.success($i18n.t('Chat archived.')); } catch (error) { console.error('Error archiving chat:', error); diff --git a/src/lib/components/layout/ArchivedChatsModal.svelte b/src/lib/components/layout/ArchivedChatsModal.svelte index ec6a74a045..31e322a105 100644 --- a/src/lib/components/layout/ArchivedChatsModal.svelte +++ b/src/lib/components/layout/ArchivedChatsModal.svelte @@ -21,6 +21,7 @@ export let show = false; export let onUpdate = () => {}; + export let onDelete: (id: string) => void = () => {}; let loading = false; let chatList: any[] | null = null; @@ -158,6 +159,9 @@ onUpdate={() => { init(); }} + onDelete={(id) => { + onDelete(id); + }} loadHandler={loadMoreChats} {unarchiveHandler} > diff --git a/src/lib/components/layout/ChatsModal.svelte b/src/lib/components/layout/ChatsModal.svelte index 796f885214..b56ed780d3 100644 --- a/src/lib/components/layout/ChatsModal.svelte +++ b/src/lib/components/layout/ChatsModal.svelte @@ -50,6 +50,7 @@ let showDeleteConfirmDialog = false; export let onUpdate = () => {}; + export let onDelete: (id: string) => void = () => {}; export let loadHandler: null | Function = null; export let unarchiveHandler: null | Function = null; @@ -69,6 +70,9 @@ toast.error(`${error}`); }); + if (res) { + onDelete(chatId); + } onUpdate(); }; diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 2a8416b95b..e7822e8c94 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -592,6 +592,12 @@ onUpdate={async () => { await initChatList(); }} + onDelete={(id) => { + if ($chatId === id) { + chatId.set(''); + window.history.replaceState({}, '', '/'); + } + }} /> { try { await archiveChatById(localStorage.token, id); + + if ($chatId === id) { + chatId.set(''); + window.history.replaceState({}, '', '/'); + } + dispatch('change'); toast.success($i18n.t('Chat archived.')); } catch (error) {