Skip to content

Commit 7f7375d

Browse files
author
Mishig
authored
[Assistants filter] Make UI more responsive (#906)
1 parent 537b6f5 commit 7f7375d

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/routes/assistants/+page.svelte

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import { PUBLIC_APP_ASSETS, PUBLIC_ORIGIN } from "$env/static/public";
55
import { isHuggingChat } from "$lib/utils/isHuggingChat";
66
7-
import { tick } from "svelte";
87
import { goto } from "$app/navigation";
98
import { base } from "$app/paths";
109
import { page } from "$app/stores";
@@ -29,7 +28,8 @@
2928
3029
const SEARCH_DEBOUNCE_DELAY = 400;
3130
let filterInputEl: HTMLInputElement;
32-
let searchDisabled = false;
31+
let filterValue = data.query;
32+
let isFilterInPorgress = false;
3333
3434
const onModelChange = (e: Event) => {
3535
const newUrl = getHref($page.url, {
@@ -39,19 +39,26 @@
3939
goto(newUrl);
4040
};
4141
42-
const filterOnName = debounce(async (e: Event) => {
43-
searchDisabled = true;
44-
const value = (e.target as HTMLInputElement).value;
42+
const filterOnName = debounce(async (value: string) => {
43+
filterValue = value;
44+
45+
if (isFilterInPorgress) {
46+
return;
47+
}
48+
49+
isFilterInPorgress = true;
4550
const newUrl = getHref($page.url, {
4651
newKeys: { q: value },
4752
existingKeys: { behaviour: "delete", keys: ["p"] },
4853
});
4954
await goto(newUrl);
50-
setTimeout(async () => {
51-
searchDisabled = false;
52-
await tick();
53-
filterInputEl.focus();
54-
}, 0);
55+
setTimeout(() => filterInputEl.focus(), 0);
56+
isFilterInPorgress = false;
57+
58+
// there was a new filter query before server returned response
59+
if (filterValue !== value) {
60+
filterOnName(filterValue);
61+
}
5562
}, SEARCH_DEBOUNCE_DELAY);
5663
5764
const settings = useSettingsStore();
@@ -171,12 +178,11 @@
171178
<input
172179
class="h-[30px] w-full bg-transparent pl-5 focus:outline-none"
173180
placeholder="Filter by name"
174-
value={data.query}
175-
on:input={filterOnName}
181+
value={filterValue}
182+
on:input={(e) => filterOnName(e.currentTarget.value)}
176183
bind:this={filterInputEl}
177184
maxlength="150"
178185
type="search"
179-
disabled={searchDisabled}
180186
/>
181187
</div>
182188
</div>

0 commit comments

Comments
 (0)