diff --git a/src/components/SearchGame.vue b/src/components/SearchGame.vue index 24b38c8..f60ec6b 100644 --- a/src/components/SearchGame.vue +++ b/src/components/SearchGame.vue @@ -24,13 +24,14 @@ type Item = { icon?: string badge?: string showSpinner: boolean + class?: string } const items: Ref = ref([]) let abortController = new AbortController() - -const SEARCH_ICON = 'search' +let lastFilterSearchTerm: string | null = null function filterGameSearch(term: string, doneFn: (callbackFn: () => void) => void) { + lastFilterSearchTerm = term abortController.abort() abortController = new AbortController() @@ -38,15 +39,6 @@ function filterGameSearch(term: string, doneFn: (callbackFn: () => void) => void doneFn(() => { const newItems: Item[] = [] - if (term) { - newItems.push({ - label: 'Montrer tous les résultats', - value: term, - icon: SEARCH_ICON, - showSpinner: false - }) - } - for (const result of results) { newItems.push({ label: result.name, @@ -79,15 +71,6 @@ watch(selectedItem, async (newItem) => { selectedItem.value = null if (!newItem) { return - } else if (newItem.icon === SEARCH_ICON) { - state.value = 'loading' - try { - fullSearchResults.value = await gameSearcher.doFullSearch(newItem.value) - state.value = 'full-search' - } catch (error) { - notifyWarn(error as Error) - state.value = 'input' - } } else { state.value = 'loading' try { @@ -101,6 +84,22 @@ watch(selectedItem, async (newItem) => { } }) +function displayFullSearch() { + if (lastFilterSearchTerm) { + state.value = 'loading' + gameSearcher + .doFullSearch(lastFilterSearchTerm) + .then((result) => { + fullSearchResults.value = result + state.value = 'full-search' + }) + .catch((error) => { + notifyWarn(error as Error) + state.value = 'input' + }) + } +} + function choseGame(game: Game): void { emit('input', game) state.value = 'input' @@ -125,7 +124,7 @@ function choseGame(game: Game): void { dense > + +