diff --git a/booklore-ui/src/app/features/bookdrop/component/bookdrop-file-review/bookdrop-file-review.component.ts b/booklore-ui/src/app/features/bookdrop/component/bookdrop-file-review/bookdrop-file-review.component.ts index 965435c4..8f482c23 100644 --- a/booklore-ui/src/app/features/bookdrop/component/bookdrop-file-review/bookdrop-file-review.component.ts +++ b/booklore-ui/src/app/features/bookdrop/component/bookdrop-file-review/bookdrop-file-review.component.ts @@ -211,6 +211,45 @@ export class BookdropFileReviewComponent implements OnInit { }); } + private async loadAllPagesIntoCache(): Promise { + const totalPages = Math.ceil(this.totalRecords / this.pageSize); + const pagePromises: Promise[] = []; + + for (let page = 0; page < totalPages; page++) { + const promise = new Promise((resolve, reject) => { + this.bookdropService.getPendingFiles(page, this.pageSize) + .pipe(takeUntilDestroyed(this.destroyRef)) + .subscribe({ + next: response => { + response.content.forEach(file => { + if (!this.fileUiCache[file.id]) { + const fresh = this.createFileUI(file); + + if (this.defaultLibraryId) { + const selectedLib = this.libraries.find(l => String(l.id) === this.defaultLibraryId); + const selectedPaths = selectedLib?.paths ?? []; + fresh.selectedLibraryId = this.defaultLibraryId; + fresh.availablePaths = selectedPaths.map(p => ({id: String(p.id ?? ''), name: p.path})); + fresh.selectedPathId = this.defaultPathId ?? null; + } + + this.fileUiCache[file.id] = fresh; + } + }); + resolve(); + }, + error: err => { + console.error('Error loading page:', err); + reject(err); + } + }); + }); + pagePromises.push(promise); + } + + await Promise.all(pagePromises); + } + 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})) ?? []; @@ -652,7 +691,21 @@ export class BookdropFileReviewComponent implements OnInit { }); } - private applyBulkMetadataViaBackend(result: BulkEditResult): void { + private async applyBulkMetadataViaBackend(result: BulkEditResult): Promise { + if (this.selectAllAcrossPages) { + try { + await this.loadAllPagesIntoCache(); + } catch (err) { + console.error('Error loading pages into cache:', err); + this.messageService.add({ + severity: 'error', + summary: 'Bulk Edit Failed', + detail: 'An error occurred while loading files into cache.', + }); + return; + } + } + const selectedFiles = this.getSelectedFiles(); const selectedIds = selectedFiles.map(f => f.file.id); @@ -716,7 +769,21 @@ export class BookdropFileReviewComponent implements OnInit { }); } - private applyExtractedMetadata(results: FileExtractionResult[]): void { + private async applyExtractedMetadata(results: FileExtractionResult[]): Promise { + if (this.selectAllAcrossPages) { + try { + await this.loadAllPagesIntoCache(); + } catch (err) { + console.error('Error loading pages into cache:', err); + this.messageService.add({ + severity: 'error', + summary: 'Pattern Extraction Failed', + detail: 'An error occurred while loading files into cache.', + }); + return; + } + } + let appliedCount = 0; results.forEach(result => {