aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/composables
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/src/composables')
-rw-r--r--apps/files/src/composables/useBeforeNavigation.ts20
-rw-r--r--apps/files/src/composables/useFilenameFilter.ts47
-rw-r--r--apps/files/src/composables/useNavigation.spec.ts7
3 files changed, 27 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,
- }
-}
diff --git a/apps/files/src/composables/useNavigation.spec.ts b/apps/files/src/composables/useNavigation.spec.ts
index 569e61825e1..b9eb671a181 100644
--- a/apps/files/src/composables/useNavigation.spec.ts
+++ b/apps/files/src/composables/useNavigation.spec.ts
@@ -29,6 +29,7 @@ describe('Composables: useNavigation', () => {
describe('currentView', () => {
beforeEach(() => {
+ // eslint-disable-next-line import/namespace
navigation = new nextcloudFiles.Navigation()
spy.mockImplementation(() => navigation)
})
@@ -39,6 +40,7 @@ describe('Composables: useNavigation', () => {
})
it('should return already active navigation', async () => {
+ // eslint-disable-next-line import/namespace
const view = new nextcloudFiles.View({ getContents: () => Promise.reject(new Error()), icon: '<svg></svg>', id: 'view-1', name: 'My View 1', order: 0 })
navigation.register(view)
navigation.setActive(view)
@@ -48,6 +50,7 @@ describe('Composables: useNavigation', () => {
})
it('should be reactive on updating active navigation', async () => {
+ // eslint-disable-next-line import/namespace
const view = new nextcloudFiles.View({ getContents: () => Promise.reject(new Error()), icon: '<svg></svg>', id: 'view-1', name: 'My View 1', order: 0 })
navigation.register(view)
const wrapper = mount(TestComponent)
@@ -63,6 +66,7 @@ describe('Composables: useNavigation', () => {
describe('views', () => {
beforeEach(() => {
+ // eslint-disable-next-line import/namespace
navigation = new nextcloudFiles.Navigation()
spy.mockImplementation(() => navigation)
})
@@ -73,6 +77,7 @@ describe('Composables: useNavigation', () => {
})
it('should return already registered views', () => {
+ // eslint-disable-next-line import/namespace
const view = new nextcloudFiles.View({ getContents: () => Promise.reject(new Error()), icon: '<svg></svg>', id: 'view-1', name: 'My View 1', order: 0 })
// register before mount
navigation.register(view)
@@ -82,7 +87,9 @@ describe('Composables: useNavigation', () => {
})
it('should be reactive on registering new views', () => {
+ // eslint-disable-next-line import/namespace
const view = new nextcloudFiles.View({ getContents: () => Promise.reject(new Error()), icon: '<svg></svg>', id: 'view-1', name: 'My View 1', order: 0 })
+ // eslint-disable-next-line import/namespace
const view2 = new nextcloudFiles.View({ getContents: () => Promise.reject(new Error()), icon: '<svg></svg>', id: 'view-2', name: 'My View 2', order: 1 })
// register before mount