New subscribe pattern

This commit is contained in:
aditya.chandel
2025-01-13 11:57:50 -07:00
parent 2cbf49a5e6
commit b0cd19189b
4 changed files with 42 additions and 42 deletions
@@ -36,7 +36,7 @@ export class FileUploadComponent {
private fileUploadService: FileUploadService,
private toastService: ToastService,
private dynamicDialogRef: DynamicDialogRef) {
this.libraryState$ = this.libraryService.libraryState$;
this.libraryState$ = this.libraryService.libraryState$;
}
triggerFileInput(fileInput: HTMLInputElement): void {
@@ -70,19 +70,18 @@ export class FileUploadComponent {
const libraryId = this.selectedLibrary?.id ? this.selectedLibrary.id.toString() : '';
const path = this.selectedPath || '';
this.isUploading = true;
this.fileUploadService.uploadFile(file, libraryId, path)
.subscribe(
() => {
console.log('File uploaded successfully');
this.toastService.showSuccess("File uploaded", file.name);
this.isUploading = false;
this.dynamicDialogRef.close();
},
(error) => {
this.isUploading = false;
this.toastService.showError("Upload failed", error.error.message);
this.errorMessage = "Upload failed. " + error.error.message + ".";
}
);
this.fileUploadService.uploadFile(file, libraryId, path).subscribe({
next: () => {
console.log('File uploaded successfully');
this.toastService.showSuccess("File uploaded", file.name);
this.isUploading = false;
this.dynamicDialogRef.close();
},
error: (e) => {
this.isUploading = false;
this.toastService.showError("Upload failed", e.error.message);
this.errorMessage = "Upload failed. " + e.error.message + ".";
}
});
}
}