This commit is contained in:
+13
-18
@@ -107,13 +107,14 @@ export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
|||||||
this.bookService.bookState$.pipe(
|
this.bookService.bookState$.pipe(
|
||||||
map(state => state.books?.find(b => b.id === bookId)),
|
map(state => state.books?.find(b => b.id === bookId)),
|
||||||
filter((book): book is Book => !!book && !!book.metadata),
|
filter((book): book is Book => !!book && !!book.metadata),
|
||||||
|
distinctUntilChanged((a, b) => a.id === b.id && a.metadata === b.metadata),
|
||||||
switchMap(book =>
|
switchMap(book =>
|
||||||
this.bookService.getBookByIdFromAPI(book.id, true)
|
this.bookService.getBookByIdFromAPI(book.id, true)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
takeUntil(this.destroy$),
|
takeUntil(this.destroy$),
|
||||||
shareReplay(1)
|
shareReplay({bufferSize: 1, refCount: true})
|
||||||
);
|
);
|
||||||
|
|
||||||
this.currentBookId$
|
this.currentBookId$
|
||||||
@@ -145,23 +146,17 @@ export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fetchBookRecommendationsIfNeeded(bookId: number): void {
|
private fetchBookRecommendationsIfNeeded(bookId: number): void {
|
||||||
this.appSettings$
|
this.appSettings$.pipe(
|
||||||
.pipe(
|
filter(settings => settings != null),
|
||||||
filter(settings => settings != null),
|
take(1),
|
||||||
take(1)
|
filter(settings => settings!.similarBookRecommendation ?? false),
|
||||||
)
|
switchMap(() => this.bookService.getBookRecommendations(bookId)),
|
||||||
.subscribe(settings => {
|
takeUntil(this.destroy$)
|
||||||
if (settings!.similarBookRecommendation ?? false) {
|
).subscribe(recommendations => {
|
||||||
this.bookService
|
this.recommendedBooks = recommendations.sort(
|
||||||
.getBookRecommendations(bookId)
|
(a, b) => (b.similarityScore ?? 0) - (a.similarityScore ?? 0)
|
||||||
.pipe(takeUntil(this.destroy$))
|
);
|
||||||
.subscribe(recommendations => {
|
});
|
||||||
this.recommendedBooks = recommendations.sort(
|
|
||||||
(a, b) => (b.similarityScore ?? 0) - (a.similarityScore ?? 0)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
|
|||||||
+85
-120
@@ -14,7 +14,7 @@ import {HttpResponse} from "@angular/common/http";
|
|||||||
import {BookService} from "../../../../book/service/book.service";
|
import {BookService} from "../../../../book/service/book.service";
|
||||||
import {ProgressSpinner} from "primeng/progressspinner";
|
import {ProgressSpinner} from "primeng/progressspinner";
|
||||||
import {Tooltip} from "primeng/tooltip";
|
import {Tooltip} from "primeng/tooltip";
|
||||||
import {filter, finalize, take, tap} from "rxjs/operators";
|
import {filter, finalize, switchMap, take, tap} from "rxjs/operators";
|
||||||
import {takeUntilDestroyed} from "@angular/core/rxjs-interop";
|
import {takeUntilDestroyed} from "@angular/core/rxjs-interop";
|
||||||
import {MetadataRefreshType} from "../../../model/request/metadata-refresh-type.enum";
|
import {MetadataRefreshType} from "../../../model/request/metadata-refresh-type.enum";
|
||||||
import {AutoComplete, AutoCompleteSelectEvent} from "primeng/autocomplete";
|
import {AutoComplete, AutoCompleteSelectEvent} from "primeng/autocomplete";
|
||||||
@@ -589,7 +589,7 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSave(): void {
|
onSave(): void {
|
||||||
this.saveMetadata().subscribe();
|
this.saveMetadata().pipe(takeUntilDestroyed(this.destroyRef)).subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
saveMetadata(): Observable<void> {
|
saveMetadata(): Observable<void> {
|
||||||
@@ -854,6 +854,7 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
const metadataUpdateWrapper = this.buildMetadataWrapper(shouldLockAllFields);
|
const metadataUpdateWrapper = this.buildMetadataWrapper(shouldLockAllFields);
|
||||||
this.bookService
|
this.bookService
|
||||||
.updateBookMetadata(this.currentBookId, metadataUpdateWrapper, false)
|
.updateBookMetadata(this.currentBookId, metadataUpdateWrapper, false)
|
||||||
|
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
if (shouldLockAllFields !== undefined) {
|
if (shouldLockAllFields !== undefined) {
|
||||||
@@ -913,24 +914,16 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
regenerateCover(bookId: number) {
|
regenerateCover(bookId: number) {
|
||||||
this.bookService.regenerateCover(bookId).subscribe({
|
this.bookService.regenerateCover(bookId).pipe(
|
||||||
next: () => {
|
switchMap(() => this.bookService.getBookByIdFromAPI(bookId, false)),
|
||||||
this.bookService.getBookByIdFromAPI(bookId, false).subscribe({
|
takeUntilDestroyed(this.destroyRef)
|
||||||
next: (updatedBook) => {
|
).subscribe({
|
||||||
this.bookService.handleBookUpdate(updatedBook);
|
next: (updatedBook) => {
|
||||||
this.messageService.add({
|
this.bookService.handleBookUpdate(updatedBook);
|
||||||
severity: "success",
|
this.messageService.add({
|
||||||
summary: this.t.translate('metadata.editor.toast.successSummary'),
|
severity: "success",
|
||||||
detail: this.t.translate('metadata.editor.toast.coverRegenerated'),
|
summary: this.t.translate('metadata.editor.toast.successSummary'),
|
||||||
});
|
detail: this.t.translate('metadata.editor.toast.coverRegenerated'),
|
||||||
},
|
|
||||||
error: () => {
|
|
||||||
this.messageService.add({
|
|
||||||
severity: "warning",
|
|
||||||
summary: this.t.translate('metadata.editor.toast.partialSuccessSummary'),
|
|
||||||
detail: this.t.translate('metadata.editor.toast.coverRegenPartialDetail'),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
error: (err) => {
|
error: (err) => {
|
||||||
@@ -945,57 +938,40 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
|
|
||||||
generateCustomCover(bookId: number) {
|
generateCustomCover(bookId: number) {
|
||||||
this.isGeneratingCover = true;
|
this.isGeneratingCover = true;
|
||||||
this.bookService.generateCustomCover(bookId)
|
this.bookService.generateCustomCover(bookId).pipe(
|
||||||
.pipe(finalize(() => this.isGeneratingCover = false))
|
switchMap(() => this.bookService.getBookByIdFromAPI(bookId, false)),
|
||||||
.subscribe({
|
finalize(() => this.isGeneratingCover = false),
|
||||||
next: () => {
|
takeUntilDestroyed(this.destroyRef)
|
||||||
this.bookService.getBookByIdFromAPI(bookId, false).subscribe({
|
).subscribe({
|
||||||
next: (updatedBook) => {
|
next: (updatedBook) => {
|
||||||
this.bookService.handleBookUpdate(updatedBook);
|
this.bookService.handleBookUpdate(updatedBook);
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: "success",
|
severity: "success",
|
||||||
summary: this.t.translate('metadata.editor.toast.successSummary'),
|
summary: this.t.translate('metadata.editor.toast.successSummary'),
|
||||||
detail: this.t.translate('metadata.editor.toast.customCoverGenerated'),
|
detail: this.t.translate('metadata.editor.toast.customCoverGenerated'),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
error: () => {
|
error: (err) => {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: "warning",
|
severity: "error",
|
||||||
summary: this.t.translate('metadata.editor.toast.partialSuccessSummary'),
|
summary: this.t.translate('metadata.editor.toast.errorSummary'),
|
||||||
detail: this.t.translate('metadata.editor.toast.customCoverPartialDetail'),
|
detail: this.t.translate('metadata.editor.toast.customCoverFailed'),
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
},
|
|
||||||
error: (err) => {
|
|
||||||
this.messageService.add({
|
|
||||||
severity: "error",
|
|
||||||
summary: this.t.translate('metadata.editor.toast.errorSummary'),
|
|
||||||
detail: this.t.translate('metadata.editor.toast.customCoverFailed'),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
regenerateAudiobookCover(bookId: number) {
|
regenerateAudiobookCover(bookId: number) {
|
||||||
this.bookService.regenerateAudiobookCover(bookId).subscribe({
|
this.bookService.regenerateAudiobookCover(bookId).pipe(
|
||||||
next: () => {
|
switchMap(() => this.bookService.getBookByIdFromAPI(bookId, false)),
|
||||||
this.bookService.getBookByIdFromAPI(bookId, false).subscribe({
|
takeUntilDestroyed(this.destroyRef)
|
||||||
next: (updatedBook) => {
|
).subscribe({
|
||||||
this.bookService.handleBookUpdate(updatedBook);
|
next: (updatedBook) => {
|
||||||
this.messageService.add({
|
this.bookService.handleBookUpdate(updatedBook);
|
||||||
severity: "success",
|
this.messageService.add({
|
||||||
summary: this.t.translate('metadata.editor.toast.successSummary'),
|
severity: "success",
|
||||||
detail: this.t.translate('metadata.editor.toast.audiobookCoverRegenerated'),
|
summary: this.t.translate('metadata.editor.toast.successSummary'),
|
||||||
});
|
detail: this.t.translate('metadata.editor.toast.audiobookCoverRegenerated'),
|
||||||
},
|
|
||||||
error: () => {
|
|
||||||
this.messageService.add({
|
|
||||||
severity: "warning",
|
|
||||||
summary: this.t.translate('metadata.editor.toast.partialSuccessSummary'),
|
|
||||||
detail: this.t.translate('metadata.editor.toast.audiobookCoverRegenPartialDetail'),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
error: (err) => {
|
error: (err) => {
|
||||||
@@ -1010,36 +986,27 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
|
|
||||||
generateCustomAudiobookCover(bookId: number) {
|
generateCustomAudiobookCover(bookId: number) {
|
||||||
this.isGeneratingAudiobookCover = true;
|
this.isGeneratingAudiobookCover = true;
|
||||||
this.bookService.generateCustomAudiobookCover(bookId)
|
this.bookService.generateCustomAudiobookCover(bookId).pipe(
|
||||||
.pipe(finalize(() => this.isGeneratingAudiobookCover = false))
|
switchMap(() => this.bookService.getBookByIdFromAPI(bookId, false)),
|
||||||
.subscribe({
|
finalize(() => this.isGeneratingAudiobookCover = false),
|
||||||
next: () => {
|
takeUntilDestroyed(this.destroyRef)
|
||||||
this.bookService.getBookByIdFromAPI(bookId, false).subscribe({
|
).subscribe({
|
||||||
next: (updatedBook) => {
|
next: (updatedBook) => {
|
||||||
this.bookService.handleBookUpdate(updatedBook);
|
this.bookService.handleBookUpdate(updatedBook);
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: "success",
|
severity: "success",
|
||||||
summary: this.t.translate('metadata.editor.toast.successSummary'),
|
summary: this.t.translate('metadata.editor.toast.successSummary'),
|
||||||
detail: this.t.translate('metadata.editor.toast.customAudiobookCoverGenerated'),
|
detail: this.t.translate('metadata.editor.toast.customAudiobookCoverGenerated'),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
error: () => {
|
error: (err) => {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: "warning",
|
severity: "error",
|
||||||
summary: this.t.translate('metadata.editor.toast.partialSuccessSummary'),
|
summary: this.t.translate('metadata.editor.toast.errorSummary'),
|
||||||
detail: this.t.translate('metadata.editor.toast.customAudiobookCoverPartialDetail'),
|
detail: this.t.translate('metadata.editor.toast.customAudiobookCoverFailed'),
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
},
|
|
||||||
error: (err) => {
|
|
||||||
this.messageService.add({
|
|
||||||
severity: "error",
|
|
||||||
summary: this.t.translate('metadata.editor.toast.errorSummary'),
|
|
||||||
detail: this.t.translate('metadata.editor.toast.customAudiobookCoverFailed'),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
autoFetch(bookId: number) {
|
autoFetch(bookId: number) {
|
||||||
@@ -1082,14 +1049,13 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
|
|
||||||
openCoverSearch() {
|
openCoverSearch() {
|
||||||
const ref = this.bookDialogHelperService.openCoverSearchDialog(this.currentBookId, 'ebook');
|
const ref = this.bookDialogHelperService.openCoverSearchDialog(this.currentBookId, 'ebook');
|
||||||
ref?.onClose.subscribe((result) => {
|
ref?.onClose.pipe(
|
||||||
if (result) {
|
take(1),
|
||||||
this.bookService.getBookByIdFromAPI(this.currentBookId, false).subscribe({
|
filter(result => !!result),
|
||||||
next: (updatedBook) => {
|
switchMap(() => this.bookService.getBookByIdFromAPI(this.currentBookId, false)),
|
||||||
this.bookService.handleBookUpdate(updatedBook);
|
takeUntilDestroyed(this.destroyRef)
|
||||||
},
|
).subscribe(updatedBook => {
|
||||||
});
|
this.bookService.handleBookUpdate(updatedBook);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1105,7 +1071,7 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
const prevBookId = this.bookNavigationService.getPreviousBookId();
|
const prevBookId = this.bookNavigationService.getPreviousBookId();
|
||||||
if (prevBookId) {
|
if (prevBookId) {
|
||||||
if (this.autoSaveEnabled && this.metadataForm.dirty) {
|
if (this.autoSaveEnabled && this.metadataForm.dirty) {
|
||||||
this.saveMetadata().subscribe(() => this.navigateToBook(prevBookId));
|
this.saveMetadata().pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => this.navigateToBook(prevBookId));
|
||||||
} else {
|
} else {
|
||||||
this.navigateToBook(prevBookId);
|
this.navigateToBook(prevBookId);
|
||||||
}
|
}
|
||||||
@@ -1116,7 +1082,7 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
const nextBookId = this.bookNavigationService.getNextBookId();
|
const nextBookId = this.bookNavigationService.getNextBookId();
|
||||||
if (nextBookId) {
|
if (nextBookId) {
|
||||||
if (this.autoSaveEnabled && this.metadataForm.dirty) {
|
if (this.autoSaveEnabled && this.metadataForm.dirty) {
|
||||||
this.saveMetadata().subscribe(() => this.navigateToBook(nextBookId));
|
this.saveMetadata().pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => this.navigateToBook(nextBookId));
|
||||||
} else {
|
} else {
|
||||||
this.navigateToBook(nextBookId);
|
this.navigateToBook(nextBookId);
|
||||||
}
|
}
|
||||||
@@ -1181,14 +1147,13 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
|
|
||||||
openAudiobookCoverSearch() {
|
openAudiobookCoverSearch() {
|
||||||
const ref = this.bookDialogHelperService.openCoverSearchDialog(this.currentBookId, 'audiobook');
|
const ref = this.bookDialogHelperService.openCoverSearchDialog(this.currentBookId, 'audiobook');
|
||||||
ref?.onClose.subscribe((result) => {
|
ref?.onClose.pipe(
|
||||||
if (result) {
|
take(1),
|
||||||
this.bookService.getBookByIdFromAPI(this.currentBookId, false).subscribe({
|
filter(result => !!result),
|
||||||
next: (updatedBook) => {
|
switchMap(() => this.bookService.getBookByIdFromAPI(this.currentBookId, false)),
|
||||||
this.bookService.handleBookUpdate(updatedBook);
|
takeUntilDestroyed(this.destroyRef)
|
||||||
},
|
).subscribe(updatedBook => {
|
||||||
});
|
this.bookService.handleBookUpdate(updatedBook);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1197,10 +1162,10 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
event.originalEvent as HttpResponse<unknown>;
|
event.originalEvent as HttpResponse<unknown>;
|
||||||
if (response && response.status === 200) {
|
if (response && response.status === 200) {
|
||||||
this.isUploading = false;
|
this.isUploading = false;
|
||||||
this.bookService.getBookByIdFromAPI(this.currentBookId, false).subscribe({
|
this.bookService.getBookByIdFromAPI(this.currentBookId, false).pipe(
|
||||||
next: (updatedBook) => {
|
takeUntilDestroyed(this.destroyRef)
|
||||||
this.bookService.handleBookUpdate(updatedBook);
|
).subscribe(updatedBook => {
|
||||||
},
|
this.bookService.handleBookUpdate(updatedBook);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.isUploading = false;
|
this.isUploading = false;
|
||||||
|
|||||||
+2
-2
@@ -76,8 +76,8 @@ export class MultiBookMetadataEditorComponent implements OnInit, OnDestroy {
|
|||||||
switchMap(book =>
|
switchMap(book =>
|
||||||
this.bookService.getBookByIdFromAPI(book.id, true)
|
this.bookService.getBookByIdFromAPI(book.id, true)
|
||||||
),
|
),
|
||||||
shareReplay(1),
|
takeUntil(this.destroy$),
|
||||||
takeUntil(this.destroy$)
|
shareReplay({bufferSize: 1, refCount: true})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user