From 49677e9c9dc7ad782629135de93af4fd63d84fdc Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 4 Aug 2024 17:04:15 +0200 Subject: [PATCH] refac --- backend/apps/webui/routers/chats.py | 2 +- src/lib/components/chat/Chat.svelte | 14 +++++++------- src/lib/components/chat/Messages.svelte | 2 +- src/lib/components/chat/Tags.svelte | 2 +- src/lib/components/layout/Sidebar.svelte | 4 +++- src/lib/components/layout/Sidebar/ChatItem.svelte | 6 +++--- src/lib/utils/index.ts | 2 +- 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/backend/apps/webui/routers/chats.py b/backend/apps/webui/routers/chats.py index 0b327d0a0..5ad9df573 100644 --- a/backend/apps/webui/routers/chats.py +++ b/backend/apps/webui/routers/chats.py @@ -45,7 +45,7 @@ router = APIRouter() async def get_session_user_chat_list( user=Depends(get_verified_user), page: Optional[int] = None ): - if page: + if page is not None: limit = 20 skip = (page - 1) * limit diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index c55605f82..2c42c2046 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -423,7 +423,7 @@ files: chatFiles }); - currentChatPage.set(0); + currentChatPage.set(1); await chats.set(await getChatList(localStorage.token, $currentChatPage)); } } @@ -471,7 +471,7 @@ files: chatFiles }); - currentChatPage.set(0); + currentChatPage.set(1); await chats.set(await getChatList(localStorage.token, $currentChatPage)); } } @@ -633,7 +633,7 @@ timestamp: Date.now() }); - currentChatPage.set(0); + currentChatPage.set(1); await chats.set(await getChatList(localStorage.token, $currentChatPage)); await chatId.set(chat.id); } else { @@ -710,7 +710,7 @@ }) ); - currentChatPage.set(0); + currentChatPage.set(1); await chats.set(await getChatList(localStorage.token, $currentChatPage)); return _responses; @@ -959,7 +959,7 @@ files: chatFiles }); - currentChatPage.set(0); + currentChatPage.set(1); await chats.set(await getChatList(localStorage.token, $currentChatPage)); } } @@ -1228,7 +1228,7 @@ files: chatFiles }); - currentChatPage.set(0); + currentChatPage.set(1); await chats.set(await getChatList(localStorage.token, $currentChatPage)); } } @@ -1395,7 +1395,7 @@ if ($settings.saveChatHistory ?? true) { chat = await updateChatById(localStorage.token, _chatId, { title: _title }); - currentChatPage.set(0); + currentChatPage.set(1); await chats.set(await getChatList(localStorage.token, $currentChatPage)); } }; diff --git a/src/lib/components/chat/Messages.svelte b/src/lib/components/chat/Messages.svelte index 5ba9fefaa..9e3c147b1 100644 --- a/src/lib/components/chat/Messages.svelte +++ b/src/lib/components/chat/Messages.svelte @@ -90,7 +90,7 @@ history: history }); - currentChatPage.set(0); + currentChatPage.set(1); await chats.set(await getChatList(localStorage.token, $currentChatPage)); }; diff --git a/src/lib/components/chat/Tags.svelte b/src/lib/components/chat/Tags.svelte index 6297d69df..746ca74c2 100644 --- a/src/lib/components/chat/Tags.svelte +++ b/src/lib/components/chat/Tags.svelte @@ -61,7 +61,7 @@ } else { // if the tag we deleted is no longer a valid tag, return to main chat list view enablePagination(); - currentChatPage.set(0); + currentChatPage.set(1); await chats.set(await getChatList(localStorage.token, $currentChatPage)); await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned')); } diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 2785266e9..1fb3cb844 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -209,7 +209,7 @@ } allChatsLoaded = false; - currentChatPage.set(0); + currentChatPage.set(1); await chats.set(await getChatList(localStorage.token, $currentChatPage)); await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned')); @@ -453,6 +453,7 @@ on:click={async () => { enablePagination(); allChatsLoaded = false; + await chats.set(await getChatList(localStorage.token, $currentChatPage)); }} > {$i18n.t('all')} @@ -469,6 +470,7 @@ // if the tag we deleted is no longer a valid tag, return to main chat list view enablePagination(); allChatsLoaded = false; + chatIds = await getChatList(localStorage.token, $currentChatPage); } await chats.set(chatIds); }} diff --git a/src/lib/components/layout/Sidebar/ChatItem.svelte b/src/lib/components/layout/Sidebar/ChatItem.svelte index 379fee716..859366949 100644 --- a/src/lib/components/layout/Sidebar/ChatItem.svelte +++ b/src/lib/components/layout/Sidebar/ChatItem.svelte @@ -41,7 +41,7 @@ title: _title }); - currentChatPage.set(0); + currentChatPage.set(1); await chats.set(await getChatList(localStorage.token, $currentChatPage)); await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned')); } @@ -56,7 +56,7 @@ if (res) { goto(`/c/${res.id}`); - currentChatPage.set(0); + currentChatPage.set(1); await chats.set(await getChatList(localStorage.token, $currentChatPage)); await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned')); } @@ -65,7 +65,7 @@ const archiveChatHandler = async (id) => { await archiveChatById(localStorage.token, id); - currentChatPage.set(0); + currentChatPage.set(1); await chats.set(await getChatList(localStorage.token, $currentChatPage)); await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned')); }; diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index f93b93612..a550b318c 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -784,7 +784,7 @@ export const bestMatchingLanguage = (supportedLanguages, preferredLanguages, def export const enablePagination = () => { // Enable infinite scroll pagination chats.set([]); - currentChatPage.set(0); + currentChatPage.set(1); scrollPaginationEnabled.set(true); };