diff options
Diffstat (limited to 'apps/files/src/composables')
-rw-r--r-- | apps/files/src/composables/useNavigation.spec.ts | 18 | ||||
-rw-r--r-- | apps/files/src/composables/useNavigation.ts | 9 |
2 files changed, 15 insertions, 12 deletions
diff --git a/apps/files/src/composables/useNavigation.spec.ts b/apps/files/src/composables/useNavigation.spec.ts index efea7103126..569e61825e1 100644 --- a/apps/files/src/composables/useNavigation.spec.ts +++ b/apps/files/src/composables/useNavigation.spec.ts @@ -2,6 +2,8 @@ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ +import type { Navigation, View } from '@nextcloud/files' + import { beforeEach, describe, expect, it, vi } from 'vitest' import { mount } from '@vue/test-utils' import { defineComponent } from 'vue' @@ -9,8 +11,6 @@ import { defineComponent } from 'vue' import { useNavigation } from './useNavigation' import * as nextcloudFiles from '@nextcloud/files' -const { Navigation, View } = nextcloudFiles - // Just a wrapper so we can test the composable const TestComponent = defineComponent({ template: '<div></div>', @@ -29,7 +29,7 @@ describe('Composables: useNavigation', () => { describe('currentView', () => { beforeEach(() => { - navigation = new Navigation() + navigation = new nextcloudFiles.Navigation() spy.mockImplementation(() => navigation) }) @@ -39,7 +39,7 @@ describe('Composables: useNavigation', () => { }) it('should return already active navigation', async () => { - const view = new View({ getContents: () => Promise.reject(new Error()), icon: '<svg></svg>', id: 'view-1', name: 'My View 1', order: 0 }) + 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) // Now the navigation is already set it should take the active navigation @@ -48,7 +48,7 @@ describe('Composables: useNavigation', () => { }) it('should be reactive on updating active navigation', async () => { - const view = new View({ getContents: () => Promise.reject(new Error()), icon: '<svg></svg>', id: 'view-1', name: 'My View 1', order: 0 }) + 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,7 +63,7 @@ describe('Composables: useNavigation', () => { describe('views', () => { beforeEach(() => { - navigation = new Navigation() + navigation = new nextcloudFiles.Navigation() spy.mockImplementation(() => navigation) }) @@ -73,7 +73,7 @@ describe('Composables: useNavigation', () => { }) it('should return already registered views', () => { - const view = new View({ getContents: () => Promise.reject(new Error()), icon: '<svg></svg>', id: 'view-1', name: 'My View 1', order: 0 }) + 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) // now mount and check that the view is listed @@ -82,8 +82,8 @@ describe('Composables: useNavigation', () => { }) it('should be reactive on registering new views', () => { - const view = new View({ getContents: () => Promise.reject(new Error()), icon: '<svg></svg>', id: 'view-1', name: 'My View 1', order: 0 }) - const view2 = new View({ getContents: () => Promise.reject(new Error()), icon: '<svg></svg>', id: 'view-2', name: 'My View 2', order: 1 }) + const view = new nextcloudFiles.View({ getContents: () => Promise.reject(new Error()), icon: '<svg></svg>', id: 'view-1', name: 'My View 1', order: 0 }) + 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 navigation.register(view) diff --git a/apps/files/src/composables/useNavigation.ts b/apps/files/src/composables/useNavigation.ts index 714b3a6d7b2..2a6f22a1232 100644 --- a/apps/files/src/composables/useNavigation.ts +++ b/apps/files/src/composables/useNavigation.ts @@ -11,18 +11,21 @@ import { onMounted, onUnmounted, shallowRef, triggerRef } from 'vue' /** * Composable to get the currently active files view from the files navigation + * @param _loaded If set enforce a current view is loaded */ -export function useNavigation() { +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export function useNavigation<T extends boolean>(_loaded?: T) { + type MaybeView = T extends true ? View : (View | null); const navigation = getNavigation() const views: ShallowRef<View[]> = shallowRef(navigation.views) - const currentView: ShallowRef<View | null> = shallowRef(navigation.active) + const currentView: ShallowRef<MaybeView> = shallowRef(navigation.active as MaybeView) /** * Event listener to update the `currentView` * @param event The update event */ function onUpdateActive(event: CustomEvent<View|null>) { - currentView.value = event.detail + currentView.value = event.detail as MaybeView } /** |