New subscribe pattern
This commit is contained in:
@@ -43,8 +43,7 @@
|
||||
|
||||
<div class="book-card-container" *ngIf="bookState?.books as books">
|
||||
|
||||
<app-book-table *ngIf="value === 'table'&& books.length > 0" [books]="books" (selectedBooksChange)="onSelectedBooksChange($event)"
|
||||
[sortOption]="selectedSort"></app-book-table>
|
||||
<app-book-table *ngIf="value === 'table'&& books.length > 0" [books]="books" (selectedBooksChange)="onSelectedBooksChange($event)" [sortOption]="selectedSort"></app-book-table>
|
||||
|
||||
<virtual-scroller *ngIf="value === 'grid'" class="virtual-scroller" #scroll [items]="books">
|
||||
<div class="grid grid-cols-12 gap-4" #container>
|
||||
|
||||
@@ -269,12 +269,14 @@ export class BookBrowserComponent implements OnInit {
|
||||
unshelfBooks() {
|
||||
if (this.entity) {
|
||||
this.bookService.updateBookShelves(this.selectedBooks, new Set(), new Set([this.entity.id])).subscribe(
|
||||
() => {
|
||||
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Books shelves updated'});
|
||||
this.selectedBooks = new Set<number>();
|
||||
},
|
||||
() => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update books shelves'});
|
||||
{
|
||||
next: () => {
|
||||
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Books shelves updated'});
|
||||
this.selectedBooks = new Set<number>();
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update books shelves'});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog';
|
||||
import { Book } from '../../model/book.model';
|
||||
import {Component, OnInit, ViewChild} from '@angular/core';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Book} from '../../model/book.model';
|
||||
import {MessageService, PrimeTemplate} from 'primeng/api';
|
||||
import { ShelfService } from '../../service/shelf.service';
|
||||
import { Observable } from 'rxjs';
|
||||
import { BookService } from '../../service/book.service';
|
||||
import { map, tap } from 'rxjs/operators';
|
||||
import { Shelf } from '../../model/shelf.model';
|
||||
import { IconPickerComponent } from '../../../utilities/component/icon-picker/icon-picker.component';
|
||||
import { ShelfState } from '../../model/state/shelf-state.model';
|
||||
import {ShelfService} from '../../service/shelf.service';
|
||||
import {Observable} from 'rxjs';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {map, tap} from 'rxjs/operators';
|
||||
import {Shelf} from '../../model/shelf.model';
|
||||
import {IconPickerComponent} from '../../../utilities/component/icon-picker/icon-picker.component';
|
||||
import {ShelfState} from '../../model/state/shelf-state.model';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {AsyncPipe, NgForOf, NgIf} from '@angular/common';
|
||||
@@ -79,16 +79,16 @@ export class ShelfAssignerComponent implements OnInit {
|
||||
name: this.shelfName,
|
||||
icon: this.selectedIcon ? this.selectedIcon.replace('pi pi-', '') : 'heart'
|
||||
};
|
||||
this.shelfService.createShelf(newShelf as Shelf).subscribe(
|
||||
() => {
|
||||
this.messageService.add({ severity: 'info', summary: 'Success', detail: `Shelf created: ${this.shelfName}` });
|
||||
this.shelfService.createShelf(newShelf as Shelf).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({severity: 'info', summary: 'Success', detail: `Shelf created: ${this.shelfName}`});
|
||||
this.displayShelfDialog = false;
|
||||
},
|
||||
error => {
|
||||
this.messageService.add({ severity: 'error', summary: 'Error', detail: 'Failed to create shelf' });
|
||||
console.error('Error creating shelf:', error);
|
||||
error: (e) => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to create shelf'});
|
||||
console.error('Error creating shelf:', e);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
updateBooksShelves(): void {
|
||||
@@ -101,11 +101,11 @@ export class ShelfAssignerComponent implements OnInit {
|
||||
private updateBookShelves(bookIds: Set<number>, idsToAssign: Set<number | undefined>, idsToUnassign: Set<number>): void {
|
||||
this.bookService.updateBookShelves(bookIds, idsToAssign, idsToUnassign).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({ severity: 'info', summary: 'Success', detail: 'Book shelves updated' });
|
||||
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book shelves updated'});
|
||||
this.dynamicDialogRef.close();
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({ severity: 'error', summary: 'Error', detail: 'Failed to update book shelves' });
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book shelves'});
|
||||
this.dynamicDialogRef.close();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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 + ".";
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user