diff options
Diffstat (limited to 'apps/files/src/composables')
-rw-r--r-- | apps/files/src/composables/useBeforeNavigation.ts | 20 | ||||
-rw-r--r-- | apps/files/src/composables/useFilenameFilter.ts | 47 |
2 files changed, 20 insertions, 47 deletions
diff --git a/apps/files/src/composables/useBeforeNavigation.ts b/apps/files/src/composables/useBeforeNavigation.ts new file mode 100644 index 00000000000..38b72e40fb3 --- /dev/null +++ b/apps/files/src/composables/useBeforeNavigation.ts @@ -0,0 +1,20 @@ +/** + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import type { NavigationGuard } from 'vue-router' + +import { onUnmounted } from 'vue' +import { useRouter } from 'vue-router/composables' + +/** + * Helper until we use Vue-Router v4 (Vue3). + * + * @param fn - The navigation guard + */ +export function onBeforeNavigation(fn: NavigationGuard) { + const router = useRouter() + const remove = router.beforeResolve(fn) + onUnmounted(remove) +} diff --git a/apps/files/src/composables/useFilenameFilter.ts b/apps/files/src/composables/useFilenameFilter.ts deleted file mode 100644 index 54c16f35384..00000000000 --- a/apps/files/src/composables/useFilenameFilter.ts +++ /dev/null @@ -1,47 +0,0 @@ -/*! - * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -import { registerFileListFilter, unregisterFileListFilter } from '@nextcloud/files' -import { watchThrottled } from '@vueuse/core' -import { onMounted, onUnmounted, ref } from 'vue' -import { FilenameFilter } from '../filters/FilenameFilter' - -/** - * This is for the `Navigation` component to provide a filename filter - */ -export function useFilenameFilter() { - const searchQuery = ref('') - const filenameFilter = new FilenameFilter() - - /** - * Updating the search query ref from the filter - * @param event The update:query event - */ - function updateQuery(event: CustomEvent) { - if (event.type === 'update:query') { - searchQuery.value = event.detail - event.stopPropagation() - } - } - - onMounted(() => { - filenameFilter.addEventListener('update:query', updateQuery) - registerFileListFilter(filenameFilter) - }) - onUnmounted(() => { - filenameFilter.removeEventListener('update:query', updateQuery) - unregisterFileListFilter(filenameFilter.id) - }) - - // Update the query on the filter, but throttle to max. every 800ms - // This will debounce the filter refresh - watchThrottled(searchQuery, () => { - filenameFilter.updateQuery(searchQuery.value) - }, { throttle: 800 }) - - return { - searchQuery, - } -} |