Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
e5dd7e65
Commit
e5dd7e65
authored
Aug 04, 2024
by
Timothy J. Baek
Browse files
refac
parent
b2999ad5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
39 deletions
+41
-39
src/lib/components/chat/Settings/Chats.svelte
src/lib/components/chat/Settings/Chats.svelte
+13
-10
src/lib/components/chat/Tags.svelte
src/lib/components/chat/Tags.svelte
+8
-3
src/lib/components/layout/Sidebar.svelte
src/lib/components/layout/Sidebar.svelte
+18
-13
src/lib/stores/index.ts
src/lib/stores/index.ts
+1
-1
src/lib/utils/index.ts
src/lib/utils/index.ts
+1
-12
No files found.
src/lib/components/chat/Settings/Chats.svelte
View file @
e5dd7e65
...
...
@@ -2,7 +2,7 @@
import fileSaver from 'file-saver';
const { saveAs } = fileSaver;
import { chats, user, settings, scrollPaginationEnabled } from '$lib/stores';
import { chats, user, settings, scrollPaginationEnabled
, currentChatPage
} from '$lib/stores';
import {
archiveAllChats,
...
...
@@ -12,12 +12,7 @@
getAllUserChats,
getChatList
} from '$lib/apis/chats';
import {
getImportOrigin,
convertOpenAIChats,
disablePagination,
enablePagination
} from '$lib/utils';
import { getImportOrigin, convertOpenAIChats } from '$lib/utils';
import { onMount, getContext } from 'svelte';
import { goto } from '$app/navigation';
import { toast } from 'svelte-sonner';
...
...
@@ -66,7 +61,10 @@
await createNewChat(localStorage.token, chat);
}
}
enablePagination();
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
scrollPaginationEnabled.set(true);
};
const exportChats = async () => {
...
...
@@ -81,7 +79,10 @@
await archiveAllChats(localStorage.token).catch((error) => {
toast.error(error);
});
enablePagination();
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
scrollPaginationEnabled.set(true);
};
const deleteAllChatsHandler = async () => {
...
...
@@ -90,7 +91,9 @@
toast.error(error);
});
enablePagination();
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
scrollPaginationEnabled.set(true);
};
const toggleSaveChatHistory = async () => {
...
...
src/lib/components/chat/Tags.svelte
View file @
e5dd7e65
...
...
@@ -8,13 +8,18 @@
getTagsById,
updateChatById
} from '$lib/apis/chats';
import { tags as _tags, chats, pinnedChats, currentChatPage } from '$lib/stores';
import {
tags as _tags,
chats,
pinnedChats,
currentChatPage,
scrollPaginationEnabled
} from '$lib/stores';
import { createEventDispatcher, onMount } from 'svelte';
const dispatch = createEventDispatcher();
import Tags from '../common/Tags.svelte';
import { enablePagination } from '$lib/utils';
export let chatId = '';
let tags = [];
...
...
@@ -60,10 +65,10 @@
}
} else {
// if the tag we deleted is no longer a valid tag, return to main chat list view
enablePagination();
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
await scrollPaginationEnabled.set(true);
}
};
...
...
src/lib/components/layout/Sidebar.svelte
View file @
e5dd7e65
...
...
@@ -18,7 +18,6 @@
import { onMount, getContext, tick } from 'svelte';
const i18n = getContext('i18n');
import { disablePagination, enablePagination } from '$lib/utils';
import { updateUserSettings } from '$lib/apis/users';
import {
...
...
@@ -56,7 +55,7 @@
let filteredChatList = [];
// Pagination variables
let chatListLoading =
tru
e;
let chatListLoading =
fals
e;
let allChatsLoaded = false;
$: filteredChatList = $chats.filter((chat) => {
...
...
@@ -79,6 +78,16 @@
}
});
const enablePagination = async () => {
// Reset pagination variables
currentChatPage.set(1);
allChatsLoaded = false;
await chats.set(await getChatList(localStorage.token, $currentChatPage));
// Enable pagination
scrollPaginationEnabled.set(true);
};
const loadMoreChats = async () => {
chatListLoading = true;
...
...
@@ -104,10 +113,8 @@
});
showSidebar.set(window.innerWidth > BREAKPOINT);
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
await chats.set(await getChatList(localStorage.token, $currentChatPage));
chatListLoading = false;
await enablePagination();
let touchstart;
let touchend;
...
...
@@ -439,7 +446,7 @@
bind:value={search}
on:focus={async () => {
// TODO: migrate backend for more scalable search mechanism
disable
Pagination
(
);
scroll
Pagination
Enabled.set(false
);
await chats.set(await getChatList(localStorage.token)); // when searching, load all chats
enrichChatsWithContent($chats);
}}
...
...
@@ -452,9 +459,7 @@
<button
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 () => {
enablePagination();
allChatsLoaded = false;
await chats.set(await getChatList(localStorage.token, $currentChatPage));
await enablePagination();
}}
>
{$i18n.t('all')}
...
...
@@ -463,17 +468,17 @@
<button
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 () => {
disable
Pagination
(
);
scroll
Pagination
Enabled.set(false
);
let chatIds = await getChatListByTagName(localStorage.token, tag.name);
if (chatIds.length === 0) {
await tags.set(await getAllChatTags(localStorage.token));
// 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 enablePagination();
}
await chats.set(chatIds);
chatListLoading = false;
}}
>
{tag.name}
...
...
src/lib/stores/index.ts
View file @
e5dd7e65
...
...
@@ -42,7 +42,7 @@ export const showArchivedChats = writable(false);
export
const
showChangelog
=
writable
(
false
);
export
const
showCallOverlay
=
writable
(
false
);
export
const
scrollPaginationEnabled
=
writable
(
tru
e
);
export
const
scrollPaginationEnabled
=
writable
(
fals
e
);
export
const
currentChatPage
=
writable
(
1
);
export
type
Model
=
OpenAIModel
|
OllamaModel
;
...
...
src/lib/utils/index.ts
View file @
e5dd7e65
...
...
@@ -2,6 +2,7 @@ import { v4 as uuidv4 } from 'uuid';
import
sha256
from
'
js-sha256
'
;
import
{
WEBUI_BASE_URL
}
from
'
$lib/constants
'
;
import
{
scrollPaginationEnabled
,
chats
,
currentChatPage
}
from
'
$lib/stores
'
;
import
{
getChatList
}
from
'
$lib/apis/chats
'
;
//////////////////////////
// Helper functions
...
...
@@ -780,15 +781,3 @@ export const bestMatchingLanguage = (supportedLanguages, preferredLanguages, def
console
.
log
(
languages
,
preferredLanguages
,
match
,
defaultLocale
);
return
match
||
defaultLocale
;
};
export
const
enablePagination
=
()
=>
{
// Enable infinite scroll pagination
chats
.
set
([]);
currentChatPage
.
set
(
1
);
scrollPaginationEnabled
.
set
(
true
);
};
export
const
disablePagination
=
()
=>
{
// Disable infinite scroll pagination
scrollPaginationEnabled
.
set
(
false
);
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment