From f9e1a933a9f885efb558be6c19d83fcbc9902bb8 Mon Sep 17 00:00:00 2001 From: Aryan Kothari <87589047+thearyadev@users.noreply.github.com> Date: Sat, 3 Aug 2024 11:52:52 -0400 Subject: [PATCH] fix: bug in chat deletion pagination interact change 1: when selecting a tag to filter the `tagView` store is set to disable paginated loading. This is so all tagged items can be loaded at once. deleting a tag when in the filtered view returns to the unfiltered view. this change now sets the `tagView` store to `false` so pagination can continue change 2: formatting --- src/lib/components/chat/Chat.svelte | 8 ++++---- src/lib/components/chat/Messages.svelte | 2 +- src/lib/components/chat/Tags.svelte | 13 ++++--------- src/lib/components/layout/Sidebar.svelte | 15 +++++++++++---- src/lib/components/layout/Sidebar/ChatItem.svelte | 6 +++--- src/lib/stores/index.ts | 1 + 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index a2a0b4de8..7ab1576c4 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -424,7 +424,7 @@ files: chatFiles }); await chats.set( - await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit) + await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit) ); } } @@ -472,7 +472,7 @@ files: chatFiles }); await chats.set( - await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit) + await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit) ); } } @@ -634,7 +634,7 @@ timestamp: Date.now() }); await chats.set( - await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit) + await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit) ); await chatId.set(chat.id); } else { @@ -711,7 +711,7 @@ }) ); - await chats.set(await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit)); + await chats.set(await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)); return _responses; }; diff --git a/src/lib/components/chat/Messages.svelte b/src/lib/components/chat/Messages.svelte index 8d8e3205e..c798de923 100644 --- a/src/lib/components/chat/Messages.svelte +++ b/src/lib/components/chat/Messages.svelte @@ -90,7 +90,7 @@ history: history }); - await chats.set(await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit)); + await chats.set(await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)); }; const confirmEditResponseMessage = async (messageId, content) => { diff --git a/src/lib/components/chat/Tags.svelte b/src/lib/components/chat/Tags.svelte index af4dbe41b..30e485ba0 100644 --- a/src/lib/components/chat/Tags.svelte +++ b/src/lib/components/chat/Tags.svelte @@ -8,7 +8,7 @@ getTagsById, updateChatById } from '$lib/apis/chats'; - import { tags as _tags, chats, pinnedChats, pageSkip, pageLimit } from '$lib/stores'; + import { tags as _tags, chats, pinnedChats, pageSkip, pageLimit, tagView } from '$lib/stores'; import { createEventDispatcher, onMount } from 'svelte'; const dispatch = createEventDispatcher(); @@ -46,20 +46,14 @@ tags: tags }); - console.log($_tags); - await _tags.set(await getAllChatTags(localStorage.token)); - console.log($_tags); - console.log('this run !!!!!'); - console.log($_tags); - if ($_tags.map((t) => t.name).includes(tagName)) { if (tagName === 'pinned') { await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned')); } else { await chats.set( - await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit) + await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit) ); } @@ -68,10 +62,11 @@ } } else { await chats.set( - await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit) + await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit) ); await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned')); } + tagView.set(false); }; onMount(async () => { diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 2d6483898..c6db94484 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -14,7 +14,8 @@ pinnedChats, pageSkip, pageLimit, - scrollPaginationEnabled + scrollPaginationEnabled, + tagView } from '$lib/stores'; import { onMount, getContext, tick } from 'svelte'; @@ -54,7 +55,6 @@ let filteredChatList = []; let paginationScrollThreashold = 0.6; let nextPageLoading = false; - let tagView = false; let chatPagniationComplete = false; // number of chats per page depends on screen size. // 35px is the height of each chat item. @@ -251,6 +251,13 @@

Chats loaded: {$chats.length}

+ +

+ Pagination Enabled: {$scrollPaginationEnabled} +

+

+ Final Page Reached: {chatPagniationComplete} +

@@ -520,7 +527,7 @@ class="pl-2 my-2 flex-1 flex flex-col space-y-1 overflow-y-auto scrollbar-hidden" on:scroll={async (e) => { if (!$scrollPaginationEnabled) return; - if (tagView) return; + if ($tagView) return; if (nextPageLoading) return; if (chatPagniationComplete) return; diff --git a/src/lib/components/layout/Sidebar/ChatItem.svelte b/src/lib/components/layout/Sidebar/ChatItem.svelte index ae9558b98..a107a5f31 100644 --- a/src/lib/components/layout/Sidebar/ChatItem.svelte +++ b/src/lib/components/layout/Sidebar/ChatItem.svelte @@ -49,7 +49,7 @@ title: _title }); await chats.set( - await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit) + await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit) ); await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned')); } @@ -64,7 +64,7 @@ if (res) { goto(`/c/${res.id}`); await chats.set( - await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit) + await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit) ); await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned')); } @@ -72,7 +72,7 @@ const archiveChatHandler = async (id) => { await archiveChatById(localStorage.token, id); - await chats.set(await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit)); + await chats.set(await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)); await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned')); }; diff --git a/src/lib/stores/index.ts b/src/lib/stores/index.ts index 60a617185..6e14fcb2c 100644 --- a/src/lib/stores/index.ts +++ b/src/lib/stores/index.ts @@ -44,6 +44,7 @@ export const showCallOverlay = writable(false); export const scrollPaginationEnabled = writable(true); export const pageSkip = writable(0); export const pageLimit = writable(-1); +export const tagView = writable(false); export type Model = OpenAIModel | OllamaModel;