diff --git a/backend/apps/webui/routers/chats.py b/backend/apps/webui/routers/chats.py index 02c9335e0..5d52f40c9 100644 --- a/backend/apps/webui/routers/chats.py +++ b/backend/apps/webui/routers/chats.py @@ -148,7 +148,7 @@ async def get_archived_session_user_chat_list( ############################ -@router.get("/archive/all", response_model=List[ChatTitleIdResponse]) +@router.post("/archive/all", response_model=List[ChatTitleIdResponse]) async def archive_all_chats(user=Depends(get_current_user)): return Chats.archive_all_chats_by_user_id(user.id) diff --git a/src/lib/apis/chats/index.ts b/src/lib/apis/chats/index.ts index a72b51939..834e29d29 100644 --- a/src/lib/apis/chats/index.ts +++ b/src/lib/apis/chats/index.ts @@ -654,3 +654,35 @@ export const deleteAllChats = async (token: string) => { return res; }; + +export const archiveAllChats = async (token: string) => { + let error = null; + + const res = await fetch(`${WEBUI_API_BASE_URL}/chats/archive/all`, { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + ...(token && { authorization: `Bearer ${token}` }) + } + }) + .then(async (res) => { + if (!res.ok) throw await res.json(); + return res.json(); + }) + .then((json) => { + return json; + }) + .catch((err) => { + error = err.detail; + + console.log(err); + return null; + }); + + if (error) { + throw error; + } + + return res; +}; diff --git a/src/lib/components/chat/Settings/Chats.svelte b/src/lib/components/chat/Settings/Chats.svelte index ef16ca1d8..9837b79b9 100644 --- a/src/lib/components/chat/Settings/Chats.svelte +++ b/src/lib/components/chat/Settings/Chats.svelte @@ -5,6 +5,7 @@ import { chats, user, config } from '$lib/stores'; import { + archiveAllChats, createNewChat, deleteAllChats, getAllChats, @@ -22,7 +23,10 @@ // Chats let saveChatHistory = true; let importFiles; + + let showArchiveConfirm = false; let showDeleteConfirm = false; + let chatImportInputElement: HTMLInputElement; $: if (importFiles) { @@ -68,6 +72,14 @@ saveAs(blob, `chat-export-${Date.now()}.json`); }; + const archiveAllChatsHandler = async () => { + await goto('/'); + await archiveAllChats(localStorage.token).catch((error) => { + toast.error(error); + }); + await chats.set(await getChatList(localStorage.token)); + }; + const deleteAllChatsHandler = async () => { await goto('/'); await deleteAllChats(localStorage.token).catch((error) => { @@ -210,88 +222,177 @@
- {#if showDeleteConfirm} -
-
- - - - - {$i18n.t('Are you sure?')} -
- -
- + +
+
+ {:else} + + {/if} + + {#if showDeleteConfirm} +
+
+ + + + + {$i18n.t('Are you sure?')} +
+ +
+ + +
+
+ {:else} + - - - - {:else} - - {/if} + +
{$i18n.t('Delete All Chats')}
+ + {/if} + diff --git a/src/lib/components/layout/Sidebar/ArchivedChatsModal.svelte b/src/lib/components/layout/Sidebar/ArchivedChatsModal.svelte index 931931f36..2044da2b6 100644 --- a/src/lib/components/layout/Sidebar/ArchivedChatsModal.svelte +++ b/src/lib/components/layout/Sidebar/ArchivedChatsModal.svelte @@ -101,95 +101,99 @@
{#if chats.length > 0} -
-
- - - - - - - - - {#each chats.filter((c) => searchValue === '' || c.title - .toLowerCase() - .includes(searchValue.toLowerCase())) as chat, idx} - - - - - - +
+
+
+
{$i18n.t('Name')} -
- -
- {chat.title} -
-
-
-
- - - - - - - -
-
+ + + + + - {/each} - -
{$i18n.t('Name')}
+ + + {#each chats.filter((c) => searchValue === '' || c.title + .toLowerCase() + .includes(searchValue.toLowerCase())) as chat, idx} + + + +
+ {chat.title} +
+
+ + + +
+ {dayjs(chat.created_at * 1000).format($i18n.t('MMMM DD, YYYY HH:mm'))} +
+ + + +
+ + + + + + + +
+ + + {/each} + + +