4848 :nodes =" nodes" />
4949 </template >
5050
51+ <!-- Body replacement if no files are available -->
52+ <template #empty >
53+ <slot name =" empty" />
54+ </template >
55+
5156 <!-- Tfoot-->
5257 <template #footer >
5358 <FilesListTableFooter :current-view =" currentView"
6570import type { UserConfig } from ' ../types'
6671import type { Node as NcNode } from ' @nextcloud/files'
6772import type { ComponentPublicInstance , PropType } from ' vue'
68- import type { Location } from ' vue-router'
6973
7074import { Folder , Permission , View , getFileActions , FileType } from ' @nextcloud/files'
7175import { showError } from ' @nextcloud/dialogs'
@@ -81,6 +85,7 @@ import { useFileListWidth } from '../composables/useFileListWidth.ts'
8185import { useRouteParameters } from ' ../composables/useRouteParameters.ts'
8286import { useSelectionStore } from ' ../store/selection.js'
8387import { useUserConfigStore } from ' ../store/userconfig.ts'
88+ import logger from ' ../logger.ts'
8489
8590import FileEntry from ' ./FileEntry.vue'
8691import FileEntryGrid from ' ./FileEntryGrid.vue'
@@ -90,7 +95,6 @@ import FilesListTableFooter from './FilesListTableFooter.vue'
9095import FilesListTableHeader from ' ./FilesListTableHeader.vue'
9196import FilesListTableHeaderActions from ' ./FilesListTableHeaderActions.vue'
9297import VirtualList from ' ./VirtualList.vue'
93- import logger from ' ../logger.ts'
9498
9599export default defineComponent ({
96100 name: ' FilesListVirtual' ,
@@ -152,7 +156,6 @@ export default defineComponent({
152156 FileEntry ,
153157 FileEntryGrid ,
154158 scrollToIndex: 0 ,
155- openFileId: null as number | null ,
156159 }
157160 },
158161
@@ -217,39 +220,26 @@ export default defineComponent({
217220 isNoneSelected() {
218221 return this .selectedNodes .length === 0
219222 },
223+
224+ isEmpty() {
225+ return this .nodes .length === 0
226+ },
220227 },
221228
222229 watch: {
223- fileId: {
224- handler(fileId ) {
225- this .scrollToFile (fileId , false )
226- },
227- immediate: true ,
230+ // If nodes gets populated and we have a fileId,
231+ // an openFile or openDetails, we fire the appropriate actions.
232+ isEmpty() {
233+ this .handleOpenQueries ()
228234 },
229-
230- openFile: {
231- handler(openFile ) {
232- if (! openFile || ! this .fileId ) {
233- return
234- }
235-
236- this .handleOpenFile (this .fileId )
237- },
238- immediate: true ,
235+ fileId() {
236+ this .handleOpenQueries ()
239237 },
240-
241- openDetails: {
242- handler(openDetails ) {
243- // wait for scrolling and updating the actions to settle
244- this .$nextTick (() => {
245- if (! openDetails || ! this .fileId ) {
246- return
247- }
248-
249- this .openSidebarForFile (this .fileId )
250- })
251- },
252- immediate: true ,
238+ openFile() {
239+ this .handleOpenQueries ()
240+ },
241+ openDetails() {
242+ this .handleOpenQueries ()
253243 },
254244 },
255245
@@ -279,6 +269,33 @@ export default defineComponent({
279269 },
280270
281271 methods: {
272+ handleOpenQueries() {
273+ // If the list is empty, or we don't have a fileId,
274+ // there's nothing to be done.
275+ if (this .isEmpty || ! this .fileId ) {
276+ return
277+ }
278+
279+ logger .debug (' FilesListVirtual: checking for requested fileId, openFile or openDetails' , {
280+ nodes: this .nodes ,
281+ fileId: this .fileId ,
282+ openFile: this .openFile ,
283+ openDetails: this .openDetails ,
284+ })
285+
286+ if (this .openFile ) {
287+ this .handleOpenFile (this .fileId )
288+ }
289+
290+ if (this .openDetails ) {
291+ this .openSidebarForFile (this .fileId )
292+ }
293+
294+ if (this .fileId ) {
295+ this .scrollToFile (this .fileId , false )
296+ }
297+ },
298+
282299 openSidebarForFile(fileId ) {
283300 // Open the sidebar for the given URL fileid
284301 // iif we just loaded the app.
@@ -288,7 +305,7 @@ export default defineComponent({
288305 sidebarAction .exec (node , this .currentView , this .currentFolder .path )
289306 return
290307 }
291- logger .error (` Failed to open sidebar on file ${fileId }, file isn't cached yet ! ` , { fileId , node })
308+ logger .warn (` Failed to open sidebar on file ${fileId }, file isn't cached yet ! ` , { fileId , node })
292309 },
293310
294311 scrollToFile(fileId : number | null , warn = true ) {
@@ -304,6 +321,7 @@ export default defineComponent({
304321 }
305322
306323 this .scrollToIndex = Math .max (0 , index )
324+ logger .debug (' Scrolling to file ' + fileId , { fileId , index })
307325 }
308326 },
309327
@@ -368,15 +386,13 @@ export default defineComponent({
368386 }
369387 // The file is either a folder or has no default action other than downloading
370388 // in this case we need to open the details instead and remove the route from the history
371- const query = this .$route .query
372- delete query .openfile
373- query .opendetails = ' '
374-
375389 logger .debug (' Ignore `openfile` query and replacing with `opendetails` for ' + node .path , { node })
376- await this .$router .replace ({
377- ... (this .$route as Location ),
378- query ,
379- })
390+ window .OCP .Files .Router .goToRoute (
391+ null ,
392+ this .$route .params ,
393+ { ... this .$route .query , openfile: undefined , opendetails: ' ' },
394+ true , // silent update of the URL
395+ )
380396 },
381397
382398 onDragOver(event : DragEvent ) {
@@ -474,6 +490,8 @@ export default defineComponent({
474490 --icon-preview-size : 32px ;
475491
476492 --fixed-block-start-position : var (--default-clickable-area );
493+ display : flex ;
494+ flex-direction : column ;
477495 overflow : auto ;
478496 height : 100% ;
479497 will-change : scroll-position ;
@@ -521,6 +539,13 @@ export default defineComponent({
521539 // Hide the table header below the overlay
522540 margin-block-start : calc (-1 * var (--row-height ));
523541 }
542+
543+ // Visually hide the table when there are no files
544+ & --hidden {
545+ visibility : hidden ;
546+ z-index : -1 ;
547+ opacity : 0 ;
548+ }
524549 }
525550
526551 .files-list__filters {
@@ -570,6 +595,16 @@ export default defineComponent({
570595 top : var (--fixed-block-start-position );
571596 }
572597
598+ // Empty content
599+ .files-list__empty {
600+ display : flex ;
601+ flex-direction : column ;
602+ align-items : center ;
603+ justify-content : center ;
604+ width : 100% ;
605+ height : 100% ;
606+ }
607+
573608 tr {
574609 position : relative ;
575610 display : flex ;
0 commit comments