This commit is contained in:
Timothy Jaeryang Baek committed 2026-01-30 10:43:40 -05:00
1 parent ee27fd8de1
commit 45d7486485
1 file changed
+11 -16
+11 -16
View File
@@ -28,7 +28,7 @@
let page = 0; let page = 0;
let allFilesLoaded = false; let allFilesLoaded = false;
let filesLoading = false; let filesLoading = false;
let searchDebounceTimeout: any; let searchDebounceTimer: ReturnType<typeof setTimeout>;
let selectedFileId: string | null = null; let selectedFileId: string | null = null;
let showDeleteConfirmDialog = false; let showDeleteConfirmDialog = false;
@@ -61,15 +61,10 @@
const searchHandler = async () => { const searchHandler = async () => {
if (!show) return; if (!show) return;
if (searchDebounceTimeout) {
clearTimeout(searchDebounceTimeout);
}
page = 0; page = 0;
files = null; files = null;
allFilesLoaded = false; allFilesLoaded = false;
const doSearch = async () => {
try { try {
const pattern = query ? `*${query}*` : '*'; const pattern = query ? `*${query}*` : '*';
const newFiles = await searchFiles(localStorage.token, pattern, 0, PAGE_SIZE); const newFiles = await searchFiles(localStorage.token, pattern, 0, PAGE_SIZE);
@@ -82,13 +77,6 @@
} }
}; };
if (query === '') {
await doSearch();
} else {
searchDebounceTimeout = setTimeout(doSearch, 500);
}
};
const loadMoreFiles = async () => { const loadMoreFiles = async () => {
if (filesLoading || allFilesLoaded) return; if (filesLoading || allFilesLoaded) return;
@@ -152,8 +140,12 @@
showFileItemModal = true; showFileItemModal = true;
}; };
$: if (show) { // Debounce query changes
$: if (show && query !== undefined) {
clearTimeout(searchDebounceTimer);
searchDebounceTimer = setTimeout(() => {
searchHandler(); searchHandler();
}, 300);
} }
onMount(() => { onMount(() => {
@@ -178,11 +170,16 @@
window.addEventListener('blur', onBlur); window.addEventListener('blur', onBlur);
return () => { return () => {
clearTimeout(searchDebounceTimer);
window.removeEventListener('keydown', onKeyDown); window.removeEventListener('keydown', onKeyDown);
window.removeEventListener('keyup', onKeyUp); window.removeEventListener('keyup', onKeyUp);
window.removeEventListener('blur', onBlur); window.removeEventListener('blur', onBlur);
}; };
}); });
onDestroy(() => {
clearTimeout(searchDebounceTimer);
});
</script> </script>
<ConfirmDialog <ConfirmDialog
@@ -243,7 +240,6 @@
<input <input
class="w-full text-sm pr-4 py-1 rounded-r-xl outline-hidden bg-transparent" class="w-full text-sm pr-4 py-1 rounded-r-xl outline-hidden bg-transparent"
bind:value={query} bind:value={query}
on:input={() => searchHandler()}
placeholder={$i18n.t('Search Files')} placeholder={$i18n.t('Search Files')}
maxlength="500" maxlength="500"
/> />
@@ -254,7 +250,6 @@
class="p-0.5 rounded-full hover:bg-gray-100 dark:hover:bg-gray-900 transition" class="p-0.5 rounded-full hover:bg-gray-100 dark:hover:bg-gray-900 transition"
on:click={() => { on:click={() => {
query = ''; query = '';
searchHandler();
}} }}
> >
<XMark className="size-3" strokeWidth="2" /> <XMark className="size-3" strokeWidth="2" />