4242import { emit } from ' @nextcloud/event-bus'
4343import { getNavigation } from ' @nextcloud/files'
4444import { t } from ' @nextcloud/l10n'
45- import { computed , ref , watchEffect } from ' vue'
45+ import { computed , provide , ref , watchEffect } from ' vue'
4646import { useRoute } from ' vue-router/composables'
4747import NcAppNavigation from ' @nextcloud/vue/components/NcAppNavigation'
4848import NcAppNavigationItem from ' @nextcloud/vue/components/NcAppNavigationItem'
@@ -65,6 +65,32 @@ const allViews = useViews()
6565
6666const route = useRoute ()
6767const currentViewId = computed (() => route ?.params ?.view || ' files' )
68+
69+ const currentNavigationViewId = computed (() => {
70+ const views = allViews .value .filter ((view ) => view .id === currentViewId .value
71+ || view .params ?.view === currentViewId .value )
72+ const matchingParams = views .filter ((view ) => view .params
73+ && Object .entries (view .params ).every (([key , value ]) => {
74+ if (key in route .params ) {
75+ return route .params [key ] === value
76+ }
77+ return route .query [key ] === value
78+ }))
79+ .sort ((a , b ) => Object .keys (b .params ! ).length - Object .keys (a .params ! ).length )
80+ // if we have a full match use that
81+ if (matchingParams .length > 0 ) {
82+ return matchingParams [0 ]
83+ }
84+ // otherwise check if at least view + dir matches
85+ const matchingDir = views .find ((view ) => view .params ?.dir === route .query .dir )
86+ if (matchingDir ) {
87+ return matchingDir
88+ }
89+ // finally fallback to the parent view
90+ return views .find ((view ) => view .id === currentViewId .value )!
91+ })
92+ provide (' currentNavigationView' , currentNavigationViewId )
93+
6894watchEffect (() => {
6995 if (currentViewId .value !== activeStore .activeView ?.id ) {
7096 logger .debug (` Route view id ${currentViewId .value } is different from active view id ${activeStore .activeView ?.id }, updating active view... ` )
0 commit comments