Skip to content

Commit c022fd6

Browse files
mykh-hailobackportbot[bot]
authored andcommitted
fix: folder tree selection after any action in main content
Signed-off-by: mykh-hailo <kristianderonta0205@gmail.com>
1 parent 5b6e217 commit c022fd6

4 files changed

Lines changed: 34 additions & 5 deletions

File tree

apps/files/src/components/FilesNavigationListItem.vue

Lines changed: 4 additions & 1 deletion
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 } 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"

apps/files/src/views/FilesNavigation.vue

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
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 { computed, provide, ref, watchEffect } from 'vue'
4646
import { useRoute } from 'vue-router/composables'
4747
import NcAppNavigation from '@nextcloud/vue/components/NcAppNavigation'
4848
import NcAppNavigationItem from '@nextcloud/vue/components/NcAppNavigationItem'
@@ -65,6 +65,32 @@ const allViews = useViews()
6565
6666
const route = useRoute()
6767
const 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+
6894
watchEffect(() => {
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...`)

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)