From 4d9362a1b4aad9ea2e1a72caa7122bade1349955 Mon Sep 17 00:00:00 2001 From: Aditya Chandel <8075870+adityachandelgit@users.noreply.github.com> Date: Mon, 24 Nov 2025 08:42:07 -0700 Subject: [PATCH] Add a shelf creation button to the left menu bar and improve the layout of the shelf creation page (#1617) --- .../booklore/util/FileService.java | 3 +- .../book-browser/BookDialogHelperService.ts | 19 +- .../shelf-assigner.component.html | 122 ++++-- .../shelf-assigner.component.scss | 358 ++++++++++++++++ .../shelf-assigner.component.ts | 61 +-- .../shelf-creator.component.html | 105 +++++ .../shelf-creator.component.scss | 384 ++++++++++++++++++ .../shelf-creator/shelf-creator.component.ts | 65 +++ .../layout-menu/app.menu.component.ts | 2 +- .../layout-menu/app.menuitem.component.ts | 8 +- 10 files changed, 1036 insertions(+), 91 deletions(-) create mode 100644 booklore-ui/src/app/features/book/components/shelf-creator/shelf-creator.component.html create mode 100644 booklore-ui/src/app/features/book/components/shelf-creator/shelf-creator.component.scss create mode 100644 booklore-ui/src/app/features/book/components/shelf-creator/shelf-creator.component.ts diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/util/FileService.java b/booklore-api/src/main/java/com/adityachandel/booklore/util/FileService.java index a89d6ab7a..05eed5d40 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/util/FileService.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/util/FileService.java @@ -53,7 +53,6 @@ public class FileService { private final BookRepository bookRepository; private final BookAdditionalFileRepository bookAdditionalFileRepository; private final BookMapper bookMapper; - private final RestTemplate restTemplate; // @formatter:off private static final String IMAGES_DIR = "images"; @@ -171,7 +170,7 @@ public class FileService { HttpEntity entity = new HttpEntity<>(headers); - ResponseEntity response = restTemplate.exchange( + ResponseEntity response = new RestTemplate().exchange( imageUrl, HttpMethod.GET, entity, diff --git a/booklore-ui/src/app/features/book/components/book-browser/BookDialogHelperService.ts b/booklore-ui/src/app/features/book/components/book-browser/BookDialogHelperService.ts index b6dd59972..16028dfa7 100644 --- a/booklore-ui/src/app/features/book/components/book-browser/BookDialogHelperService.ts +++ b/booklore-ui/src/app/features/book/components/book-browser/BookDialogHelperService.ts @@ -7,6 +7,7 @@ import {BulkMetadataUpdateComponent} from '../../../metadata/component/bulk-meta import {MultiBookMetadataEditorComponent} from '../../../metadata/component/multi-book-metadata-editor/multi-book-metadata-editor-component'; import {MultiBookMetadataFetchComponent} from '../../../metadata/component/multi-book-metadata-fetch/multi-book-metadata-fetch-component'; import {FileMoverComponent} from '../../../../shared/components/file-mover/file-mover-component'; +import {ShelfCreatorComponent} from '../shelf-creator/shelf-creator.component'; @Injectable({providedIn: 'root'}) export class BookDialogHelperService { @@ -15,7 +16,7 @@ export class BookDialogHelperService { openShelfAssigner(bookIds: Set): DynamicDialogRef | null { return this.dialogService.open(ShelfAssignerComponent, { - header: `Update Books' Shelves`, + showHeader: false, modal: true, closable: true, contentStyle: {overflow: 'auto'}, @@ -31,6 +32,22 @@ export class BookDialogHelperService { }); } + openShelfCreator(): DynamicDialogRef { + return this.dialogService.open(ShelfCreatorComponent, { + showHeader: false, + modal: true, + draggable: false, + dismissableMask: true, + closable: true, + contentStyle: {overflow: 'auto'}, + baseZIndex: 10, + style: { + position: 'absolute', + top: '15%', + }, + })!; + } + openLockUnlockMetadataDialog(bookIds: Set): DynamicDialogRef | null { const count = bookIds.size; return this.dialogService.open(LockUnlockMetadataDialogComponent, { diff --git a/booklore-ui/src/app/features/book/components/shelf-assigner/shelf-assigner.component.html b/booklore-ui/src/app/features/book/components/shelf-assigner/shelf-assigner.component.html index e85c0b516..6e4f783f5 100644 --- a/booklore-ui/src/app/features/book/components/shelf-assigner/shelf-assigner.component.html +++ b/booklore-ui/src/app/features/book/components/shelf-assigner/shelf-assigner.component.html @@ -1,47 +1,89 @@ -
- -
- - @for (shelf of (shelfState$ | async)?.shelves; track shelf) { -
-
- - -
-
- } - -
- -
- - -
+
+
+
+ +
+
+

Assign Books to Shelves

+

+ @if (isMultiBooks) { + Select shelves for {{ bookIds.size }} {{ bookIds.size === 1 ? 'book' : 'books' }} + } @else { + Organize "{{ book.metadata?.title }}" into your shelves + } +

- -
- - -
-
- - @if (!selectedIcon) { -
- +
+ @if ((shelfState$ | async)?.shelves && (shelfState$ | async)!.shelves!.length > 0) { +
+
+ + + {{ (shelfState$ | async)!.shelves!.length }} {{ (shelfState$ | async)!.shelves!.length === 1 ? 'shelf' : 'shelves' }} available +
- } - @if (selectedIcon) { -
- - + +
+ @for (shelf of (shelfState$ | async)?.shelves; track shelf.id) { +
+
+ +
+ +
+ }
- } +
+ } @else { +
+
+ +
+

No Shelves Available

+

+ Create your first shelf to start organizing your books.
+ Click the button below to get started. +

+
+ } +
+ +
diff --git a/booklore-ui/src/app/features/book/components/shelf-assigner/shelf-assigner.component.scss b/booklore-ui/src/app/features/book/components/shelf-assigner/shelf-assigner.component.scss index e69de29bb..bf9e1b4fe 100644 --- a/booklore-ui/src/app/features/book/components/shelf-assigner/shelf-assigner.component.scss +++ b/booklore-ui/src/app/features/book/components/shelf-assigner/shelf-assigner.component.scss @@ -0,0 +1,358 @@ +.shelf-assigner { + width: 550px; + max-width: 550px; + display: flex; + flex-direction: column; + padding-top: 20px; + + @media (max-width: 640px) { + width: 100%; + max-width: 100%; + } +} + +.panel-header { + display: flex; + align-items: center; + gap: 1rem; + padding: 1.25rem; + background: linear-gradient(135deg, rgba(var(--primary-color-rgb), 0.1) 0%, rgba(var(--primary-color-rgb), 0.05) 100%); + border-radius: 10px 10px 0 0; + border: 1px solid var(--border-color); + border-bottom: none; + box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08); + + .header-icon-wrapper { + display: flex; + align-items: center; + justify-content: center; + width: 48px; + height: 48px; + background: var(--primary-color); + border-radius: 10px; + box-shadow: 0 3px 8px rgba(var(--primary-color-rgb), 0.3); + + .header-icon { + font-size: 1.5rem; + color: var(--primary-contrast-color); + } + } + + .header-text { + flex: 1; + + .panel-title { + margin: 0 0 0.25rem 0; + font-size: 1.25rem; + font-weight: 600; + color: var(--text-color); + } + + .panel-description { + margin: 0; + font-size: 0.875rem; + color: var(--text-secondary-color); + } + } + + @media (max-width: 480px) { + padding: 1rem; + + .header-icon-wrapper { + width: 40px; + height: 40px; + + .header-icon { + font-size: 1.25rem; + } + } + + .header-text { + .panel-title { + font-size: 1.125rem; + } + + .panel-description { + font-size: 0.8rem; + } + } + } +} + +.shelves-container { + display: flex; + flex-direction: column; + gap: 1rem; + padding: 1.5rem; + background: var(--card-background); + border: 1px solid var(--border-color); + box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08); + min-height: 350px; + max-height: 450px; + + @media (max-width: 480px) { + padding: 1rem; + min-height: 300px; + max-height: 400px; + } +} + +.shelves-list { + display: flex; + flex-direction: column; + gap: 0.75rem; + height: 100%; +} + +.list-header { + display: flex; + align-items: center; + justify-content: space-between; + padding: 0.625rem 0.875rem; + background: var(--overlay-background); + border-radius: 6px; + + .shelf-count { + display: flex; + align-items: center; + gap: 0.375rem; + font-size: 0.9rem; + font-weight: 600; + color: var(--text-color); + + i { + color: var(--primary-color); + } + } + + @media (max-width: 480px) { + padding: 0.5rem 0.625rem; + + .shelf-count { + font-size: 0.85rem; + } + } +} + +.shelves-grid { + display: flex; + flex-direction: column; + gap: 0.5rem; + overflow-y: auto; + flex: 1; + padding-right: 0.25rem; + + &::-webkit-scrollbar { + width: 6px; + } + + &::-webkit-scrollbar-track { + background: var(--overlay-background); + border-radius: 3px; + } + + &::-webkit-scrollbar-thumb { + background: var(--border-color); + border-radius: 3px; + transition: background 0.2s ease; + + &:hover { + background: var(--primary-color); + } + } + + scrollbar-width: thin; + scrollbar-color: var(--border-color) var(--overlay-background); +} + +.shelf-item { + display: flex; + align-items: center; + gap: 0.75rem; + padding: 0.75rem; + background: var(--ground-background); + border: 1px solid var(--border-color); + border-radius: 8px; + transition: all 0.3s ease; + cursor: pointer; + + &:hover { + border-color: var(--primary-color); + transform: translateX(3px); + box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1); + + .shelf-icon { + color: var(--primary-color); + transform: scale(1.08); + } + } + + &.selected { + background: rgba(var(--primary-color-rgb), 0.08); + border-color: var(--primary-color); + + .shelf-icon-wrapper { + background: var(--primary-color); + + .shelf-icon { + color: var(--primary-contrast-color); + } + } + } + + .shelf-checkbox { + display: flex; + align-items: center; + } + + .shelf-label { + flex: 1; + display: flex; + align-items: center; + gap: 0.75rem; + cursor: pointer; + min-width: 0; + + .shelf-icon-wrapper { + display: flex; + align-items: center; + justify-content: center; + width: 38px; + height: 38px; + background: var(--overlay-background); + border-radius: 8px; + flex-shrink: 0; + + .shelf-icon { + font-size: 1.125rem; + color: var(--text-secondary-color); + transition: all 0.3s ease; + } + } + + .shelf-name { + font-size: 0.9375rem; + color: var(--text-color); + font-weight: 500; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + } + } + + @media (max-width: 480px) { + padding: 0.625rem; + gap: 0.5rem; + + .shelf-label { + gap: 0.5rem; + + .shelf-icon-wrapper { + width: 32px; + height: 32px; + + .shelf-icon { + font-size: 1rem; + } + } + + .shelf-name { + font-size: 0.875rem; + } + } + } +} + +.empty-state { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + text-align: center; + padding: 2rem 1rem; + flex: 1; + + .empty-icon-wrapper { + display: flex; + align-items: center; + justify-content: center; + width: 80px; + height: 80px; + background: var(--overlay-background); + border-radius: 50%; + margin-bottom: 1rem; + + .empty-icon { + font-size: 2.5rem; + color: var(--text-secondary-color); + opacity: 0.5; + } + } + + .empty-title { + margin: 0 0 0.5rem 0; + font-size: 1.125rem; + font-weight: 600; + color: var(--text-color); + } + + .empty-description { + margin: 0; + font-size: 0.875rem; + color: var(--text-secondary-color); + max-width: 350px; + line-height: 1.5; + } + + @media (max-width: 480px) { + padding: 1.5rem 0.75rem; + + .empty-icon-wrapper { + width: 60px; + height: 60px; + + .empty-icon { + font-size: 2rem; + } + } + + .empty-title { + font-size: 1rem; + } + + .empty-description { + font-size: 0.8rem; + max-width: 100%; + } + } +} + +.dialog-footer { + display: flex; + justify-content: space-between; + align-items: center; + gap: 0.75rem; + padding: 1.25rem 1.5rem; + background: var(--card-background); + border: 1px solid var(--border-color); + border-top: none; + border-radius: 0 0 10px 10px; + box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06); + + .footer-actions { + display: flex; + gap: 0.75rem; + } + + @media (max-width: 480px) { + flex-direction: column; + padding: 1rem; + gap: 0.5rem; + + .footer-actions { + width: 100%; + justify-content: flex-end; + gap: 0.5rem; + } + } +} diff --git a/booklore-ui/src/app/features/book/components/shelf-assigner/shelf-assigner.component.ts b/booklore-ui/src/app/features/book/components/shelf-assigner/shelf-assigner.component.ts index 29403d33a..a4dd7118d 100644 --- a/booklore-ui/src/app/features/book/components/shelf-assigner/shelf-assigner.component.ts +++ b/booklore-ui/src/app/features/book/components/shelf-assigner/shelf-assigner.component.ts @@ -1,7 +1,7 @@ import {Component, inject, OnInit} from '@angular/core'; -import {DialogService, DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog'; +import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog'; import {Book} from '../../model/book.model'; -import {MessageService, PrimeTemplate} from 'primeng/api'; +import {MessageService} from 'primeng/api'; import {ShelfService} from '../../service/shelf.service'; import {Observable} from 'rxjs'; import {BookService} from '../../service/book.service'; @@ -12,24 +12,19 @@ import {Button} from 'primeng/button'; import {AsyncPipe} from '@angular/common'; import {Checkbox} from 'primeng/checkbox'; import {FormsModule} from '@angular/forms'; -import {Dialog} from 'primeng/dialog'; -import {InputText} from 'primeng/inputtext'; -import {IconPickerService} from '../../../../shared/service/icon-picker.service'; +import {BookDialogHelperService} from '../book-browser/BookDialogHelperService'; @Component({ selector: 'app-shelf-assigner', standalone: true, templateUrl: './shelf-assigner.component.html', + styleUrl: './shelf-assigner.component.scss', imports: [ Button, Checkbox, AsyncPipe, - FormsModule, - Dialog, - InputText, - PrimeTemplate -], - styleUrls: ['./shelf-assigner.component.scss'] + FormsModule + ] }) export class ShelfAssignerComponent implements OnInit { @@ -38,16 +33,13 @@ export class ShelfAssignerComponent implements OnInit { private dynamicDialogRef = inject(DynamicDialogRef); private messageService = inject(MessageService); private bookService = inject(BookService); - private iconPickerService = inject(IconPickerService); + private bookDialogHelper = inject(BookDialogHelperService); shelfState$: Observable = this.shelfService.shelfState$; book: Book = this.dynamicDialogConfig.data.book; selectedShelves: Shelf[] = []; - displayShelfDialog: boolean = false; - shelfName: string = ''; bookIds: Set = this.dynamicDialogConfig.data.bookIds; isMultiBooks: boolean = this.dynamicDialogConfig.data.isMultiBooks; - selectedIcon: string | null = null; ngOnInit(): void { if (!this.isMultiBooks && this.book.shelves) { @@ -62,23 +54,6 @@ export class ShelfAssignerComponent implements OnInit { } } - saveNewShelf(): void { - const newShelf: Partial = { - name: this.shelfName, - icon: this.selectedIcon ? this.selectedIcon.replace('pi pi-', '') : 'heart' - }; - this.shelfService.createShelf(newShelf as Shelf).subscribe({ - next: () => { - this.messageService.add({severity: 'info', summary: 'Success', detail: `Shelf created: ${this.shelfName}`}); - this.displayShelfDialog = false; - }, - error: (e) => { - this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to create shelf'}); - console.error('Error creating shelf:', e); - } - }); - } - updateBooksShelves(): void { const idsToAssign = new Set(this.selectedShelves.map(shelf => shelf.id)); const idsToUnassign: Set = this.isMultiBooks ? new Set() : this.getIdsToUnAssign(this.book, idsToAssign); @@ -110,26 +85,20 @@ export class ShelfAssignerComponent implements OnInit { } createShelfDialog(): void { - this.displayShelfDialog = true; - } + const dialogRef = this.bookDialogHelper.openShelfCreator(); - closeShelfDialog(): void { - this.displayShelfDialog = false; + dialogRef.onClose.subscribe((created: boolean) => { + if (created) { + this.shelfService.reloadShelves(); + } + }); } closeDialog(): void { this.dynamicDialogRef.close(); } - openIconPicker() { - this.iconPickerService.open().subscribe(icon => { - if (icon) { - this.selectedIcon = icon; - } - }) - } - - clearSelectedIcon() { - this.selectedIcon = null; + isShelfSelected(shelf: Shelf): boolean { + return this.selectedShelves.some(s => s.id === shelf.id); } } diff --git a/booklore-ui/src/app/features/book/components/shelf-creator/shelf-creator.component.html b/booklore-ui/src/app/features/book/components/shelf-creator/shelf-creator.component.html new file mode 100644 index 000000000..7a58dc195 --- /dev/null +++ b/booklore-ui/src/app/features/book/components/shelf-creator/shelf-creator.component.html @@ -0,0 +1,105 @@ +
+
+
+ +
+
+

Create New Shelf

+

Add a custom shelf to organize your books

+
+
+ +
+
+ +
+ + @if (shelfName.trim()) { + + } +
+
+ +
+ +
+ + @if (!selectedIcon) { + + } @else { +
+
+ +
+
+ Selected Icon + {{ selectedIcon }} +
+ +
+ } +
+
+ + +
diff --git a/booklore-ui/src/app/features/book/components/shelf-creator/shelf-creator.component.scss b/booklore-ui/src/app/features/book/components/shelf-creator/shelf-creator.component.scss new file mode 100644 index 000000000..b27d57850 --- /dev/null +++ b/booklore-ui/src/app/features/book/components/shelf-creator/shelf-creator.component.scss @@ -0,0 +1,384 @@ +.shelf-creator { + display: flex; + flex-direction: column; + min-width: 600px; + padding-top: 20px; + + @media (max-width: 640px) { + min-width: auto; + width: 100%; + } +} + +.panel-header { + display: flex; + align-items: center; + gap: 1rem; + padding: 1.25rem; + background: linear-gradient(135deg, rgba(var(--primary-color-rgb), 0.1) 0%, rgba(var(--primary-color-rgb), 0.05) 100%); + border-radius: 10px 10px 0 0; + border: 1px solid var(--border-color); + + .header-icon-wrapper { + display: flex; + align-items: center; + justify-content: center; + width: 48px; + height: 48px; + background: var(--primary-color); + border-radius: 10px; + box-shadow: 0 3px 8px rgba(var(--primary-color-rgb), 0.3); + + .header-icon { + font-size: 1.5rem; + color: var(--primary-contrast-color); + } + } + + .header-text { + flex: 1; + + .panel-title { + margin: 0 0 0.25rem 0; + font-size: 1.25rem; + font-weight: 600; + color: var(--text-color); + } + + .panel-description { + margin: 0; + font-size: 0.875rem; + color: var(--text-secondary-color); + } + } + + @media (max-width: 480px) { + padding: 1rem; + + .header-icon-wrapper { + width: 40px; + height: 40px; + + .header-icon { + font-size: 1.25rem; + } + } + + .header-text { + .panel-title { + font-size: 1.125rem; + } + + .panel-description { + font-size: 0.8rem; + } + } + } +} + +.form-container { + display: flex; + flex-direction: column; + gap: 1.5rem; + padding: 1.5rem; + background: var(--card-background); + border: 1px solid var(--border-color); + border-top: none; + box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08); + + @media (max-width: 480px) { + padding: 1rem; + gap: 1rem; + } +} + +.form-group { + display: flex; + flex-direction: column; + gap: 0.5rem; + + &.highlight-group { + padding: 0.875rem; + } + + @media (max-width: 480px) { + gap: 0.375rem; + + &.highlight-group { + padding: 0.625rem; + } + } +} + +.form-label { + display: flex; + align-items: center; + gap: 0.375rem; + font-size: 0.95rem; + font-weight: 600; + color: var(--text-color); + + .label-icon { + color: var(--primary-color); + } + + .required-indicator { + color: var(--p-red-500); + margin-left: 0.125rem; + } + + @media (max-width: 480px) { + font-size: 0.875rem; + } +} + +.input-wrapper { + position: relative; + + .input-full { + width: 100%; + padding-right: 2.5rem; + box-sizing: border-box; + } + + .input-icon { + position: absolute; + right: 0.75rem; + top: 50%; + transform: translateY(-50%); + font-size: 1rem; + pointer-events: none; + + &.success { + color: var(--p-green-500); + } + } +} + +.icon-select-btn { + display: flex; + align-items: center; + justify-content: center; + gap: 0.75rem; + width: 100%; + padding: 1rem; + background: var(--ground-background); + border: 1px dashed var(--border-color); + border-radius: 8px; + color: var(--text-color); + font-size: 0.875rem; + font-weight: 500; + cursor: pointer; + transition: all 0.3s ease; + + &:hover { + background: var(--overlay-background); + border-color: var(--primary-color); + color: var(--primary-color); + transform: translateY(-1px); + box-shadow: 0 3px 8px rgba(var(--primary-color-rgb), 0.2); + } + + i { + font-size: 1.25rem; + } + + .btn-content { + display: flex; + flex-direction: column; + align-items: flex-start; + gap: 0.125rem; + + .btn-title { + font-size: 0.9375rem; + font-weight: 600; + } + + .btn-subtitle { + font-size: 0.8rem; + opacity: 0.85; + } + } + + @media (max-width: 480px) { + padding: 0.75rem; + gap: 0.5rem; + + i { + font-size: 1.125rem; + } + + .btn-content { + .btn-title { + font-size: 0.875rem; + } + + .btn-subtitle { + font-size: 0.75rem; + } + } + } +} + +.selected-icon-display { + display: flex; + align-items: center; + gap: 0.75rem; + padding: 0.875rem; + border: 1px solid var(--border-color); + border-radius: 8px; + background: var(--ground-background); + + .icon-preview { + display: flex; + align-items: center; + justify-content: center; + width: 42px; + height: 42px; + background: var(--primary-color); + border-radius: 8px; + box-shadow: 0 3px 8px rgba(var(--primary-color-rgb), 0.3); + + i { + font-size: 1.25rem; + color: var(--primary-contrast-color); + } + } + + .icon-info { + flex: 1; + display: flex; + flex-direction: column; + gap: 0.125rem; + + .icon-label { + font-size: 0.8rem; + color: var(--text-secondary-color); + } + + .icon-name { + font-size: 0.875rem; + font-weight: 500; + color: var(--text-color); + font-family: monospace; + } + } + + @media (max-width: 480px) { + padding: 0.625rem; + gap: 0.5rem; + + .icon-preview { + width: 36px; + height: 36px; + + i { + font-size: 1.125rem; + } + } + + .icon-info { + .icon-label { + font-size: 0.75rem; + } + + .icon-name { + font-size: 0.8rem; + } + } + } +} + +.divider { + height: 1px; + background: linear-gradient(90deg, transparent, var(--border-color), transparent); + margin: 0.25rem 0; +} + +.dialog-footer { + display: flex; + justify-content: space-between; + align-items: center; + gap: 1rem; + padding: 1.25rem 1.5rem; + background: var(--card-background); + border: 1px solid var(--border-color); + border-top: none; + border-radius: 0 0 10px 10px; + box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06); + + .validation-status { + flex: 1; + min-width: 0; + } + + .footer-actions { + display: flex; + gap: 0.75rem; + flex-shrink: 0; + } + + @media (max-width: 640px) { + flex-direction: column; + align-items: stretch; + padding: 1rem; + gap: 0.75rem; + + .validation-status { + width: 100%; + } + + .footer-actions { + width: 100%; + justify-content: flex-end; + gap: 0.5rem; + } + } +} + +.validation-message { + display: flex; + align-items: center; + gap: 0.375rem; + padding: 0.5rem 0.75rem; + font-weight: 500; + border-radius: 6px; + font-size: 0.875rem; + width: fit-content; + max-width: 100%; + + i { + font-size: 0.95rem; + } + + &.error { + background: rgba(239, 68, 68, 0.1); + color: rgb(239, 68, 68); + border: 1px solid rgba(239, 68, 68, 0.3); + + i { + color: rgb(239, 68, 68); + } + } + + &.success { + background: rgba(34, 197, 94, 0.1); + color: rgb(34, 197, 94); + border: 1px solid rgba(34, 197, 94, 0.3); + + i { + color: rgb(34, 197, 94); + } + } + + @media (max-width: 640px) { + font-size: 0.8rem; + padding: 0.375rem 0.5rem; + width: 100%; + + i { + font-size: 0.875rem; + } + } +} + diff --git a/booklore-ui/src/app/features/book/components/shelf-creator/shelf-creator.component.ts b/booklore-ui/src/app/features/book/components/shelf-creator/shelf-creator.component.ts new file mode 100644 index 000000000..299dc7731 --- /dev/null +++ b/booklore-ui/src/app/features/book/components/shelf-creator/shelf-creator.component.ts @@ -0,0 +1,65 @@ +import {Component, inject} from '@angular/core'; +import {DynamicDialogRef} from 'primeng/dynamicdialog'; +import {MessageService} from 'primeng/api'; +import {ShelfService} from '../../service/shelf.service'; +import {IconPickerService} from '../../../../shared/service/icon-picker.service'; +import {Shelf} from '../../model/shelf.model'; +import {FormsModule} from '@angular/forms'; +import {Button} from 'primeng/button'; +import {InputText} from 'primeng/inputtext'; +import {Tooltip} from 'primeng/tooltip'; + +@Component({ + selector: 'app-shelf-creator', + standalone: true, + templateUrl: './shelf-creator.component.html', + imports: [ + FormsModule, + Button, + InputText, + Tooltip + ], + styleUrl: './shelf-creator.component.scss', +}) +export class ShelfCreatorComponent { + private shelfService = inject(ShelfService); + private dynamicDialogRef = inject(DynamicDialogRef); + private messageService = inject(MessageService); + private iconPickerService = inject(IconPickerService); + + shelfName: string = ''; + selectedIcon: string | null = null; + + saveNewShelf(): void { + const newShelf: Partial = { + name: this.shelfName, + icon: this.selectedIcon ? this.selectedIcon.replace('pi pi-', '') : 'heart' + }; + this.shelfService.createShelf(newShelf as Shelf).subscribe({ + next: () => { + this.messageService.add({severity: 'info', summary: 'Success', detail: `Shelf created: ${this.shelfName}`}); + this.dynamicDialogRef.close(true); + }, + error: (e) => { + this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to create shelf'}); + console.error('Error creating shelf:', e); + } + }); + } + + openIconPicker(): void { + this.iconPickerService.open().subscribe(icon => { + if (icon) { + this.selectedIcon = icon; + } + }); + } + + clearSelectedIcon(): void { + this.selectedIcon = null; + } + + cancel(): void { + this.dynamicDialogRef.close(); + } +} diff --git a/booklore-ui/src/app/shared/layout/component/layout-menu/app.menu.component.ts b/booklore-ui/src/app/shared/layout/component/layout-menu/app.menu.component.ts index eaf9e0a89..0de400592 100644 --- a/booklore-ui/src/app/shared/layout/component/layout-menu/app.menu.component.ts +++ b/booklore-ui/src/app/shared/layout/component/layout-menu/app.menu.component.ts @@ -178,7 +178,7 @@ export class AppMenuComponent implements OnInit { type: 'shelf', label: 'Shelves', hasDropDown: true, - hasCreate: false, + hasCreate: true, items, }, ]; diff --git a/booklore-ui/src/app/shared/layout/component/layout-menu/app.menuitem.component.ts b/booklore-ui/src/app/shared/layout/component/layout-menu/app.menuitem.component.ts index 1b3ee6674..fdde05b6d 100644 --- a/booklore-ui/src/app/shared/layout/component/layout-menu/app.menuitem.component.ts +++ b/booklore-ui/src/app/shared/layout/component/layout-menu/app.menuitem.component.ts @@ -10,6 +10,8 @@ import {Button} from 'primeng/button'; import {Menu} from 'primeng/menu'; import {UserService} from '../../../../features/settings/user-management/user.service'; import {DialogLauncherService} from '../../../services/dialog-launcher.service'; +import {ShelfCreatorComponent} from '../../../../features/book/components/shelf-creator/shelf-creator.component'; +import {BookDialogHelperService} from '../../../../features/book/components/book-browser/BookDialogHelperService'; @Component({ selector: '[app-menuitem]', @@ -56,7 +58,8 @@ export class AppMenuitemComponent implements OnInit, OnDestroy { public router: Router, private menuService: MenuService, private userService: UserService, - private dialogLauncher: DialogLauncherService + private dialogLauncher: DialogLauncherService, + private bookDialogHelperService: BookDialogHelperService ) { this.userService.userState$.subscribe(userState => { if (userState?.user) { @@ -151,6 +154,9 @@ export class AppMenuitemComponent implements OnInit, OnDestroy { if (item.type === 'magicShelf') { this.dialogLauncher.openMagicShelfDialog(); } + if (item.type === 'shelf') { + this.bookDialogHelperService.openShelfCreator(); + } } triggerLink() {