mirror of
https://github.com/open-webui/open-webui
synced 2025-03-16 02:17:33 +00:00
refactor: disable pagination moved to a function
reduces repeated code
This commit is contained in:
parent
f9e1a933a9
commit
cdac0cd1df
@ -12,7 +12,7 @@
|
|||||||
getAllUserChats,
|
getAllUserChats,
|
||||||
getChatList
|
getChatList
|
||||||
} from '$lib/apis/chats';
|
} from '$lib/apis/chats';
|
||||||
import { getImportOrigin, convertOpenAIChats } from '$lib/utils';
|
import { getImportOrigin, convertOpenAIChats, disablePagination } from '$lib/utils';
|
||||||
import { onMount, getContext } from 'svelte';
|
import { onMount, getContext } from 'svelte';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
@ -61,12 +61,7 @@
|
|||||||
await createNewChat(localStorage.token, chat);
|
await createNewChat(localStorage.token, chat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// loading all chats. disable pagination on scrol.
|
disablePagination();
|
||||||
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);
|
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(await getChatList(localStorage.token));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -82,12 +77,7 @@
|
|||||||
await archiveAllChats(localStorage.token).catch((error) => {
|
await archiveAllChats(localStorage.token).catch((error) => {
|
||||||
toast.error(error);
|
toast.error(error);
|
||||||
});
|
});
|
||||||
// loading all chats. disable pagination on scrol.
|
disablePagination();
|
||||||
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);
|
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(await getChatList(localStorage.token));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -96,12 +86,7 @@
|
|||||||
await deleteAllChats(localStorage.token).catch((error) => {
|
await deleteAllChats(localStorage.token).catch((error) => {
|
||||||
toast.error(error);
|
toast.error(error);
|
||||||
});
|
});
|
||||||
// loading all chats. disable pagination on scrol.
|
disablePagination();
|
||||||
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);
|
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(await getChatList(localStorage.token));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
import { onMount, getContext, tick } from 'svelte';
|
import { onMount, getContext, tick } from 'svelte';
|
||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
import { disablePagination } from '$lib/utils';
|
||||||
|
|
||||||
import { updateUserSettings } from '$lib/apis/users';
|
import { updateUserSettings } from '$lib/apis/users';
|
||||||
import {
|
import {
|
||||||
@ -434,12 +435,7 @@
|
|||||||
placeholder={$i18n.t('Search')}
|
placeholder={$i18n.t('Search')}
|
||||||
bind:value={search}
|
bind:value={search}
|
||||||
on:focus={async () => {
|
on:focus={async () => {
|
||||||
// loading all chats. disable pagination on scrol.
|
disablePagination();
|
||||||
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);
|
|
||||||
await chats.set(await getChatList(localStorage.token)); // when searching, load all chats
|
await chats.set(await getChatList(localStorage.token)); // when searching, load all chats
|
||||||
|
|
||||||
enrichChatsWithContent($chats);
|
enrichChatsWithContent($chats);
|
||||||
@ -453,9 +449,7 @@
|
|||||||
<button
|
<button
|
||||||
class="px-2.5 text-xs font-medium bg-gray-50 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
|
class="px-2.5 text-xs font-medium bg-gray-50 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
|
||||||
on:click={async () => {
|
on:click={async () => {
|
||||||
scrollPaginationEnabled.set(false);
|
disablePagination();
|
||||||
pageSkip.set(0);
|
|
||||||
pageLimit.set(-1);
|
|
||||||
|
|
||||||
await chats.set(
|
await chats.set(
|
||||||
await getChatList(localStorage.token, $pageSkip * $pageLimit, $pageLimit)
|
await getChatList(localStorage.token, $pageSkip * $pageLimit, $pageLimit)
|
||||||
@ -472,9 +466,7 @@
|
|||||||
if (chatIds.length === 0) {
|
if (chatIds.length === 0) {
|
||||||
// no chats found in the tag
|
// no chats found in the tag
|
||||||
await tags.set(await getAllChatTags(localStorage.token));
|
await tags.set(await getAllChatTags(localStorage.token));
|
||||||
scrollPaginationEnabled.set(false);
|
disablePagination();
|
||||||
pageSkip.set(0);
|
|
||||||
pageLimit.set(-1);
|
|
||||||
chatIds = await getChatList(
|
chatIds = await getChatList(
|
||||||
localStorage.token,
|
localStorage.token,
|
||||||
$pageSkip * $pageLimit,
|
$pageSkip * $pageLimit,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import sha256 from 'js-sha256';
|
import sha256 from 'js-sha256';
|
||||||
import { WEBUI_BASE_URL } from '$lib/constants';
|
import { WEBUI_BASE_URL } from '$lib/constants';
|
||||||
|
import { scrollPaginationEnabled, pageLimit, pageSkip } from '$lib/stores';
|
||||||
|
|
||||||
//////////////////////////
|
//////////////////////////
|
||||||
// Helper functions
|
// Helper functions
|
||||||
@ -779,3 +780,9 @@ export const bestMatchingLanguage = (supportedLanguages, preferredLanguages, def
|
|||||||
console.log(languages, preferredLanguages, match, defaultLocale);
|
console.log(languages, preferredLanguages, match, defaultLocale);
|
||||||
return match || defaultLocale;
|
return match || defaultLocale;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const disablePagination = () => {
|
||||||
|
scrollPaginationEnabled.set(false);
|
||||||
|
pageLimit.set(-1);
|
||||||
|
pageSkip.set(0);
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user