diff --git a/booklore-ui/src/app/bookdrop/bookdrop-file-review-component/bookdrop-file-review.component.ts b/booklore-ui/src/app/bookdrop/bookdrop-file-review-component/bookdrop-file-review.component.ts index e91f8854b..076dfbcf2 100644 --- a/booklore-ui/src/app/bookdrop/bookdrop-file-review-component/bookdrop-file-review.component.ts +++ b/booklore-ui/src/app/bookdrop/bookdrop-file-review-component/bookdrop-file-review.component.ts @@ -75,7 +75,8 @@ export class BookdropFileReviewComponent implements OnInit { appSettings$: Observable = this.appSettingsService.appSettings$; uploadPattern = ''; - defaultLibraryId: string | null = null; + _defaultLibraryId: string | null = null; + defaultPathId: string | null = null; libraries: Library[] = []; bookdropFileUis: BookdropFileUI[] = []; @@ -108,6 +109,20 @@ export class BookdropFileReviewComponent implements OnInit { }); } + get defaultLibraryId() { + return this._defaultLibraryId; + } + + set defaultLibraryId(value: string | null) { + this._defaultLibraryId = value; + + const selected = this.libraries.find((lib) => lib?.id && String(lib.id) === value) + + if (selected && selected.paths.length ===1) { + this.defaultPathId = String(selected.paths[0].id) + } + } + get libraryOptions() { if (!this.libraries) return []; return this.libraries.map(lib => ({label: lib.name, value: String(lib.id ?? '')})); @@ -188,7 +203,7 @@ export class BookdropFileReviewComponent implements OnInit { onLibraryChange(file: BookdropFileUI): void { const lib = this.libraries.find(l => String(l.id) === file.selectedLibraryId); file.availablePaths = lib?.paths.map(p => ({id: String(p.id ?? ''), name: p.path})) ?? []; - file.selectedPathId = null; + file.selectedPathId = file.availablePaths.length === 1 ? file.availablePaths[0].id : null; } onMetadataCopied(fileId: number, copied: boolean): void { 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..ea7511ecd 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,7 +44,7 @@ interface UploadingFile { export class BookUploaderComponent implements OnInit { files: UploadingFile[] = []; isUploading: boolean = false; - selectedLibrary: Library | null = null; + _selectedLibrary: Library | null = null; selectedPath: LibraryPath | null = null; private readonly libraryService = inject(LibraryService); @@ -70,6 +70,26 @@ 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]; + }); + } + + 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]; + } } hasPendingFiles(): boolean {