Skip to content

Commit 26b42e9

Browse files
susnuxartonge
andcommitted
fix(files): reuse available date for folder tree
Co-authored-by: Ferdinand Thiessen <opensource@fthiessen.de> Co-authored-by: Louis <louis@chmn.me> Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 9def7a8 commit 26b42e9

File tree

4 files changed

+179
-97
lines changed

4 files changed

+179
-97
lines changed

apps/files/src/eventbus.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ declare module '@nextcloud/event-bus' {
1212
'files:config:updated': { key: string, value: UserConfig[string] }
1313
'files:view-config:updated': { key: string, value: string | number | boolean, IView: string }
1414

15+
'files:list:initialized': undefined
16+
1517
'files:favorites:added': INode
1618
'files:favorites:removed': INode
1719

apps/files/src/views/FilesList.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ export default defineComponent({
285285
286286
data() {
287287
return {
288+
initialized: false,
289+
288290
loading: true,
289291
loadingAction: null as string | null,
290292
error: null as string | null,
@@ -497,6 +499,15 @@ export default defineComponent({
497499
498500
currentFolder() {
499501
this.activeStore.activeFolder = this.currentFolder
502+
503+
// if not already initialized and we have a valid folder, we can consider the list as initialized
504+
if (!this.initialized
505+
&& this.currentFolder.fileid
506+
&& this.currentFolder.fileid > 0
507+
) {
508+
this.initialized = true
509+
this.$nextTick(async () => emit('files:list:initialized'))
510+
}
500511
},
501512
502513
currentView(newView, oldView) {

apps/files/src/views/FilesNavigation.vue

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@
4343
</template>
4444

4545
<script lang="ts">
46-
import type { View } from '@nextcloud/files'
47-
import type { ViewConfig } from '../types.ts'
46+
import type { IView, View } from '@nextcloud/files'
4847
49-
import { emit, subscribe } from '@nextcloud/event-bus'
48+
import { emit } from '@nextcloud/event-bus'
5049
import { getNavigation } from '@nextcloud/files'
5150
import { getCanonicalLocale, getLanguage, t } from '@nextcloud/l10n'
51+
import { watchDebounced } from '@vueuse/core'
5252
import { defineComponent } from 'vue'
5353
import NcAppNavigation from '@nextcloud/vue/components/NcAppNavigation'
5454
import NcAppNavigationItem from '@nextcloud/vue/components/NcAppNavigationItem'
@@ -94,6 +94,19 @@ export default defineComponent({
9494
const filtersStore = useFiltersStore()
9595
const viewConfigStore = useViewConfigStore()
9696
97+
const views = useViews()
98+
watchDebounced(views, () => {
99+
const expandedViews = Object.entries(viewConfigStore.viewConfigs)
100+
.filter(([, config]) => config.expanded)
101+
.map(([id]) => id)
102+
const expandedViewsWithChildView = views.value
103+
.filter((view) => 'loadChildViews' in view && view.loadChildViews)
104+
.filter((view) => expandedViews.includes(view.id)) as (View & Pick<Required<IView>, 'loadChildViews'>)[]
105+
for (const view of expandedViewsWithChildView) {
106+
view.loadChildViews(view)
107+
}
108+
}, { debounce: 100 })
109+
97110
return {
98111
t,
99112
@@ -102,7 +115,7 @@ export default defineComponent({
102115
filtersStore,
103116
viewConfigStore,
104117
105-
views: useViews(),
118+
views,
106119
}
107120
},
108121
@@ -123,18 +136,18 @@ export default defineComponent({
123136
/**
124137
* Map of parent ids to views
125138
*/
126-
viewMap(): Record<string, View[]> {
139+
viewMap(): Record<string, IView[]> {
127140
return this.views
128141
.reduce((map, view) => {
129142
map[view.parent!] = [...(map[view.parent!] || []), view]
130-
map[view.parent!].sort((a, b) => {
143+
map[view.parent!]!.sort((a, b) => {
131144
if (typeof a.order === 'number' || typeof b.order === 'number') {
132145
return (a.order ?? 0) - (b.order ?? 0)
133146
}
134147
return collator.compare(a.name, b.name)
135148
})
136149
return map
137-
}, {} as Record<string, View[]>)
150+
}, {} as Record<string, IView[]>)
138151
},
139152
},
140153
@@ -150,11 +163,6 @@ export default defineComponent({
150163
},
151164
},
152165
153-
created() {
154-
subscribe('files:folder-tree:initialized', this.loadExpandedViews)
155-
subscribe('files:folder-tree:expanded', this.loadExpandedViews)
156-
},
157-
158166
beforeMount() {
159167
// This is guaranteed to be a view because `currentViewId` falls back to the default 'files' view
160168
const view = this.views.find(({ id }) => id === this.currentViewId)!
@@ -163,23 +171,12 @@ export default defineComponent({
163171
},
164172
165173
methods: {
166-
async loadExpandedViews() {
167-
const viewsToLoad: View[] = (Object.entries(this.viewConfigStore.viewConfigs) as Array<[string, ViewConfig]>)
168-
.filter(([, config]) => config.expanded === true)
169-
.map(([viewId]) => this.views.find((view) => view.id === viewId))
170-
.filter(Boolean as unknown as ((u: unknown) => u is View))
171-
.filter((view) => view.loadChildViews && !view.loaded)
172-
for (const view of viewsToLoad) {
173-
await view.loadChildViews(view)
174-
}
175-
},
176-
177174
/**
178175
* Set the view as active on the navigation and handle internal state
179176
*
180177
* @param view View to set active
181178
*/
182-
showView(view: View) {
179+
showView(view: IView) {
183180
this.sidebar.close()
184181
getNavigation().setActive(view.id)
185182
emit('files:navigation:changed', view)

0 commit comments

Comments
 (0)