Skip to content

Commit

Permalink
[Assistants filter] Make UI more responsive (#906)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishig authored Mar 6, 2024
1 parent 537b6f5 commit 7f7375d
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/routes/assistants/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { PUBLIC_APP_ASSETS, PUBLIC_ORIGIN } from "$env/static/public";
import { isHuggingChat } from "$lib/utils/isHuggingChat";
import { tick } from "svelte";
import { goto } from "$app/navigation";
import { base } from "$app/paths";
import { page } from "$app/stores";
Expand All @@ -29,7 +28,8 @@
const SEARCH_DEBOUNCE_DELAY = 400;
let filterInputEl: HTMLInputElement;
let searchDisabled = false;
let filterValue = data.query;
let isFilterInPorgress = false;
const onModelChange = (e: Event) => {
const newUrl = getHref($page.url, {
Expand All @@ -39,19 +39,26 @@
goto(newUrl);
};
const filterOnName = debounce(async (e: Event) => {
searchDisabled = true;
const value = (e.target as HTMLInputElement).value;
const filterOnName = debounce(async (value: string) => {
filterValue = value;
if (isFilterInPorgress) {
return;
}
isFilterInPorgress = true;
const newUrl = getHref($page.url, {
newKeys: { q: value },
existingKeys: { behaviour: "delete", keys: ["p"] },
});
await goto(newUrl);
setTimeout(async () => {
searchDisabled = false;
await tick();
filterInputEl.focus();
}, 0);
setTimeout(() => filterInputEl.focus(), 0);
isFilterInPorgress = false;
// there was a new filter query before server returned response
if (filterValue !== value) {
filterOnName(filterValue);
}
}, SEARCH_DEBOUNCE_DELAY);
const settings = useSettingsStore();
Expand Down Expand Up @@ -171,12 +178,11 @@
<input
class="h-[30px] w-full bg-transparent pl-5 focus:outline-none"
placeholder="Filter by name"
value={data.query}
on:input={filterOnName}
value={filterValue}
on:input={(e) => filterOnName(e.currentTarget.value)}
bind:this={filterInputEl}
maxlength="150"
type="search"
disabled={searchDisabled}
/>
</div>
</div>
Expand Down

0 comments on commit 7f7375d

Please sign in to comment.