From cdac0cd1df7cfa81dd69a66366c6789eae292c86 Mon Sep 17 00:00:00 2001 From: Aryan Kothari <87589047+thearyadev@users.noreply.github.com> Date: Sat, 3 Aug 2024 19:40:12 -0400 Subject: [PATCH] refactor: disable pagination moved to a function reduces repeated code --- src/lib/components/chat/Settings/Chats.svelte | 23 ++++--------------- src/lib/components/layout/Sidebar.svelte | 16 ++++--------- src/lib/utils/index.ts | 7 ++++++ 3 files changed, 15 insertions(+), 31 deletions(-) diff --git a/src/lib/components/chat/Settings/Chats.svelte b/src/lib/components/chat/Settings/Chats.svelte index 00a9af6a2..2c032d4df 100644 --- a/src/lib/components/chat/Settings/Chats.svelte +++ b/src/lib/components/chat/Settings/Chats.svelte @@ -12,7 +12,7 @@ getAllUserChats, getChatList } from '$lib/apis/chats'; - import { getImportOrigin, convertOpenAIChats } from '$lib/utils'; + import { getImportOrigin, convertOpenAIChats, disablePagination } from '$lib/utils'; import { onMount, getContext } from 'svelte'; import { goto } from '$app/navigation'; import { toast } from 'svelte-sonner'; @@ -61,12 +61,7 @@ await createNewChat(localStorage.token, chat); } } - // loading all chats. disable pagination on scrol. - scrollPaginationEnabled.set(false); - // subsequent queries will calculate page size to rehydrate the ui. - // since every chat is already loaded, the calculation should now load all chats. - pageSkip.set(0); - pageLimit.set(-1); + disablePagination(); await chats.set(await getChatList(localStorage.token)); }; @@ -82,12 +77,7 @@ await archiveAllChats(localStorage.token).catch((error) => { toast.error(error); }); - // loading all chats. disable pagination on scrol. - scrollPaginationEnabled.set(false); - // subsequent queries will calculate page size to rehydrate the ui. - // since every chat is already loaded, the calculation should now load all chats. - pageSkip.set(0); - pageLimit.set(-1); + disablePagination(); await chats.set(await getChatList(localStorage.token)); }; @@ -96,12 +86,7 @@ await deleteAllChats(localStorage.token).catch((error) => { toast.error(error); }); - // loading all chats. disable pagination on scrol. - scrollPaginationEnabled.set(false); - // subsequent queries will calculate page size to rehydrate the ui. - // since every chat is already loaded, the calculation should now load all chats. - pageSkip.set(0); - pageLimit.set(-1); + disablePagination(); await chats.set(await getChatList(localStorage.token)); }; diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index c6db94484..5a988a4a6 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -20,6 +20,7 @@ import { onMount, getContext, tick } from 'svelte'; const i18n = getContext('i18n'); + import { disablePagination } from '$lib/utils'; import { updateUserSettings } from '$lib/apis/users'; import { @@ -434,12 +435,7 @@ placeholder={$i18n.t('Search')} bind:value={search} on:focus={async () => { - // loading all chats. disable pagination on scrol. - scrollPaginationEnabled.set(false); - // subsequent queries will calculate page size to rehydrate the ui. - // since every chat is already loaded, the calculation should now load all chats. - pageSkip.set(0); - pageLimit.set(-1); + disablePagination(); await chats.set(await getChatList(localStorage.token)); // when searching, load all chats enrichChatsWithContent($chats); @@ -453,9 +449,7 @@