diff --git a/app/app.vue b/app/app.vue index 850b6eb..80fceec 100644 --- a/app/app.vue +++ b/app/app.vue @@ -2,10 +2,29 @@
+ + + +
+ + diff --git a/app/components/box.vue b/app/components/box.vue index 9ec5d62..e2af164 100644 --- a/app/components/box.vue +++ b/app/components/box.vue @@ -3,7 +3,7 @@
-
+
  • diff --git a/app/plugins/search-shortcut.client.ts b/app/plugins/search-shortcut.client.ts new file mode 100644 index 0000000..5476345 --- /dev/null +++ b/app/plugins/search-shortcut.client.ts @@ -0,0 +1,17 @@ +import { useUiStore } from '~/store/ui' +export default defineNuxtPlugin((nuxtApp) => { + const ui = useUiStore() + const isMobile = nuxtApp.$isMobile as boolean | undefined + + const onKeyDown = (e: KeyboardEvent) => { + if ((e.metaKey || e.ctrlKey) && (e.key === 'f' || e.key === 'F')) { + if (isMobile) return + e.preventDefault() + if (!ui.showSearch) ui.openSearch() + } + } + + if (process.client) { + window.addEventListener('keydown', onKeyDown) + } +}) diff --git a/app/store/ui.ts b/app/store/ui.ts index e36d7c3..b76f1ab 100644 --- a/app/store/ui.ts +++ b/app/store/ui.ts @@ -5,9 +5,26 @@ import type { Box } from '~/../types/types' export const useUiStore = defineStore('ui', { state: () => ({ // UI-only state can live here later + showSearch: false, + searchQuery: '' }), actions: { + openSearch() { + this.showSearch = true + // reset query on open to avoid stale state + this.searchQuery = '' + }, + + closeSearch() { + this.showSearch = false + this.searchQuery = '' + }, + + setSearchQuery(q: string) { + this.searchQuery = q + }, + selectBox(id: string) { const dataStore = useDataStore() dataStore.boxes.forEach((box) => {