diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 85308451b7..a6a73347f0 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -17,7 +17,6 @@ import { chatId, - chats, config, type Model, models, @@ -31,7 +30,6 @@ audioQueue, showControls, showCallOverlay, - currentChatPage, temporaryChatEnabled, mobile, chatTitle, @@ -43,7 +41,6 @@ terminalServers, functions, selectedFolder, - pinnedChats, showEmbeds, selectedTerminalId, showFileNavPath, @@ -51,6 +48,7 @@ chatRequestQueues, desktopEvent } from '$lib/stores'; + import { refreshChatList } from '$lib/stores/chat-list'; import { WEBUI_API_BASE_URL } from '$lib/constants'; @@ -76,8 +74,6 @@ deleteChatById, getAllTags, getChatById, - getChatList, - getPinnedChatList, getTagsById, updateChatById, updateChatFolderIdById @@ -699,13 +695,12 @@ } else if (type === 'chat:message:favorite') { // Update message favorite status message.favorite = data.favorite; - } else if (type === 'chat:title') { - chatTitle.set(data); - currentChatPage.set(1); - await chats.set(await getChatList(localStorage.token, $currentChatPage)); - } else if (type === 'chat:tags') { - chat = await getChatById(localStorage.token, $chatId); - allTags.set(await getAllTags(localStorage.token)); + } else if (type === 'chat:title') { + chatTitle.set(data); + await refreshChatList(localStorage.token); + } else if (type === 'chat:tags') { + chat = await getChatById(localStorage.token, $chatId); + allTags.set(await getAllTags(localStorage.token)); } else if (type === 'source' || type === 'citation') { if (data?.type === 'code_execution') { // Code execution; update existing code execution by ID, or add new one. @@ -1764,12 +1759,11 @@ const chatCompletedHandler = async (_chatId, modelId, responseMessageId, messages) => { // Backend handles outlet filters and persistence inline. - // Just refresh the sidebar chat list. - if ($chatId == _chatId && !$temporaryChatEnabled) { - currentChatPage.set(1); - await chats.set(await getChatList(localStorage.token, $currentChatPage)); - } - }; + // Just refresh the sidebar chat list. + if ($chatId == _chatId && !$temporaryChatEnabled) { + await refreshChatList(localStorage.token); + } + }; const chatActionHandler = async (_chatId, actionId, modelId, responseMessageId, event = null) => { const messages = createMessagesList(history, responseMessageId); @@ -1816,13 +1810,12 @@ history: history, params: params, files: chatFiles - }); + }); - currentChatPage.set(1); - await chats.set(await getChatList(localStorage.token, $currentChatPage)); + await refreshChatList(localStorage.token); + } } - } - }; + }; const getChatEventEmitter = async (modelId: string, chatId: string = '') => { return setInterval(() => { @@ -2660,12 +2653,11 @@ // and causing spurious toast notifications / state duplication). if (res.chat_id && $chatId !== res.chat_id && $chatId === _chatId) { await chatId.set(res.chat_id); - if (!$temporaryChatEnabled) { - window.history.replaceState(history.state, '', `/c/${res.chat_id}`); - currentChatPage.set(1); - await chats.set(await getChatList(localStorage.token, $currentChatPage)); + if (!$temporaryChatEnabled) { + window.history.replaceState(history.state, '', `/c/${res.chat_id}`); + await refreshChatList(localStorage.token); - // Persist chat-level params (system prompt, advanced + // Persist chat-level params (system prompt, advanced // params) that the backend doesn't receive in the // chat completion request. Files are now persisted // by the backend at chat creation time. @@ -2938,15 +2930,14 @@ _chatId = chat.id; await chatId.set(_chatId); - window.history.replaceState(history.state, '', `/c/${_chatId}`); + window.history.replaceState(history.state, '', `/c/${_chatId}`); - await tick(); + await tick(); - await chats.set(await getChatList(localStorage.token, $currentChatPage)); - currentChatPage.set(1); + await refreshChatList(localStorage.token); - selectedFolder.set(null); - } else { + selectedFolder.set(null); + } else { _chatId = `local:${$socket?.id}`; // Use socket id for temporary chat await chatId.set(_chatId); } @@ -3021,28 +3012,24 @@ } ); - if (res) { - currentChatPage.set(1); - await chats.set(await getChatList(localStorage.token, $currentChatPage)); - await pinnedChats.set(await getPinnedChatList(localStorage.token)); + if (res) { + await refreshChatList(localStorage.token, { refreshPinned: true }); - toast.success($i18n.t('Chat moved successfully')); - } + toast.success($i18n.t('Chat moved successfully')); + } } else { toast.error($i18n.t('Failed to move chat')); } }; - const archiveChatHandler = async (id: string) => { - try { - await archiveChatById(localStorage.token, id); - currentChatPage.set(1); - initNewChat(); - await goto('/'); - chats.set(await getChatList(localStorage.token, $currentChatPage)); - pinnedChats.set(await getPinnedChatList(localStorage.token)); - toast.success($i18n.t('Chat archived.')); - } catch (error) { + const archiveChatHandler = async (id: string) => { + try { + await archiveChatById(localStorage.token, id); + initNewChat(); + await goto('/'); + await refreshChatList(localStorage.token, { refreshPinned: true }); + toast.success($i18n.t('Chat archived.')); + } catch (error) { console.error('Error archiving chat:', error); toast.error($i18n.t('Failed to archive chat.')); } @@ -3071,15 +3058,13 @@ if (!id) return; try { - const res = await deleteChatById(localStorage.token, id); - if (res) { - currentChatPage.set(1); - initNewChat(); - await goto('/'); - chats.set(await getChatList(localStorage.token, $currentChatPage)); - pinnedChats.set(await getPinnedChatList(localStorage.token)); - allTags.set(await getAllTags(localStorage.token)); - toast.success($i18n.t('Chat deleted.')); + const res = await deleteChatById(localStorage.token, id); + if (res) { + initNewChat(); + await goto('/'); + await refreshChatList(localStorage.token, { refreshPinned: true }); + allTags.set(await getAllTags(localStorage.token)); + toast.success($i18n.t('Chat deleted.')); } } catch (error) { console.error('Error deleting chat:', error); @@ -3229,12 +3214,12 @@ null ); - if (savedChat) { - temporaryChatEnabled.set(false); - chatId.set(savedChat.id); - chats.set(await getChatList(localStorage.token, $currentChatPage)); + if (savedChat) { + temporaryChatEnabled.set(false); + chatId.set(savedChat.id); + await refreshChatList(localStorage.token); - await goto(`/c/${savedChat.id}`); + await goto(`/c/${savedChat.id}`); toast.success($i18n.t('Conversation saved successfully')); } } catch (error) { diff --git a/src/lib/components/chat/MessageInput/InputMenu.svelte b/src/lib/components/chat/MessageInput/InputMenu.svelte index 3907e01487..815be23e74 100644 --- a/src/lib/components/chat/MessageInput/InputMenu.svelte +++ b/src/lib/components/chat/MessageInput/InputMenu.svelte @@ -106,7 +106,7 @@ accept="image/*" capture="environment" on:change={handleFileChange} - style="display: none;" + class="hidden" /> {/if} diff --git a/src/lib/components/chat/MessageInput/InputMenu/Chats.svelte b/src/lib/components/chat/MessageInput/InputMenu/Chats.svelte index 5cdf675e36..b498b6099e 100644 --- a/src/lib/components/chat/MessageInput/InputMenu/Chats.svelte +++ b/src/lib/components/chat/MessageInput/InputMenu/Chats.svelte @@ -74,9 +74,9 @@
{#each items as item, idx}