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
@@ -43,8 +43,7 @@
<div class="book-card-container" *ngIf="bookState?.books as books"> <div class="book-card-container" *ngIf="bookState?.books as books">
<app-book-table *ngIf="value === 'table'&& books.length > 0" [books]="books" (selectedBooksChange)="onSelectedBooksChange($event)" <app-book-table *ngIf="value === 'table'&& books.length > 0" [books]="books" (selectedBooksChange)="onSelectedBooksChange($event)" [sortOption]="selectedSort"></app-book-table>
[sortOption]="selectedSort"></app-book-table>
<virtual-scroller *ngIf="value === 'grid'" class="virtual-scroller" #scroll [items]="books"> <virtual-scroller *ngIf="value === 'grid'" class="virtual-scroller" #scroll [items]="books">
<div class="grid grid-cols-12 gap-4" #container> <div class="grid grid-cols-12 gap-4" #container>
@@ -269,13 +269,15 @@ export class BookBrowserComponent implements OnInit {
unshelfBooks() { unshelfBooks() {
if (this.entity) { if (this.entity) {
this.bookService.updateBookShelves(this.selectedBooks, new Set(), new Set([this.entity.id])).subscribe( this.bookService.updateBookShelves(this.selectedBooks, new Set(), new Set([this.entity.id])).subscribe(
() => { {
next: () => {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Books shelves updated'}); this.messageService.add({severity: 'info', summary: 'Success', detail: 'Books shelves updated'});
this.selectedBooks = new Set<number>(); this.selectedBooks = new Set<number>();
}, },
() => { error: () => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update books shelves'}); this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update books shelves'});
} }
}
); );
} }
} }
@@ -79,16 +79,16 @@ export class ShelfAssignerComponent implements OnInit {
name: this.shelfName, name: this.shelfName,
icon: this.selectedIcon ? this.selectedIcon.replace('pi pi-', '') : 'heart' icon: this.selectedIcon ? this.selectedIcon.replace('pi pi-', '') : 'heart'
}; };
this.shelfService.createShelf(newShelf as Shelf).subscribe( this.shelfService.createShelf(newShelf as Shelf).subscribe({
() => { next: () => {
this.messageService.add({severity: 'info', summary: 'Success', detail: `Shelf created: ${this.shelfName}`}); this.messageService.add({severity: 'info', summary: 'Success', detail: `Shelf created: ${this.shelfName}`});
this.displayShelfDialog = false; this.displayShelfDialog = false;
}, },
error => { error: (e) => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to create shelf'}); this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to create shelf'});
console.error('Error creating shelf:', error); console.error('Error creating shelf:', e);
} }
); });
} }
updateBooksShelves(): void { updateBooksShelves(): void {
@@ -70,19 +70,18 @@ export class FileUploadComponent {
const libraryId = this.selectedLibrary?.id ? this.selectedLibrary.id.toString() : ''; const libraryId = this.selectedLibrary?.id ? this.selectedLibrary.id.toString() : '';
const path = this.selectedPath || ''; const path = this.selectedPath || '';
this.isUploading = true; this.isUploading = true;
this.fileUploadService.uploadFile(file, libraryId, path) this.fileUploadService.uploadFile(file, libraryId, path).subscribe({
.subscribe( next: () => {
() => {
console.log('File uploaded successfully'); console.log('File uploaded successfully');
this.toastService.showSuccess("File uploaded", file.name); this.toastService.showSuccess("File uploaded", file.name);
this.isUploading = false; this.isUploading = false;
this.dynamicDialogRef.close(); this.dynamicDialogRef.close();
}, },
(error) => { error: (e) => {
this.isUploading = false; this.isUploading = false;
this.toastService.showError("Upload failed", error.error.message); this.toastService.showError("Upload failed", e.error.message);
this.errorMessage = "Upload failed. " + error.error.message + "."; this.errorMessage = "Upload failed. " + e.error.message + ".";
} }
); });
} }
} }