@@ -5,7 +5,7 @@ import { DialogService } from 'primeng/dynamicdialog';
55import { PaginatorState } from 'primeng/paginator' ;
66import { Tree , TreeNodeDropEvent } from 'primeng/tree' ;
77
8- import { EMPTY , finalize , firstValueFrom , Observable , take } from 'rxjs' ;
8+ import { EMPTY , finalize , Observable , take } from 'rxjs' ;
99
1010import { Clipboard } from '@angular/cdk/clipboard' ;
1111import { DatePipe } from '@angular/common' ;
@@ -114,6 +114,22 @@ export class FilesTreeComponent implements OnDestroy, AfterViewInit {
114114 }
115115 } ) ;
116116
117+ constructor ( ) {
118+ effect ( ( ) => {
119+ const currentFolder = this . currentFolder ( ) ;
120+ if ( currentFolder ) {
121+ this . updateFilesList ( currentFolder ) . subscribe ( ( ) => this . folderIsOpening . emit ( false ) ) ;
122+ }
123+ } ) ;
124+
125+ effect ( ( ) => {
126+ const storageChanged = this . storage ( ) ;
127+ if ( storageChanged ) {
128+ this . foldersStack = [ ] ;
129+ }
130+ } ) ;
131+ }
132+
117133 ngAfterViewInit ( ) : void {
118134 if ( ! this . viewOnly ( ) ) {
119135 this . dropZoneContainerRef ( ) ! . nativeElement . addEventListener ( 'dragenter' , this . dragEnterHandler ) ;
@@ -176,22 +192,6 @@ export class FilesTreeComponent implements OnDestroy, AfterViewInit {
176192 }
177193 }
178194
179- constructor ( ) {
180- effect ( ( ) => {
181- const currentFolder = this . currentFolder ( ) ;
182- if ( currentFolder ) {
183- this . updateFilesList ( currentFolder ) . subscribe ( ( ) => this . folderIsOpening . emit ( false ) ) ;
184- }
185- } ) ;
186-
187- effect ( ( ) => {
188- const storageChanged = this . storage ( ) ;
189- if ( storageChanged ) {
190- this . foldersStack = [ ] ;
191- }
192- } ) ;
193- }
194-
195195 openEntry ( file : OsfFile ) {
196196 if ( file . kind === 'file' ) {
197197 if ( file . guid ) {
@@ -366,21 +366,27 @@ export class FilesTreeComponent implements OnDestroy, AfterViewInit {
366366 ? this . translateService . instant ( 'files.dialogs.moveFile.title' )
367367 : this . translateService . instant ( 'files.dialogs.copyFile.title' ) ;
368368
369- this . dialogService . open ( MoveFileDialogComponent , {
370- width : '552px' ,
371- focusOnShow : false ,
372- header : header ,
373- closeOnEscape : true ,
374- modal : true ,
375- closable : true ,
376- data : {
377- file : file ,
378- resourceId : this . resourceId ( ) ,
379- action : action ,
380- storageName : this . storage ( ) ?. label ,
381- foldersStack : [ ...this . foldersStack ] ,
382- } ,
383- } ) ;
369+ this . dialogService
370+ . open ( MoveFileDialogComponent , {
371+ width : '552px' ,
372+ focusOnShow : false ,
373+ header : header ,
374+ closeOnEscape : true ,
375+ modal : true ,
376+ closable : true ,
377+ data : {
378+ file : file ,
379+ resourceId : this . resourceId ( ) ,
380+ action : action ,
381+ storageName : this . storage ( ) ?. label ,
382+ foldersStack : [ ...this . foldersStack ] ,
383+ } ,
384+ } )
385+ . onClose . subscribe ( ( foldersStack ) => {
386+ if ( foldersStack ) {
387+ this . foldersStack = [ ...foldersStack ] ;
388+ }
389+ } ) ;
384390 } ) ;
385391 }
386392
@@ -424,17 +430,20 @@ export class FilesTreeComponent implements OnDestroy, AfterViewInit {
424430
425431 const dropNode = event . dropNode as OsfFile ;
426432 const dragNode = event . dragNode as OsfFile ;
427- let path = dropNode ?. path ;
428433 const moveLink = dragNode ?. links ?. move ;
429- let parentFolder : OsfFile | null = null ;
434+ let targetFolder : OsfFile | null = null ;
435+ let path = '' ;
430436
431437 if ( dropNode ?. previousFolder ) {
432- parentFolder = await firstValueFrom ( this . filesService . getFolder ( dropNode . relationships . parentFolderLink ) ) ;
433- if ( ! parentFolder . relationships . parentFolderLink ) {
434- path = '/' ;
438+ if ( this . foldersStack . length > 0 ) {
439+ targetFolder = this . foldersStack [ this . foldersStack . length - 1 ] ;
440+ path = targetFolder ?. path || '/' ;
435441 } else {
436- path = parentFolder . path ;
442+ path = '/' ;
437443 }
444+ } else {
445+ targetFolder = dropNode ;
446+ path = dropNode ?. path || '/' ;
438447 }
439448
440449 if ( ! path ) {
@@ -446,19 +455,23 @@ export class FilesTreeComponent implements OnDestroy, AfterViewInit {
446455 . pipe (
447456 take ( 1 ) ,
448457 finalize ( ( ) => {
449- this . actions ( ) . setCurrentFolder ( dropNode ?. previousFolder ? parentFolder : dropNode ) ;
458+ if ( dropNode ?. previousFolder ) {
459+ if ( this . foldersStack . length > 0 ) {
460+ this . foldersStack . pop ( ) ;
461+ }
462+ this . actions ( ) . setCurrentFolder ( targetFolder ) ;
463+ } else {
464+ if ( this . currentFolder ( ) ) {
465+ this . foldersStack . push ( this . currentFolder ( ) ! ) ;
466+ }
467+ this . actions ( ) . setCurrentFolder ( targetFolder ) ;
468+ }
450469 } )
451470 )
452471 . subscribe ( ( file ) => {
453472 if ( file . id ) {
454- if ( dropNode ?. previousFolder ) {
455- const filesLink = parentFolder ?. relationships . filesLink ;
456-
457- if ( filesLink ) {
458- this . actions ( ) . getFiles ( filesLink ) ;
459- }
460- } else {
461- const filesLink = dropNode ?. relationships . filesLink ;
473+ const filesLink = targetFolder ?. relationships . filesLink ;
474+ if ( filesLink ) {
462475 this . actions ( ) . getFiles ( filesLink ) ;
463476 }
464477 }
0 commit comments