Shelf implementation complete

This commit is contained in:
aditya.chandel
2024-12-25 00:53:33 -07:00
parent f3427a4564
commit ebcd6cd908
4 changed files with 42 additions and 16 deletions
@@ -12,9 +12,12 @@
</div>
<div *ngIf="isAnyBookSelected()">
<p-button icon="pi pi-ellipsis-v" label="Options" severity="primary" [rounded]="true" [outlined]="true" (click)="menu.toggle($event)"></p-button>
<div class="button-container">
<p-button *ngIf="(entityType$ | async) === 'Library'" icon="pi pi-ellipsis-v" label="Options" severity="primary" [rounded]="true" [outlined]="true" (click)="menu.toggle($event)"></p-button>
<p-button *ngIf="(entityType$ | async) === 'Shelf'" icon="pi pi-minus-circle" label="Unshelf" severity="primary" [rounded]="true" [outlined]="true" (click)="unshelfBooks()"></p-button>
<p-button icon="pi pi-times" label="Deselect" severity="warning" [rounded]="true" [outlined]="true" (click)="deselectAllBooks()"></p-button>
</div>
<p-menu #menu [model]="items" [popup]="true" appendTo="body"></p-menu>
<p-button icon="pi pi-times" label="Deselect All" severity="warning" [rounded]="true" [outlined]="true" (click)="deselectAllBooks()"></p-button>
</div>
<div class="library-header-right">
@@ -55,3 +55,8 @@
display: flex;
justify-content: space-around;
}
.button-container {
display: flex;
gap: 10px; /* Adds 10px space between buttons */
}
@@ -25,6 +25,7 @@ export class BooksBrowserComponent implements OnInit {
items: MenuItem[] | undefined;
selectedBooks: Set<number> = new Set();
book: Book | undefined;
entity: Library | Shelf | null = null;
constructor(
private activatedRoute: ActivatedRoute,
@@ -88,6 +89,11 @@ export class BooksBrowserComponent implements OnInit {
return of(null);
})
);
this.entity$.subscribe(entity => {
this.entity = entity; // Store resolved value in local variable
});
}
handleBookSelect(book: Book, selected: boolean): void {
@@ -142,4 +148,19 @@ export class BooksBrowserComponent implements OnInit {
},
});
}
unshelfBooks() {
if (this.entity) {
this.bookService.assignShelvesToBook(this.selectedBooks, new Set(), new Set([this.entity.id])).subscribe(
() => {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book\'s shelves updated'});
this.selectedBooks = new Set<number>();
},
(error) => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book\'s shelves'});
}
);
}
}
}