MCPcopy Create free account
hub / github.com/dfinity/orbit / useAutocomplete

Function useAutocomplete

apps/wallet/src/composables/autocomplete.composable.ts:7–39  ·  view source on GitHub ↗
(fetchCall: (search: string) => Promise<T[]>)

Source from the content-addressed store, hash-verified

5import { debounce } from '~/utils/helper.utils';
6
7export const useAutocomplete = <T>(fetchCall: (search: string) => Promise<T[]>) => {
8 const search = ref<string>('');
9 const loading = ref<boolean>(false);
10 const results: Ref<T[]> = ref([]);
11
12 const triggerSearch = debounce(async () => {
13 try {
14 loading.value = true;
15 const fetchResults = await fetchCall(search.value);
16
17 results.value = fetchResults;
18 } catch (err) {
19 logger.error(`Failed to search`, { err });
20
21 results.value = [];
22 } finally {
23 loading.value = false;
24 }
25 }, 500);
26
27 const searchItems = async (searchTerm?: string): Promise<void> => {
28 search.value = searchTerm || '';
29
30 return triggerSearch();
31 };
32
33 return {
34 search,
35 loading,
36 results,
37 searchItems,
38 };
39};
40
41export const useUserGroupsAutocomplete = () => {
42 const station = useStationStore();

Calls 1

debounceFunction · 0.90

Tested by

no test coverage detected