From d9d7a18d893d9a81d2854806500409b2621d7d7d Mon Sep 17 00:00:00 2001
From: brios <127139797+balazs-szucs@users.noreply.github.com>
Date: Mon, 20 Apr 2026 02:20:16 +0200
Subject: [PATCH] fix(file-mover): fix file mover never updating (#651)
---
.../file-mover/file-mover-component.html | 10 +--
.../file-mover/file-mover-component.ts | 73 +++++++++++--------
2 files changed, 48 insertions(+), 35 deletions(-)
diff --git a/frontend/src/app/shared/components/file-mover/file-mover-component.html b/frontend/src/app/shared/components/file-mover/file-mover-component.html
index 46713a057..78a36e62c 100644
--- a/frontend/src/app/shared/components/file-mover/file-mover-component.html
+++ b/frontend/src/app/shared/components/file-mover/file-mover-component.html
@@ -26,7 +26,7 @@
- Preview and organize {{ filePreviews.length }} file{{ filePreviews.length !== 1 ? 's' : '' }}.
+ Preview and organize {{ filePreviews().length }} file{{ filePreviews().length !== 1 ? 's' : '' }}.
Files will be renamed based on metadata and naming patterns.
@@ -132,7 +132,7 @@
} @else {
();
books: Book[] = [];
- filePreviews: FilePreview[] = [];
+ filePreviews = signal([]);
defaultTargetLibraryId: number | null = null;
defaultTargetLibraryPathId: number | null = null;
defaultAvailableLibraryPaths: LibraryPath[] = [];
@@ -134,7 +134,7 @@ export class FileMoverComponent implements OnDestroy {
}
applyPattern(): void {
- this.filePreviews = this.books.map(book => {
+ const previews = this.books.map(book => {
const fileName = book.fileName ?? '';
const fileSubPath = book.fileSubPath ? `${book.fileSubPath.replace(/\/+$/g, '')}/` : '';
@@ -169,39 +169,46 @@ export class FileMoverComponent implements OnDestroy {
this.updatePreviewPaths(preview, book);
return preview;
});
+ this.filePreviews.set(previews);
}
onDefaultLibraryChange(): void {
this.defaultAvailableLibraryPaths = this.getLibraryPathsById(this.defaultTargetLibraryId);
this.defaultTargetLibraryPathId = this.defaultAvailableLibraryPaths.length > 0 ? this.defaultAvailableLibraryPaths[0].id ?? null : null;
- this.filePreviews.forEach(preview => {
- if (!preview.isMoved) {
- preview.targetLibraryId = this.defaultTargetLibraryId;
- preview.targetLibraryName = this.getLibraryNameById(this.defaultTargetLibraryId);
- preview.availableLibraryPaths = this.defaultAvailableLibraryPaths;
- preview.targetLibraryPathId = this.defaultTargetLibraryPathId;
- preview.targetLibraryPath = this.defaultAvailableLibraryPaths.find(p => p.id === this.defaultTargetLibraryPathId)?.path || '';
+ this.filePreviews.update(previews => {
+ previews.forEach(preview => {
+ if (!preview.isMoved) {
+ preview.targetLibraryId = this.defaultTargetLibraryId;
+ preview.targetLibraryName = this.getLibraryNameById(this.defaultTargetLibraryId);
+ preview.availableLibraryPaths = this.defaultAvailableLibraryPaths;
+ preview.targetLibraryPathId = this.defaultTargetLibraryPathId;
+ preview.targetLibraryPath = this.defaultAvailableLibraryPaths.find(p => p.id === this.defaultTargetLibraryPathId)?.path || '';
- const book = this.books.find(b => b.id === preview.bookId);
- if (book) {
- this.updatePreviewPaths(preview, book);
+ const book = this.books.find(b => b.id === preview.bookId);
+ if (book) {
+ this.updatePreviewPaths(preview, book);
+ }
}
- }
+ });
+ return [...previews];
});
}
onDefaultLibraryPathChange(): void {
- this.filePreviews.forEach(preview => {
- if (!preview.isMoved && preview.targetLibraryId === this.defaultTargetLibraryId) {
- preview.targetLibraryPathId = this.defaultTargetLibraryPathId;
- preview.targetLibraryPath = this.defaultAvailableLibraryPaths.find(p => p.id === this.defaultTargetLibraryPathId)?.path || '';
+ this.filePreviews.update(previews => {
+ previews.forEach(preview => {
+ if (!preview.isMoved && preview.targetLibraryId === this.defaultTargetLibraryId) {
+ preview.targetLibraryPathId = this.defaultTargetLibraryPathId;
+ preview.targetLibraryPath = this.defaultAvailableLibraryPaths.find(p => p.id === this.defaultTargetLibraryPathId)?.path || '';
- const book = this.books.find(b => b.id === preview.bookId);
- if (book) {
- this.updatePreviewPaths(preview, book);
+ const book = this.books.find(b => b.id === preview.bookId);
+ if (book) {
+ this.updatePreviewPaths(preview, book);
+ }
}
- }
+ });
+ return [...previews];
});
}
@@ -215,6 +222,7 @@ export class FileMoverComponent implements OnDestroy {
if (book) {
this.updatePreviewPaths(preview, book);
}
+ this.filePreviews.update(previews => [...previews]);
}
onLibraryPathChange(preview: FilePreview): void {
@@ -225,6 +233,7 @@ export class FileMoverComponent implements OnDestroy {
if (book) {
this.updatePreviewPaths(preview, book);
}
+ this.filePreviews.update(previews => [...previews]);
}
private updatePreviewPaths(preview: FilePreview, book: Book): void {
@@ -300,7 +309,7 @@ export class FileMoverComponent implements OnDestroy {
}
get movedFileCount(): number {
- return this.filePreviews.filter(p => p.isMoved).length;
+ return this.filePreviews().filter(p => p.isMoved).length;
}
sanitize(input: string | undefined): string {
@@ -341,11 +350,11 @@ export class FileMoverComponent implements OnDestroy {
}
saveChanges(): void {
- this.loading = true;
+ this.loading.set(true);
const request: FileMoveRequest = {
bookIds: [...this.bookIds],
- moves: this.filePreviews.map(preview => ({
+ moves: this.filePreviews().map(preview => ({
bookId: preview.bookId,
targetLibraryId: preview.targetLibraryId,
targetLibraryPathId: preview.targetLibraryPathId
@@ -356,17 +365,21 @@ export class FileMoverComponent implements OnDestroy {
takeUntil(this.destroy$)
).subscribe({
next: () => {
- this.loading = false;
- this.filePreviews.forEach(p => (p.isMoved = true));
+ this.loading.set(false);
+ this.filePreviews.update(previews => {
+ previews.forEach(p => (p.isMoved = true));
+ return [...previews];
+ });
+ const currentPreviews = this.filePreviews();
this.messageService.add({
severity: 'success',
summary: 'Files Organized!',
- detail: `Successfully organized ${this.filePreviews.length} file${this.filePreviews.length === 1 ? '' : 's'}.`,
+ detail: `Successfully organized ${currentPreviews.length} file${currentPreviews.length === 1 ? '' : 's'}.`,
life: 3000
});
},
error: () => {
- this.loading = false;
+ this.loading.set(false);
this.messageService.add({
severity: 'error',
summary: 'Oops! Something went wrong',