This commit is contained in:
Timothy Jaeryang Baek 2026-11-05 21:50:59 +09:00
parent e9cb194f46
commit 1632222f39
2 changed files with 14 additions and 2 deletions

View file

@ -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;

View file

@ -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);