aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/composables/useNavigation.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/src/composables/useNavigation.ts')
-rw-r--r--apps/files/src/composables/useNavigation.ts15
1 files changed, 11 insertions, 4 deletions
diff --git a/apps/files/src/composables/useNavigation.ts b/apps/files/src/composables/useNavigation.ts
index f410aec895f..2a6f22a1232 100644
--- a/apps/files/src/composables/useNavigation.ts
+++ b/apps/files/src/composables/useNavigation.ts
@@ -3,24 +3,29 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { View } from '@nextcloud/files'
+import type { ShallowRef } from 'vue'
import { getNavigation } from '@nextcloud/files'
-import { onMounted, onUnmounted, shallowRef, type ShallowRef } from 'vue'
+import { subscribe } from '@nextcloud/event-bus'
+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
}
/**
@@ -28,11 +33,13 @@ export function useNavigation() {
*/
function onUpdateViews() {
views.value = navigation.views
+ triggerRef(views)
}
onMounted(() => {
navigation.addEventListener('update', onUpdateViews)
navigation.addEventListener('updateActive', onUpdateActive)
+ subscribe('files:navigation:updated', onUpdateViews)
})
onUnmounted(() => {
navigation.removeEventListener('update', onUpdateViews)