From 9e1d437e74c954c184e6cef6d2670bfaf5428f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20Staicu?= Date: Tue, 12 Aug 2025 17:41:27 +0300 Subject: [PATCH] automatically set library/path if there is only one option available --- .../book-uploader/book-uploader.component.ts | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/booklore-ui/src/app/utilities/component/book-uploader/book-uploader.component.ts b/booklore-ui/src/app/utilities/component/book-uploader/book-uploader.component.ts index ab9433880..39682be81 100644 --- a/booklore-ui/src/app/utilities/component/book-uploader/book-uploader.component.ts +++ b/booklore-ui/src/app/utilities/component/book-uploader/book-uploader.component.ts @@ -44,9 +44,21 @@ interface UploadingFile { export class BookUploaderComponent implements OnInit { files: UploadingFile[] = []; isUploading: boolean = false; - selectedLibrary: Library | null = null; + _selectedLibrary: Library | null = null; selectedPath: LibraryPath | null = null; + get selectedLibrary(): Library | null { + return this._selectedLibrary; + } + + set selectedLibrary(library: Library | null) { + this._selectedLibrary = library; + + if(library?.paths?.length === 1) { + this.selectedPath = library.paths[0]; + } + } + private readonly libraryService = inject(LibraryService); private readonly messageService = inject(MessageService); private readonly appSettingsService = inject(AppSettingsService); @@ -70,6 +82,15 @@ export class BookUploaderComponent implements OnInit { .subscribe(settings => { this.maxFileSizeBytes = (settings?.maxFileUploadSizeInMb ?? 100) * 1024 * 1024; }); + + this.libraryState$.subscribe(state => { + if (state?.libraries?.length !== 1 || this.selectedLibrary) { + return; + } + + this.selectedLibrary = state.libraries[0]; + }); + } hasPendingFiles(): boolean {