mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-28 16:11:43 -05:00
refac
This commit is contained in:
1 parent
df61370456
commit
44a9d499db
6 files changed
+130
-104
No files matched your search
@@ -3,7 +3,7 @@
|
||||
import { onDestroy, onMount, tick, getContext } from 'svelte';
|
||||
|
||||
import { decodeString } from '$lib/utils';
|
||||
import { getChatList, getChatListBySearchText } from '$lib/apis/chats';
|
||||
import { getChatList, getChatListBySearchText, getChatSearchSnippet } from '$lib/apis/chats';
|
||||
|
||||
import Tooltip from '$lib/components/common/Tooltip.svelte';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
let loaded = false;
|
||||
|
||||
let items = [];
|
||||
let items: { id: string; name: string; updated_at: number; snippet?: string | null }[] = [];
|
||||
let selectedIdx = 0;
|
||||
let query = '';
|
||||
|
||||
@@ -29,6 +29,18 @@
|
||||
let searchDebounceTimer: ReturnType<typeof setTimeout>;
|
||||
let requestId = 0;
|
||||
|
||||
const loadSnippet = async (item: { id: string; snippet?: string | null }) => {
|
||||
if (!searchedQuery.trim() || item.snippet !== undefined) return;
|
||||
item.snippet = null;
|
||||
try {
|
||||
item.snippet = await getChatSearchSnippet(localStorage.token, item.id, searchedQuery);
|
||||
items = items;
|
||||
} catch (error) {
|
||||
item.snippet = undefined;
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
// Only re-run the search when the query actually changes. Flipping `initialized`
|
||||
// after the initial load would otherwise trigger a second, identical request.
|
||||
$: if (initialized && query !== searchedQuery) {
|
||||
@@ -82,6 +94,7 @@
|
||||
.map((item) => {
|
||||
return {
|
||||
...item,
|
||||
snippet: undefined,
|
||||
type: 'chat',
|
||||
name: item.title
|
||||
};
|
||||
@@ -145,6 +158,7 @@
|
||||
.locale($i18n.language)
|
||||
.fromNow()}
|
||||
placement="top-start"
|
||||
tippyOptions={{ onShown: () => loadSnippet(item) }}
|
||||
>
|
||||
<div class="line-clamp-1 flex-1">
|
||||
{decodeString(item?.name)}
|
||||
|
||||
Reference in new issue
Block a user