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 @@