44-->
55
66<script setup lang="ts">
7+ import { emit } from ' @nextcloud/event-bus'
78import { loadState } from ' @nextcloud/initial-state'
89import { t } from ' @nextcloud/l10n'
9- import { computed , ref , watch } from ' vue'
10- import { useRouter } from ' vue-router'
10+ import { useHotKey } from ' @nextcloud/vue'
11+ import { watchDebounced } from ' @vueuse/core'
12+ import { computed , ref , useTemplateRef , watch } from ' vue'
13+ import { useRoute , useRouter } from ' vue-router'
1114import NcAppNavigation from ' @nextcloud/vue/components/NcAppNavigation'
1215import NcAppNavigationItem from ' @nextcloud/vue/components/NcAppNavigationItem'
1316import NcAppNavigationSearch from ' @nextcloud/vue/components/NcAppNavigationSearch'
@@ -28,26 +31,52 @@ const userSettings = useUserSettingsStore()
2831const categories = computed (() => store .categories )
2932const categoriesLoading = computed (() => store .isLoadingCategories )
3033
34+ const route = useRoute ()
3135const router = useRouter ()
3236
37+ const searchElement = useTemplateRef (' search' )
38+
39+ useHotKey (' f' , () => {
40+ if (! searchElement .value ?.$refs .inputElement ) {
41+ emit (' toggle-navigation' , {
42+ open: true ,
43+ })
44+ // open animation
45+ window .setTimeout (() => searchElement .value ?.$refs .inputElement ?.focus (), 400 )
46+ }
47+ searchElement .value ?.$refs .inputElement ?.focus ()
48+ }, { ctrl: true , stop: true , prevent: true })
49+
3350const search = ref (' ' )
34- watch (search , (newValue , oldValue ) => {
51+ // initialize the search value from the query parameter on mount
52+ watch (() => route .query .q , (newQuery ) => {
53+ search .value = [newQuery || ' ' ].flat ()[0 ]!
54+ }, { immediate: true })
55+ // update the query parameter when the search value changes, debounced to avoid excessive updates
56+ watchDebounced (search , (newValue , oldValue ) => {
3557 if (newValue .trim () === oldValue .trim ()) {
3658 return
3759 }
3860
39- if (router .currentRoute .value .name === ' apps-search ' ) {
40- router .replace ({
61+ if (router .currentRoute .value .name === ' apps-discover ' || ( router . currentRoute . value . name === ' apps-manage ' && route . params . category === ' bundles ' ) ) {
62+ router .push ({
4163 name: ' apps-search' ,
42- query: { q: newValue },
64+ query: {
65+ ... route .query ,
66+ q: newValue .trim () || undefined ,
67+ },
4368 })
4469 return
4570 }
46- router .push ({
47- name: ' apps-search' ,
48- query: { q: newValue },
71+
72+ router .replace ({
73+ ... route ,
74+ query: {
75+ ... route .query ,
76+ q: newValue .trim () || undefined ,
77+ },
4978 })
50- })
79+ }, { debounce: 500 } )
5180
5281/**
5382 * Check if the current instance has a support subscription from the Nextcloud GmbH
@@ -62,6 +91,7 @@ const isSubscribed = computed(() => store.apps.find(({ level }) => level === 300
6291 <NcAppNavigation :aria-label =" t('appstore', 'Apps')" >
6392 <template #search >
6493 <NcAppNavigationSearch
94+ ref =" search"
6595 v-model =" search"
6696 :label =" t('appstore', 'Search apps…')" />
6797 </template >
0 commit comments