mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-14 09:21:22 +00:00
refac
This commit is contained in:
parent
e9cb194f46
commit
1632222f39
2 changed files with 14 additions and 2 deletions
|
|
@ -131,7 +131,8 @@ export const searchNotes = async (
|
|||
permission: string | null = null,
|
||||
sortKey: string | null = null,
|
||||
page: number | null = null,
|
||||
direction: string | null = null
|
||||
direction: string | null = null,
|
||||
signal?: AbortSignal
|
||||
) => {
|
||||
let error = null;
|
||||
const searchParams = new URLSearchParams();
|
||||
|
|
@ -162,6 +163,7 @@ export const searchNotes = async (
|
|||
|
||||
const res = await fetch(`${WEBUI_API_BASE_URL}/notes/search?${searchParams.toString()}`, {
|
||||
method: 'GET',
|
||||
signal,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
|
|
@ -176,6 +178,7 @@ export const searchNotes = async (
|
|||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
if (signal?.aborted) return null;
|
||||
error = err.detail;
|
||||
console.error(err);
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@
|
|||
|
||||
let query = '';
|
||||
let searchDebounceTimer: ReturnType<typeof setTimeout>;
|
||||
let searchController: AbortController;
|
||||
|
||||
let sortKey = 'updated_at';
|
||||
let sortDirection = 'desc';
|
||||
|
|
@ -200,6 +201,10 @@
|
|||
: `/notes/${note.id}`;
|
||||
|
||||
const getItemsPage = async () => {
|
||||
searchController?.abort();
|
||||
searchController = new AbortController();
|
||||
const { signal } = searchController;
|
||||
|
||||
itemsLoading = true;
|
||||
|
||||
if (viewOption === 'created') {
|
||||
|
|
@ -213,11 +218,14 @@
|
|||
permission,
|
||||
sortKey,
|
||||
page,
|
||||
sortKey ? sortDirection : null
|
||||
sortKey ? sortDirection : null,
|
||||
signal
|
||||
).catch(() => {
|
||||
return [];
|
||||
});
|
||||
|
||||
if (signal.aborted) return;
|
||||
|
||||
if (res) {
|
||||
total = res.total;
|
||||
const pageItems = res.items;
|
||||
|
|
@ -349,6 +357,7 @@
|
|||
window.addEventListener('blur', onBlur);
|
||||
|
||||
return () => {
|
||||
searchController?.abort();
|
||||
clearTimeout(searchDebounceTimer);
|
||||
|
||||
window.removeEventListener('focusin', onFocusIn);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue