@@ -8,10 +8,11 @@ import { Button } from 'primeng/button';
88import { filter , finalize , switchMap , take } from 'rxjs' ;
99
1010import { HttpEventType } from '@angular/common/http' ;
11- import { ChangeDetectionStrategy , Component , DestroyRef , inject , input , output , signal } from '@angular/core' ;
11+ import { ChangeDetectionStrategy , Component , DestroyRef , effect , inject , input , output , signal } from '@angular/core' ;
1212import { takeUntilDestroyed , toObservable } from '@angular/core/rxjs-interop' ;
1313
1414import { CreateFolderDialogComponent } from '@osf/features/files/components' ;
15+ import { DeleteEntry } from '@osf/features/files/store' ;
1516import { FileUploadDialogComponent } from '@osf/shared/components/file-upload-dialog/file-upload-dialog.component' ;
1617import { FilesTreeComponent } from '@osf/shared/components/files-tree/files-tree.component' ;
1718import { LoadingSpinnerComponent } from '@osf/shared/components/loading-spinner/loading-spinner.component' ;
@@ -53,7 +54,9 @@ export class FilesControlComponent {
5354 projectId = input . required < string > ( ) ;
5455 provider = input . required < string > ( ) ;
5556 filesViewOnly = input < boolean > ( false ) ;
57+ isDraftResource = input < boolean > ( false ) ;
5658 attachFile = output < FileModel > ( ) ;
59+ removeFromAttachedFiles = output < FileModel > ( ) ;
5760 openFile = output < FileModel > ( ) ;
5861
5962 private readonly filesService = inject ( FilesService ) ;
@@ -69,6 +72,7 @@ export class FilesControlComponent {
6972 readonly progress = signal ( 0 ) ;
7073 readonly fileName = signal ( '' ) ;
7174 readonly dataLoaded = signal ( false ) ;
75+ pageNumber = signal ( 1 ) ;
7276
7377 fileIsUploading = signal ( false ) ;
7478 filesSelection : FileModel [ ] = [ ] ;
@@ -79,11 +83,38 @@ export class FilesControlComponent {
7983 setFilesIsLoading : SetFilesIsLoading ,
8084 setCurrentFolder : SetRegistriesCurrentFolder ,
8185 getRootFolders : GetRootFolders ,
86+ deleteEntry : DeleteEntry ,
8287 } ) ;
8388
8489 constructor ( ) {
8590 this . setupRootFoldersLoader ( ) ;
8691 this . setupCurrentFolderWatcher ( ) ;
92+
93+ effect ( ( ) => {
94+ const currentFolder = this . currentFolder ( ) ;
95+ if ( currentFolder ) {
96+ this . pageNumber . set ( 1 ) ;
97+ this . updateFilesList ( ) ;
98+ }
99+ } ) ;
100+ }
101+
102+ updateFilesList = ( ) : void => {
103+ const currentFolder = this . currentFolder ( ) ;
104+ const filesLink = currentFolder ?. links . filesLink ;
105+ if ( filesLink ) {
106+ this . actions . getFiles ( filesLink , this . pageNumber ( ) ) ;
107+ }
108+ } ;
109+
110+ deleteEntry ( file : FileModel ) : void {
111+ this . actions . deleteEntry ( file ?. links . delete ) . subscribe ( ( ) => {
112+ this . toastService . showSuccess ( 'files.dialogs.deleteFile.success' ) ;
113+ this . updateFilesList ( ) ;
114+ if ( this . isDraftResource ( ) ) {
115+ this . removeFromAttachedFiles . emit ( file ) ;
116+ }
117+ } ) ;
87118 }
88119
89120 onFileSelected ( event : Event ) : void {
@@ -169,6 +200,10 @@ export class FilesControlComponent {
169200 this . filesSelection = [ ...new Set ( this . filesSelection ) ] ;
170201 }
171202
203+ onRemoveFromAttachedFiles ( file : FileModel ) {
204+ this . removeFromAttachedFiles . emit ( file ) ;
205+ }
206+
172207 onLoadFiles ( event : { link : string ; page : number } ) {
173208 this . actions . getFiles ( event . link , event . page ) ;
174209 }
0 commit comments