Skip to content

Commit 0453041

Browse files
committed
Bugfix(modeling-commons): Fix twitchy search bar in models page
1 parent fecb71e commit 0453041

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

  • apps/modeling-commons-frontend/app/pages/models

apps/modeling-commons-frontend/app/pages/models/index.vue

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
<div class="space-y-2">
55
<div class="flex flex-col sm:flex-row gap-3">
66
<div class="relative flex-1">
7-
<SearchBar
8-
:model-value="filters.keyword"
9-
autofocus
10-
@update:model-value="onKeywordChange"
11-
/>
7+
<SearchBar v-model="keyword" autofocus />
128
</div>
139

1410
<!-- @extract -->
@@ -230,13 +226,21 @@ watch(pending, (isLoading) => {
230226
else indicator.finish();
231227
});
232228
233-
let keywordTimeout: ReturnType<typeof setTimeout>;
234-
function onKeywordChange(value: string | number) {
235-
clearTimeout(keywordTimeout);
236-
keywordTimeout = setTimeout(() => {
237-
void setFilter("keyword", String(value));
238-
}, modelKeywordDebounceMs);
239-
}
229+
const { query: keyword, debouncedQuery: debouncedKeyword } = useSearchQuery({
230+
defaultValue: filters.value.keyword ?? "",
231+
debounce: { ms: modelKeywordDebounceMs },
232+
});
233+
234+
watch(debouncedKeyword, (value) => {
235+
void setFilter("keyword", value ?? "");
236+
});
237+
238+
watch(
239+
() => filters.value.keyword,
240+
(value) => {
241+
if ((value ?? "") !== debouncedKeyword.value) keyword.value = value ?? "";
242+
},
243+
);
240244
</script>
241245

242246
<style>

0 commit comments

Comments
 (0)