Mishig commited on
Commit
7f7375d
1 Parent(s): 537b6f5

[Assistants filter] Make UI more responsive (#906)

Browse files
Files changed (1) hide show
  1. src/routes/assistants/+page.svelte +19 -13
src/routes/assistants/+page.svelte CHANGED
@@ -4,7 +4,6 @@
4
  import { PUBLIC_APP_ASSETS, PUBLIC_ORIGIN } from "$env/static/public";
5
  import { isHuggingChat } from "$lib/utils/isHuggingChat";
6
 
7
- import { tick } from "svelte";
8
  import { goto } from "$app/navigation";
9
  import { base } from "$app/paths";
10
  import { page } from "$app/stores";
@@ -29,7 +28,8 @@
29
 
30
  const SEARCH_DEBOUNCE_DELAY = 400;
31
  let filterInputEl: HTMLInputElement;
32
- let searchDisabled = false;
 
33
 
34
  const onModelChange = (e: Event) => {
35
  const newUrl = getHref($page.url, {
@@ -39,19 +39,26 @@
39
  goto(newUrl);
40
  };
41
 
42
- const filterOnName = debounce(async (e: Event) => {
43
- searchDisabled = true;
44
- const value = (e.target as HTMLInputElement).value;
 
 
 
 
 
45
  const newUrl = getHref($page.url, {
46
  newKeys: { q: value },
47
  existingKeys: { behaviour: "delete", keys: ["p"] },
48
  });
49
  await goto(newUrl);
50
- setTimeout(async () => {
51
- searchDisabled = false;
52
- await tick();
53
- filterInputEl.focus();
54
- }, 0);
 
 
55
  }, SEARCH_DEBOUNCE_DELAY);
56
 
57
  const settings = useSettingsStore();
@@ -171,12 +178,11 @@
171
  <input
172
  class="h-[30px] w-full bg-transparent pl-5 focus:outline-none"
173
  placeholder="Filter by name"
174
- value={data.query}
175
- on:input={filterOnName}
176
  bind:this={filterInputEl}
177
  maxlength="150"
178
  type="search"
179
- disabled={searchDisabled}
180
  />
181
  </div>
182
  </div>
 
4
  import { PUBLIC_APP_ASSETS, PUBLIC_ORIGIN } from "$env/static/public";
5
  import { isHuggingChat } from "$lib/utils/isHuggingChat";
6
 
 
7
  import { goto } from "$app/navigation";
8
  import { base } from "$app/paths";
9
  import { page } from "$app/stores";
 
28
 
29
  const SEARCH_DEBOUNCE_DELAY = 400;
30
  let filterInputEl: HTMLInputElement;
31
+ let filterValue = data.query;
32
+ let isFilterInPorgress = false;
33
 
34
  const onModelChange = (e: Event) => {
35
  const newUrl = getHref($page.url, {
 
39
  goto(newUrl);
40
  };
41
 
42
+ const filterOnName = debounce(async (value: string) => {
43
+ filterValue = value;
44
+
45
+ if (isFilterInPorgress) {
46
+ return;
47
+ }
48
+
49
+ isFilterInPorgress = true;
50
  const newUrl = getHref($page.url, {
51
  newKeys: { q: value },
52
  existingKeys: { behaviour: "delete", keys: ["p"] },
53
  });
54
  await goto(newUrl);
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
+ }
62
  }, SEARCH_DEBOUNCE_DELAY);
63
 
64
  const settings = useSettingsStore();
 
178
  <input
179
  class="h-[30px] w-full bg-transparent pl-5 focus:outline-none"
180
  placeholder="Filter by name"
181
+ value={filterValue}
182
+ on:input={(e) => filterOnName(e.currentTarget.value)}
183
  bind:this={filterInputEl}
184
  maxlength="150"
185
  type="search"
 
186
  />
187
  </div>
188
  </div>