|
13 | 13 | <script lang="ts"> |
14 | 14 | import type { ConditionalPick } from 'type-fest'; |
15 | 15 | import Loader from '$lib/components/Loader.svelte'; |
16 | | - import { DebouncedInput } from '$lib/forms'; |
| 16 | + import { PlainInput } from '$lib/forms'; |
17 | 17 | import { pick } from '$lib/util/object'; |
18 | 18 | import t from '$lib/i18n'; |
19 | 19 | import type { Writable } from 'svelte/store'; |
20 | 20 | import Dropdown from '../Dropdown.svelte'; |
21 | | - import { Previous } from 'runed'; |
| 21 | + import { Previous, Debounced, watch } from 'runed'; |
| 22 | + import { DEFAULT_DEBOUNCE_TIME } from '$lib/util/time'; |
22 | 23 |
|
23 | 24 | type DumbFilters = $$Generic<Record<string, unknown>>; |
24 | 25 | // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents |
25 | 26 | type Filters = DumbFilters & Record<typeof searchKey, string>; |
26 | 27 |
|
27 | | - let searchInput: DebouncedInput | undefined = $state(); |
| 28 | + let searchInput: PlainInput | undefined = $state(); |
28 | 29 |
|
29 | 30 | interface Props { |
30 | 31 | searchKey: keyof ConditionalPick<DumbFilters, string>; |
|
57 | 58 | filterSlot, |
58 | 59 | }: Props = $props(); |
59 | 60 | let undebouncedSearch: string | undefined = $state(undefined); |
| 61 | + let watcher: () => string | undefined; |
| 62 | + if (debounce === false) { |
| 63 | + watcher = () => undebouncedSearch; |
| 64 | + } else { |
| 65 | + const debounceTime: number = debounce === true ? DEFAULT_DEBOUNCE_TIME : debounce; |
| 66 | + const debouncer = new Debounced(() => undebouncedSearch, debounceTime); |
| 67 | + watcher = () => debouncer.current; |
| 68 | + } |
| 69 | + watch(watcher, (value) => { |
| 70 | + $allFilters[searchKey] = value as Filters[typeof searchKey]; |
| 71 | + }); |
60 | 72 |
|
61 | 73 | function onClearFiltersClick(): void { |
62 | 74 | if (!searchInput) return; |
|
103 | 115 | <div class="input filter-bar input-bordered flex items-center gap-2 py-1.5 px-2 flex-wrap h-[unset] min-h-12"> |
104 | 116 | {@render activeFilterSlot?.({ activeFilters })} |
105 | 117 | <div class="flex grow"> |
106 | | - <DebouncedInput |
107 | | - bind:value={$allFilters[searchKey]} |
108 | | - {debounce} |
109 | | - bind:undebouncedValue={undebouncedSearch} |
| 118 | + <PlainInput |
| 119 | + bind:value={undebouncedSearch} |
110 | 120 | bind:this={searchInput} |
111 | 121 | placeholder={$t('filter.placeholder')} |
112 | 122 | style="seach-input border-none h-8 px-1 focus:outline-none min-w-[120px] flex-grow" |
|
0 commit comments