Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Add debouncing on search term update
Browse files Browse the repository at this point in the history
  • Loading branch information
HuakunShen committed May 20, 2024
1 parent e702782 commit ccab3ac
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions apps/desktop/src/components/MainSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from "@/components/ui/command";
import { getAllApps, refreshApplicationsList } from "@/lib/commands/apps";
import { systemCommands } from "@/lib/commands/system";
import { computed, onMounted, onUnmounted, ref } from "vue";
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
import { IconType, UiCmd, type AppInfo, type TCommand, type TListItem } from "@jarvis/api";
import {
AlertDialogControlled,
Expand Down Expand Up @@ -48,6 +48,19 @@ const searchTerm = computed({
set: (value) => setSearchTerm(value),
});
/**
* searchTermInSync is used for debouncing the searching triggered by searchTerm
* This is to prevent the search term from being updated on every key press
*/
const searchTermInSync = ref("");
let updateSearchTermTimeout: NodeJS.Timeout;
watch(searchTermInSync, (val) => {
clearTimeout(updateSearchTermTimeout);
updateSearchTermTimeout = setTimeout(() => {
setSearchTerm(val);
}, 200);
});
// const filteredApps = useStore($filteredApps);
const filteredApps = computed(() => {
if (searchTerm.value.length > 1) {
Expand Down Expand Up @@ -129,7 +142,7 @@ function openExtention(item: TListItem) {
}
</script>
<template>
<Command class="" v-model:searchTerm="searchTerm" :identity-filter="true">
<Command class="" v-model:searchTerm="searchTermInSync" :identity-filter="true">
<!-- <img width="40":src="convertFileSrc('/Applications/Google Chrome.app/Contents/Resources/app.icns', 'macicns')" alt="">
<img width="40":src="convertFileSrc('/Applications/Visual Studio Code.app/Contents/Resources/Code.icns', 'macicns')" alt=""> -->
<CommandInput placeholder="Search for apps or commands..." :always-focus="true" />
Expand Down

0 comments on commit ccab3ac

Please sign in to comment.