Merge pull request #892 from iamntz/feat/auto-set-paths
Feat: automatically set library/path if there is only one option available
This commit is contained in:
+17
-2
@@ -75,7 +75,8 @@ export class BookdropFileReviewComponent implements OnInit {
|
||||
appSettings$: Observable<AppSettings | null> = 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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user