feat(icons): Made icons for libraries and shelves optional with no default icons. (#2599)

* feat(icons): Made icons for libraries and shelves optional with no default icon displayed.

* Added tests for making sure the API handles nullable icons for Shelves and Libraries.

* Fixed some issues identified during PR review.

* Rebased on develop.
This commit is contained in:
Giroux Arthur
2026-02-07 08:25:34 -07:00
committed by GitHub
parent 07cbf89e4c
commit 14236299f2
28 changed files with 817 additions and 90 deletions
@@ -21,6 +21,10 @@ import {DomSanitizer, SafeHtml} from '@angular/platform-browser';
[ngStyle]="getSvgStyle()"
></div>
}
} @else if (displayEmpty) {
<div
[ngStyle]="getEmptyIconStyle()"
></div>
}
`,
styles: [`
@@ -50,6 +54,7 @@ export class IconDisplayComponent implements OnInit, OnChanges {
@Input() iconStyle: Record<string, string> = {};
@Input() size: string = '16px';
@Input() alt: string = 'Icon';
@Input() displayEmpty: boolean = false;
private iconCache = inject(IconCacheService);
private iconService = inject(IconService);
@@ -115,6 +120,13 @@ export class IconDisplayComponent implements OnInit, OnChanges {
};
}
getEmptyIconStyle(): Record<string, string> {
return {
width: this.size,
height: this.size,
};
}
getPrimeNgStyle(): Record<string, string> {
const fontSize = this.size.endsWith('px')
? `${parseInt(this.size) * 0.85}px`
@@ -109,8 +109,8 @@ export class AppMenuComponent implements OnInit {
menu: this.libraryShelfMenuService.initializeLibraryMenuItems(library),
label: library.name,
type: 'Library',
icon: library.icon,
iconType: (library.iconType || 'PRIME_NG') as 'PRIME_NG' | 'CUSTOM_SVG',
icon: library.icon || undefined,
iconType: (library.iconType || undefined) as 'PRIME_NG' | 'CUSTOM_SVG' | undefined,
routerLink: [`/library/${library.id}/books`],
bookCount$: this.libraryService.getBookCount(library.id ?? 0),
})),
@@ -132,8 +132,8 @@ export class AppMenuComponent implements OnInit {
items: sortedShelves.map((shelf) => ({
label: shelf.name,
type: 'magicShelfItem',
icon: shelf.icon || 'pi pi-book',
iconType: (shelf.iconType || 'PRIME_NG') as 'PRIME_NG' | 'CUSTOM_SVG',
icon: shelf.icon || undefined,
iconType: (shelf.iconType || undefined) as 'PRIME_NG' | 'CUSTOM_SVG' | undefined,
menu: this.libraryShelfMenuService.initializeMagicShelfMenuItems(shelf),
routerLink: [`/magic-shelf/${shelf.id}/books`],
bookCount$: this.magicShelfService.getBookCount(shelf.id ?? 0),
@@ -158,8 +158,8 @@ export class AppMenuComponent implements OnInit {
menu: this.libraryShelfMenuService.initializeShelfMenuItems(shelf),
label: shelf.name,
type: 'Shelf',
icon: shelf.icon,
iconType: (shelf.iconType || 'PRIME_NG') as 'PRIME_NG' | 'CUSTOM_SVG',
icon: shelf.icon || undefined,
iconType: (shelf.iconType || undefined) as 'PRIME_NG' | 'CUSTOM_SVG' | undefined,
routerLink: [`/shelf/${shelf.id}/books`],
bookCount$: this.shelfService.getBookCount(shelf.id ?? 0),
}));
@@ -173,13 +173,13 @@ export class AppMenuComponent implements OnInit {
bookCount$: this.shelfService.getUnshelvedBookCount?.() ?? of(0),
};
const items = [unshelvedItem];
const items: MenuItem[] = [unshelvedItem];
if (koboShelf) {
items.push({
label: koboShelf.name,
type: 'Shelf',
icon: koboShelf.icon,
iconType: (koboShelf.iconType || 'PRIME_NG') as 'PRIME_NG' | 'CUSTOM_SVG',
icon: koboShelf.icon || undefined,
iconType: (koboShelf.iconType || undefined) as 'PRIME_NG' | 'CUSTOM_SVG' | undefined,
routerLink: [`/shelf/${koboShelf.id}/books`],
bookCount$: this.shelfService.getBookCount(koboShelf.id ?? 0),
});
@@ -57,6 +57,7 @@
[icon]="getIconSelection()"
iconClass="layout-menuitem-icon"
size="18px"
[displayEmpty]="true"
></app-icon-display>
<span class="layout-menuitem-text menu-item-text">
{{ item.label }}