Skip to content

Commit 9c6022f

Browse files
committed
fix: folder tree selection after any action in main content
Signed-off-by: mykh-hailo <kristianderonta0205@gmail.com>
1 parent 0f82477 commit 9c6022f

4 files changed

Lines changed: 36 additions & 6 deletions

File tree

apps/files/src/components/FilesNavigationListItem.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import type { IView } from '@nextcloud/files'
88
99
import { getCanonicalLocale, getLanguage } from '@nextcloud/l10n'
10-
import { computed, onMounted, ref } from 'vue'
10+
import { computed, inject, onMounted, ref, watchEffect } from 'vue'
1111
import NcAppNavigationItem from '@nextcloud/vue/components/NcAppNavigationItem'
1212
import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper'
1313
import { useVisibleViews } from '../composables/useViews.ts'
@@ -62,6 +62,8 @@ const sortedChildViews = computed(() => childViews.value.slice().sort((a, b) =>
6262
return collator.compare(a.name, b.name)
6363
}))
6464
const hasChildViews = computed(() => childViews.value.length > 0)
65+
const activeViewId = inject("currentNavigationView", ref<string | undefined>(undefined))
66+
const isActiveView = computed(() => activeViewId.value.id === props.view.id)
6567
6668
const navigationRoute = computed(() => {
6769
if (props.view.params) {
@@ -138,6 +140,7 @@ export default {
138140
<template>
139141
<NcAppNavigationItem
140142
class="files-navigation__item"
143+
:active="isActiveView"
141144
allow-collapse
142145
:loading="isLoading"
143146
:data-cy-files-navigation-item="view.id"
@@ -164,4 +167,4 @@ export default {
164167
:level="level + 1"
165168
:view="childView" />
166169
</NcAppNavigationItem>
167-
</template>
170+
</template>

apps/files/src/views/FilesNavigation.vue

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
import { emit } from '@nextcloud/event-bus'
4343
import { getNavigation } from '@nextcloud/files'
4444
import { t } from '@nextcloud/l10n'
45-
import { computed, ref, watchEffect } from 'vue'
45+
import { isSamePath } from '@nextcloud/paths'
46+
import { computed, provide, ref, watchEffect } from 'vue'
4647
import { useRoute } from 'vue-router/composables'
4748
import NcAppNavigation from '@nextcloud/vue/components/NcAppNavigation'
4849
import NcAppNavigationItem from '@nextcloud/vue/components/NcAppNavigationItem'
@@ -65,6 +66,32 @@ const allViews = useViews()
6566
6667
const route = useRoute()
6768
const currentViewId = computed(() => route?.params?.view || 'files')
69+
70+
const currentNavigationViewId = computed(() => {
71+
const views = allViews.value.filter((view) => view.id === currentViewId.value
72+
|| view.params?.view === currentViewId.value)
73+
const matchingParams = views.filter((view) => view.params
74+
&& Object.entries(view.params).every(([key, value]) => {
75+
if (key in route.params) {
76+
return route.params[key] === value
77+
}
78+
return route.query[key] === value
79+
}))
80+
.sort((a, b) => Object.keys(b.params!).length - Object.keys(a.params!).length)
81+
// if we have a full match use that
82+
if (matchingParams.length > 0) {
83+
return matchingParams[0]
84+
}
85+
// otherwise check if at least view + dir matches
86+
const matchingDir = views.find((view) => view.params?.dir === route.query.dir)
87+
if (matchingDir) {
88+
return matchingDir
89+
}
90+
// finally fallback to the parent view
91+
return views.find((view) => view.id === currentViewId.value)!
92+
})
93+
provide("currentNavigationView", currentNavigationViewId)
94+
6895
watchEffect(() => {
6996
if (currentViewId.value !== activeStore.activeView?.id) {
7097
logger.debug(`Route view id ${currentViewId.value} is different from active view id ${activeStore.activeView?.id}, updating active view...`)

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)