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'
5049import { getNavigation } from ' @nextcloud/files'
5150import { getCanonicalLocale , getLanguage , t } from ' @nextcloud/l10n'
51+ import { watchDebounced } from ' @vueuse/core'
5252import { defineComponent } from ' vue'
5353import NcAppNavigation from ' @nextcloud/vue/components/NcAppNavigation'
5454import 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