fix(loading): update loading checks to use signal() for reactive state management (#727)
This commit is contained in:
+2
-2
@@ -1,5 +1,5 @@
|
||||
<div class="reading-sessions-container" *transloco="let t; prefix: 'metadata.readingSessions'">
|
||||
@if (loading && sessions.length === 0) {
|
||||
@if (loading() && sessions.length === 0) {
|
||||
<div class="loading-state">
|
||||
<p-progressSpinner strokeWidth="4" fill="transparent" animationDuration=".8s"></p-progressSpinner>
|
||||
<p class="loading-text">{{ t('loading') }}</p>
|
||||
@@ -14,7 +14,7 @@
|
||||
[value]="sessions"
|
||||
[paginator]="true"
|
||||
[rows]="rows"
|
||||
[loading]="loading"
|
||||
[loading]="loading()"
|
||||
[showCurrentPageReport]="true"
|
||||
currentPageReportTemplate="Showing {first} to {last} of {totalRecords} sessions"
|
||||
class="p-datatable-sm">
|
||||
|
||||
+3
-3
@@ -59,7 +59,7 @@ describe('BookReadingSessionsComponent', () => {
|
||||
|
||||
expect(getSessionsByBookId).toHaveBeenCalledWith(7, 0, 100);
|
||||
expect(component.sessions).toEqual([session]);
|
||||
expect(component.loading).toBe(false);
|
||||
expect(component.loading()).toBe(false);
|
||||
expect(component.pageReportTemplate).toBe('translated:metadata.readingSessions.pageReport');
|
||||
});
|
||||
|
||||
@@ -75,7 +75,7 @@ describe('BookReadingSessionsComponent', () => {
|
||||
component.bookId = 7;
|
||||
|
||||
component.loadSessions();
|
||||
expect(component.loading).toBe(false);
|
||||
expect(component.loading()).toBe(false);
|
||||
expect(component.sessions).toEqual([]);
|
||||
|
||||
component.bookId = 9;
|
||||
@@ -85,7 +85,7 @@ describe('BookReadingSessionsComponent', () => {
|
||||
|
||||
expect(getSessionsByBookId).toHaveBeenNthCalledWith(2, 9, 0, 100);
|
||||
expect(component.sessions).toEqual([createSession({id: 2, bookId: 9})]);
|
||||
expect(component.loading).toBe(false);
|
||||
expect(component.loading()).toBe(false);
|
||||
});
|
||||
|
||||
it('ignores the initial ngOnChanges first-change event', () => {
|
||||
|
||||
+17
-5
@@ -1,5 +1,8 @@
|
||||
import {Component, inject, Input, OnInit, OnChanges, SimpleChanges} from '@angular/core';
|
||||
import {Component, DestroyRef, inject, Input, OnInit, OnChanges, signal, SimpleChanges} from '@angular/core';
|
||||
import {ReadingSessionApiService, ReadingSessionResponse} from '../../../../../shared/service/reading-session-api.service';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {finalize, Subject, takeUntil} from 'rxjs';
|
||||
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
@@ -16,11 +19,14 @@ export class BookReadingSessionsComponent implements OnInit, OnChanges {
|
||||
@Input() bookId!: number;
|
||||
|
||||
private readonly readingSessionService = inject(ReadingSessionApiService);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
private readonly cancelLoad$ = new Subject<void>();
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
|
||||
sessions: ReadingSessionResponse[] = [];
|
||||
rows = 5;
|
||||
loading = false;
|
||||
loading = signal(false);
|
||||
|
||||
get pageReportTemplate(): string {
|
||||
return this.t.translate('metadata.readingSessions.pageReport');
|
||||
@@ -37,19 +43,25 @@ export class BookReadingSessionsComponent implements OnInit, OnChanges {
|
||||
}
|
||||
|
||||
loadSessions() {
|
||||
this.loading = true;
|
||||
this.cancelLoad$.next();
|
||||
this.loading.set(true);
|
||||
this.readingSessionService.getSessionsByBookId(this.bookId, 0, 100)
|
||||
.pipe(
|
||||
takeUntil(this.cancelLoad$),
|
||||
takeUntilDestroyed(this.destroyRef),
|
||||
finalize(() => this.loading.set(false))
|
||||
)
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
this.sessions = response.content;
|
||||
this.loading = false;
|
||||
},
|
||||
error: () => {
|
||||
this.loading = false;
|
||||
this.sessions = [];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
formatDuration(seconds: number): string {
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
|
||||
+6
-6
@@ -3,7 +3,7 @@
|
||||
<app-metadata-picker
|
||||
[fetchedMetadata]="selectedFetchedMetadata"
|
||||
[book]="book"
|
||||
[detailLoading]="detailLoading"
|
||||
[detailLoading]="detailLoading()"
|
||||
(goBack)="onGoBack()">
|
||||
</app-metadata-picker>
|
||||
</div>
|
||||
@@ -76,7 +76,7 @@
|
||||
<p-button
|
||||
[label]="t('searchBtn')"
|
||||
type="submit"
|
||||
[disabled]="!isSearchEnabled || loading"
|
||||
[disabled]="!isSearchEnabled || loading()"
|
||||
icon="pi pi-search"
|
||||
class="'custom-search-button'">
|
||||
</p-button>
|
||||
@@ -84,7 +84,7 @@
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@if (loading || searchTriggered) {
|
||||
@if (loading() || searchTriggered()) {
|
||||
<div class="provider-status">
|
||||
<div class="status-header">
|
||||
<div class="results-info">
|
||||
@@ -94,7 +94,7 @@
|
||||
</h3>
|
||||
<span class="results-count">{{ t('booksFound', { count: filteredMetadata().length }) }}</span>
|
||||
</div>
|
||||
@if (loading) {
|
||||
@if (loading()) {
|
||||
<span class="fetching-badge">
|
||||
<i class="pi pi-spin pi-spinner"></i>
|
||||
{{ t('fetching') }}
|
||||
@@ -129,7 +129,7 @@
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!searchTriggered && allFetchedMetadata().length === 0) {
|
||||
@if (!searchTriggered() && allFetchedMetadata().length === 0) {
|
||||
<div class="empty-state">
|
||||
<div class="empty-icon">
|
||||
<i class="pi pi-search"></i>
|
||||
@@ -139,7 +139,7 @@
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (searchTriggered && allFetchedMetadata().length === 0 && !loading) {
|
||||
@if (searchTriggered() && allFetchedMetadata().length === 0 && !loading()) {
|
||||
<div class="empty-state">
|
||||
<div class="empty-icon no-results">
|
||||
<i class="pi pi-inbox"></i>
|
||||
|
||||
+13
-13
@@ -36,8 +36,8 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
||||
providers: string[] = [];
|
||||
|
||||
bookId!: number;
|
||||
loading: boolean = false;
|
||||
searchTriggered = false;
|
||||
loading = signal(false);
|
||||
searchTriggered = signal(false);
|
||||
|
||||
private currentBook: Book | null = null;
|
||||
private currentSettings: AppSettings | null = null;
|
||||
@@ -55,7 +55,7 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
||||
@Input() isActiveTab: boolean = false;
|
||||
|
||||
readonly selectedFetchedMetadata = signal<BookMetadata | null>(null);
|
||||
detailLoading = false;
|
||||
detailLoading = signal(false);
|
||||
|
||||
private formBuilder = inject(FormBuilder);
|
||||
private bookMetadataService = inject(BookMetadataService);
|
||||
@@ -190,8 +190,8 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
||||
|
||||
private resetFormFromBook(book: Book): void {
|
||||
this.cancelRequest$.next();
|
||||
this.loading = false;
|
||||
this.detailLoading = false;
|
||||
this.loading.set(false);
|
||||
this.detailLoading.set(false);
|
||||
this.selectedFetchedMetadata.set(null);
|
||||
this.allFetchedMetadata.set([]);
|
||||
|
||||
@@ -239,7 +239,7 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
||||
}
|
||||
|
||||
onSubmit(): void {
|
||||
this.searchTriggered = true;
|
||||
this.searchTriggered.set(true);
|
||||
if (this.form.valid) {
|
||||
const providerKeys = this.form.get('provider')?.value;
|
||||
if (!providerKeys) return;
|
||||
@@ -252,7 +252,7 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
||||
isbn: this.form.get('isbn')?.value
|
||||
};
|
||||
|
||||
this.loading = true;
|
||||
this.loading.set(true);
|
||||
this.allFetchedMetadata.set([]);
|
||||
|
||||
const initialCounts = new Map<string, number>();
|
||||
@@ -304,11 +304,11 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error fetching metadata:', error);
|
||||
this.loading = false;
|
||||
this.loading.set(false);
|
||||
this.providerLoading.set(new Map());
|
||||
},
|
||||
complete: () => {
|
||||
this.loading = false;
|
||||
this.loading.set(false);
|
||||
activeProviders.forEach((provider: string) => {
|
||||
if (!this.providerCompletionStatus().get(provider)) {
|
||||
this.providerLoading.update(map => new Map(map).set(provider, false));
|
||||
@@ -391,7 +391,7 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
||||
const enrichment = this.getDetailEnrichmentInfo(fetchedMetadata);
|
||||
|
||||
if (enrichment) {
|
||||
this.detailLoading = true;
|
||||
this.detailLoading.set(true);
|
||||
this.bookMetadataService.fetchMetadataDetail(enrichment.provider, enrichment.id)
|
||||
.pipe(takeUntil(this.cancelRequest$))
|
||||
.subscribe({
|
||||
@@ -401,11 +401,11 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
||||
if (currentId === enrichment.id) {
|
||||
this.selectedFetchedMetadata.set(enriched);
|
||||
}
|
||||
this.detailLoading = false;
|
||||
this.detailLoading.set(false);
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Error fetching detailed metadata:', err);
|
||||
this.detailLoading = false;
|
||||
this.detailLoading.set(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -445,7 +445,7 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
||||
}
|
||||
|
||||
onGoBack() {
|
||||
this.detailLoading = false;
|
||||
this.detailLoading.set(false);
|
||||
this.selectedFetchedMetadata.set(null);
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -16,7 +16,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (loading) {
|
||||
@if (loading()) {
|
||||
<div class="loading-state">
|
||||
<i class="pi pi-spin pi-spinner"></i>
|
||||
<span>{{ t('loading') }}</span>
|
||||
@@ -26,7 +26,7 @@
|
||||
<p-button
|
||||
[label]="t('exportBtn')"
|
||||
icon="pi pi-upload"
|
||||
[loading]="exporting"
|
||||
[loading]="exporting()"
|
||||
(onClick)="exportToSidecar()"
|
||||
severity="primary"
|
||||
size="small"
|
||||
@@ -36,7 +36,7 @@
|
||||
<p-button
|
||||
[label]="t('importBtn')"
|
||||
icon="pi pi-download"
|
||||
[loading]="importing"
|
||||
[loading]="importing()"
|
||||
[disabled]="syncStatus === 'MISSING'"
|
||||
(onClick)="importFromSidecar()"
|
||||
severity="secondary"
|
||||
|
||||
+11
-11
@@ -65,7 +65,7 @@ describe('SidecarViewerComponent', () => {
|
||||
component.currentBookId = 7;
|
||||
component.sidecarContent = createMetadata();
|
||||
component.syncStatus = 'IN_SYNC';
|
||||
component.loading = true;
|
||||
component.loading.set(true);
|
||||
component.error = 'failed';
|
||||
|
||||
component.book = null;
|
||||
@@ -73,7 +73,7 @@ describe('SidecarViewerComponent', () => {
|
||||
expect(component.currentBookId).toBeNull();
|
||||
expect(component.sidecarContent).toBeNull();
|
||||
expect(component.syncStatus).toBe('NOT_APPLICABLE');
|
||||
expect(component.loading).toBe(false);
|
||||
expect(component.loading()).toBe(false);
|
||||
expect(component.error).toBeNull();
|
||||
});
|
||||
|
||||
@@ -90,7 +90,7 @@ describe('SidecarViewerComponent', () => {
|
||||
expect(component.currentBookId).toBe(7);
|
||||
expect(component.syncStatus).toBe('IN_SYNC');
|
||||
expect(component.sidecarContent).toEqual(metadata);
|
||||
expect(component.loading).toBe(false);
|
||||
expect(component.loading()).toBe(false);
|
||||
});
|
||||
|
||||
it('skips content loading when the sidecar is missing or not applicable', () => {
|
||||
@@ -102,14 +102,14 @@ describe('SidecarViewerComponent', () => {
|
||||
expect(getSidecarContent).not.toHaveBeenCalled();
|
||||
expect(component.syncStatus).toBe('MISSING');
|
||||
expect(component.sidecarContent).toBeNull();
|
||||
expect(component.loading).toBe(false);
|
||||
expect(component.loading()).toBe(false);
|
||||
|
||||
getSyncStatus.mockReturnValue(of({status: 'NOT_APPLICABLE'}));
|
||||
component.book = createBook(4);
|
||||
|
||||
expect(getSidecarContent).not.toHaveBeenCalled();
|
||||
expect(component.syncStatus).toBe('NOT_APPLICABLE');
|
||||
expect(component.loading).toBe(false);
|
||||
expect(component.loading()).toBe(false);
|
||||
});
|
||||
|
||||
it('falls back to NOT_APPLICABLE when sync status lookup fails', () => {
|
||||
@@ -121,7 +121,7 @@ describe('SidecarViewerComponent', () => {
|
||||
|
||||
expect(component.syncStatus).toBe('NOT_APPLICABLE');
|
||||
expect(component.sidecarContent).toBeNull();
|
||||
expect(component.loading).toBe(false);
|
||||
expect(component.loading()).toBe(false);
|
||||
expect(consoleError).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
@@ -134,7 +134,7 @@ describe('SidecarViewerComponent', () => {
|
||||
component.book = createBook(6);
|
||||
|
||||
expect(component.sidecarContent).toBeNull();
|
||||
expect(component.loading).toBe(false);
|
||||
expect(component.loading()).toBe(false);
|
||||
expect(consoleError).not.toHaveBeenCalled();
|
||||
|
||||
getSidecarContent.mockReturnValue(throwError(() => ({status: 500})));
|
||||
@@ -159,7 +159,7 @@ describe('SidecarViewerComponent', () => {
|
||||
detail: 'translated:metadata.sidecar.toast.exportSuccessDetail',
|
||||
});
|
||||
expect(reload).toHaveBeenCalledWith(9);
|
||||
expect(component.exporting).toBe(false);
|
||||
expect(component.exporting()).toBe(false);
|
||||
});
|
||||
|
||||
it('shows an error toast when export fails and ignores export without a selected book', () => {
|
||||
@@ -179,7 +179,7 @@ describe('SidecarViewerComponent', () => {
|
||||
summary: 'translated:metadata.sidecar.toast.exportFailedSummary',
|
||||
detail: 'translated:metadata.sidecar.toast.exportFailedDetail',
|
||||
});
|
||||
expect(component.exporting).toBe(false);
|
||||
expect(component.exporting()).toBe(false);
|
||||
expect(consoleError).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
@@ -199,7 +199,7 @@ describe('SidecarViewerComponent', () => {
|
||||
detail: 'translated:metadata.sidecar.toast.importSuccessDetail',
|
||||
});
|
||||
expect(reload).toHaveBeenCalledWith(12);
|
||||
expect(component.importing).toBe(false);
|
||||
expect(component.importing()).toBe(false);
|
||||
|
||||
component.importFromSidecar();
|
||||
|
||||
@@ -208,7 +208,7 @@ describe('SidecarViewerComponent', () => {
|
||||
summary: 'translated:metadata.sidecar.toast.importFailedSummary',
|
||||
detail: 'translated:metadata.sidecar.toast.importFailedDetail',
|
||||
});
|
||||
expect(component.importing).toBe(false);
|
||||
expect(component.importing()).toBe(false);
|
||||
expect(consoleError).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
|
||||
+16
-16
@@ -1,4 +1,4 @@
|
||||
import {Component, inject, Input, OnDestroy} from '@angular/core';
|
||||
import {Component, inject, Input, OnDestroy, signal} from '@angular/core';
|
||||
import {Subject} from 'rxjs';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
import {Book} from '../../../../book/model/book.model';
|
||||
@@ -24,7 +24,7 @@ export class SidecarViewerComponent implements OnDestroy {
|
||||
this.currentBookId = null;
|
||||
this.sidecarContent = null;
|
||||
this.syncStatus = 'NOT_APPLICABLE';
|
||||
this.loading = false;
|
||||
this.loading.set(false);
|
||||
this.error = null;
|
||||
return;
|
||||
}
|
||||
@@ -40,14 +40,14 @@ export class SidecarViewerComponent implements OnDestroy {
|
||||
|
||||
sidecarContent: SidecarMetadata | null = null;
|
||||
syncStatus: SidecarSyncStatus = 'NOT_APPLICABLE';
|
||||
loading = false;
|
||||
exporting = false;
|
||||
importing = false;
|
||||
loading = signal(false);
|
||||
exporting = signal(false);
|
||||
importing = signal(false);
|
||||
currentBookId: number | null = null;
|
||||
error: string | null = null;
|
||||
|
||||
loadSidecarData(bookId: number): void {
|
||||
this.loading = true;
|
||||
this.loading.set(true);
|
||||
this.error = null;
|
||||
|
||||
this.sidecarService.getSyncStatus(bookId).pipe(
|
||||
@@ -60,13 +60,13 @@ export class SidecarViewerComponent implements OnDestroy {
|
||||
this.loadSidecarContent(bookId);
|
||||
} else {
|
||||
this.sidecarContent = null;
|
||||
this.loading = false;
|
||||
this.loading.set(false);
|
||||
}
|
||||
},
|
||||
error: (err) => {
|
||||
this.syncStatus = 'NOT_APPLICABLE';
|
||||
this.sidecarContent = null;
|
||||
this.loading = false;
|
||||
this.loading.set(false);
|
||||
console.error('Failed to get sync status:', err);
|
||||
}
|
||||
});
|
||||
@@ -78,11 +78,11 @@ export class SidecarViewerComponent implements OnDestroy {
|
||||
).subscribe({
|
||||
next: (content) => {
|
||||
this.sidecarContent = content;
|
||||
this.loading = false;
|
||||
this.loading.set(false);
|
||||
},
|
||||
error: (err) => {
|
||||
this.sidecarContent = null;
|
||||
this.loading = false;
|
||||
this.loading.set(false);
|
||||
if (err.status !== 404) {
|
||||
console.error('Failed to load sidecar content:', err);
|
||||
}
|
||||
@@ -93,7 +93,7 @@ export class SidecarViewerComponent implements OnDestroy {
|
||||
exportToSidecar(): void {
|
||||
if (!this.currentBookId) return;
|
||||
|
||||
this.exporting = true;
|
||||
this.exporting.set(true);
|
||||
this.sidecarService.exportToSidecar(this.currentBookId).pipe(
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe({
|
||||
@@ -104,7 +104,7 @@ export class SidecarViewerComponent implements OnDestroy {
|
||||
detail: this.t.translate('metadata.sidecar.toast.exportSuccessDetail')
|
||||
});
|
||||
this.loadSidecarData(this.currentBookId!);
|
||||
this.exporting = false;
|
||||
this.exporting.set(false);
|
||||
},
|
||||
error: (err) => {
|
||||
this.messageService.add({
|
||||
@@ -112,7 +112,7 @@ export class SidecarViewerComponent implements OnDestroy {
|
||||
summary: this.t.translate('metadata.sidecar.toast.exportFailedSummary'),
|
||||
detail: this.t.translate('metadata.sidecar.toast.exportFailedDetail')
|
||||
});
|
||||
this.exporting = false;
|
||||
this.exporting.set(false);
|
||||
console.error('Export failed:', err);
|
||||
}
|
||||
});
|
||||
@@ -121,7 +121,7 @@ export class SidecarViewerComponent implements OnDestroy {
|
||||
importFromSidecar(): void {
|
||||
if (!this.currentBookId) return;
|
||||
|
||||
this.importing = true;
|
||||
this.importing.set(true);
|
||||
this.sidecarService.importFromSidecar(this.currentBookId).pipe(
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe({
|
||||
@@ -132,7 +132,7 @@ export class SidecarViewerComponent implements OnDestroy {
|
||||
detail: this.t.translate('metadata.sidecar.toast.importSuccessDetail')
|
||||
});
|
||||
this.loadSidecarData(this.currentBookId!);
|
||||
this.importing = false;
|
||||
this.importing.set(false);
|
||||
},
|
||||
error: (err) => {
|
||||
this.messageService.add({
|
||||
@@ -140,7 +140,7 @@ export class SidecarViewerComponent implements OnDestroy {
|
||||
summary: this.t.translate('metadata.sidecar.toast.importFailedSummary'),
|
||||
detail: this.t.translate('metadata.sidecar.toast.importFailedDetail')
|
||||
});
|
||||
this.importing = false;
|
||||
this.importing.set(false);
|
||||
console.error('Import failed:', err);
|
||||
}
|
||||
});
|
||||
|
||||
+3
-3
@@ -61,7 +61,7 @@
|
||||
type="submit"
|
||||
[label]="t('searchBtn')"
|
||||
icon="pi pi-search"
|
||||
[loading]="loading"
|
||||
[loading]="loading()"
|
||||
[disabled]="searchForm.invalid">
|
||||
</p-button>
|
||||
<p-button
|
||||
@@ -81,7 +81,7 @@
|
||||
|
||||
<!-- Results Area -->
|
||||
<div class="results-section">
|
||||
@if (!hasSearched) {
|
||||
@if (!hasSearched()) {
|
||||
<!-- Initial State -->
|
||||
<div class="empty-state">
|
||||
<div class="empty-state-icon">
|
||||
@@ -90,7 +90,7 @@
|
||||
<h3>{{ t('searchForCovers') }}</h3>
|
||||
<p>{{ t('searchForCoversDescription') }}</p>
|
||||
</div>
|
||||
} @else if (loading) {
|
||||
} @else if (loading()) {
|
||||
<!-- Loading State -->
|
||||
<div class="loading-state">
|
||||
<p-progressSpinner strokeWidth="3" animationDuration="1s"></p-progressSpinner>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Component, inject, Input, OnInit} from '@angular/core';
|
||||
import {Component, inject, Input, OnInit, signal} from '@angular/core';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||
import {BookCoverService, CoverFetchRequest, CoverImage} from '../../../../shared/services/book-cover.service';
|
||||
@@ -32,8 +32,8 @@ export class CoverSearchComponent implements OnInit {
|
||||
@Input() bookId!: number;
|
||||
searchForm: FormGroup;
|
||||
coverImages: CoverImage[] = [];
|
||||
loading = false;
|
||||
hasSearched = false;
|
||||
loading = signal(false);
|
||||
hasSearched = signal(false);
|
||||
coverType: 'ebook' | 'audiobook' = 'ebook';
|
||||
|
||||
private fb = inject(FormBuilder);
|
||||
@@ -79,7 +79,7 @@ export class CoverSearchComponent implements OnInit {
|
||||
|
||||
onSearch() {
|
||||
if (this.searchForm.valid) {
|
||||
this.loading = true;
|
||||
this.loading.set(true);
|
||||
this.coverImages = [];
|
||||
const request: CoverFetchRequest = {
|
||||
bookId: this.bookId,
|
||||
@@ -90,8 +90,8 @@ export class CoverSearchComponent implements OnInit {
|
||||
|
||||
this.bookCoverService.fetchBookCovers(request)
|
||||
.pipe(finalize(() => {
|
||||
this.loading = false;
|
||||
this.hasSearched = true;
|
||||
this.loading.set(false);
|
||||
this.hasSearched.set(true);
|
||||
}))
|
||||
.subscribe({
|
||||
next: (image) => {
|
||||
@@ -139,6 +139,6 @@ export class CoverSearchComponent implements OnInit {
|
||||
onClear() {
|
||||
this.searchForm.reset();
|
||||
this.coverImages = [];
|
||||
this.hasSearched = false;
|
||||
this.hasSearched.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
+19
-19
@@ -70,7 +70,7 @@
|
||||
<p-table
|
||||
#dataTable
|
||||
[value]="getMetadataItems(tab.type)"
|
||||
[loading]="loading"
|
||||
[loading]="loading()"
|
||||
[globalFilterFields]="['value']"
|
||||
[paginator]="true"
|
||||
[rows]="50"
|
||||
@@ -195,7 +195,7 @@
|
||||
<small class="help-text" [innerHTML]="t('multiMergeHowItWorks', { type: getTypeLabel(currentMergeType, true) })"></small>
|
||||
}
|
||||
</div>
|
||||
@if (mergingInProgress) {
|
||||
@if (mergingInProgress()) {
|
||||
<div class="processing-note">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<span>{{ t('processingNote') }}</span>
|
||||
@@ -209,14 +209,14 @@
|
||||
[label]="'common.cancel' | transloco"
|
||||
icon="pi pi-times"
|
||||
(onClick)="showMergeDialog = false"
|
||||
[disabled]="mergingInProgress"
|
||||
[disabled]="mergingInProgress()"
|
||||
severity="secondary"
|
||||
outlined></p-button>
|
||||
<p-button
|
||||
[label]="mergingInProgress ? t('processing') : ('common.confirm' | transloco)"
|
||||
[icon]="mergingInProgress ? 'pi pi-spin pi-spinner' : 'pi pi-check'"
|
||||
[loading]="mergingInProgress"
|
||||
[disabled]="mergingInProgress"
|
||||
[label]="mergingInProgress() ? t('processing') : ('common.confirm' | transloco)"
|
||||
[icon]="mergingInProgress() ? 'pi pi-spin pi-spinner' : 'pi pi-check'"
|
||||
[loading]="mergingInProgress()"
|
||||
[disabled]="mergingInProgress()"
|
||||
(onClick)="confirmMerge()"
|
||||
severity="success"></p-button>
|
||||
</div>
|
||||
@@ -252,7 +252,7 @@
|
||||
<small class="help-text" [innerHTML]="t('multiRenameHowItWorks', { singular: getTypeLabel(currentMergeType, false), type: getTypeLabel(currentMergeType, true) })"></small>
|
||||
}
|
||||
</div>
|
||||
@if (mergingInProgress) {
|
||||
@if (mergingInProgress()) {
|
||||
<div class="processing-note">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<span>{{ t('renameProcessingNote') }}</span>
|
||||
@@ -266,14 +266,14 @@
|
||||
[label]="'common.cancel' | transloco"
|
||||
icon="pi pi-times"
|
||||
(onClick)="showRenameDialog = false"
|
||||
[disabled]="mergingInProgress"
|
||||
[disabled]="mergingInProgress()"
|
||||
severity="secondary"
|
||||
outlined></p-button>
|
||||
<p-button
|
||||
[label]="mergingInProgress ? t('processing') : ('common.confirm' | transloco)"
|
||||
[icon]="mergingInProgress ? 'pi pi-spin pi-spinner' : 'pi pi-check'"
|
||||
[loading]="mergingInProgress"
|
||||
[disabled]="mergingInProgress"
|
||||
[label]="mergingInProgress() ? t('processing') : ('common.confirm' | transloco)"
|
||||
[icon]="mergingInProgress() ? 'pi pi-spin pi-spinner' : 'pi pi-check'"
|
||||
[loading]="mergingInProgress()"
|
||||
[disabled]="mergingInProgress()"
|
||||
(onClick)="confirmRename()"
|
||||
severity="success"></p-button>
|
||||
</div>
|
||||
@@ -315,7 +315,7 @@
|
||||
<li>{{ t('totalBooksAffected') }} <strong>{{ currentDeleteItem ? currentDeleteItem.count : getTotalAffectedBooks(getSelectedItems(currentMergeType)) }}</strong></li>
|
||||
</ul>
|
||||
</div>
|
||||
@if (deletingInProgress) {
|
||||
@if (deletingInProgress()) {
|
||||
<div class="processing-note">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<span>{{ t('renameProcessingNote') }}</span>
|
||||
@@ -329,14 +329,14 @@
|
||||
[label]="'common.cancel' | transloco"
|
||||
icon="pi pi-times"
|
||||
(onClick)="showDeleteDialog = false"
|
||||
[disabled]="deletingInProgress"
|
||||
[disabled]="deletingInProgress()"
|
||||
severity="secondary"
|
||||
outlined></p-button>
|
||||
<p-button
|
||||
[label]="deletingInProgress ? t('deleting') : ('common.delete' | transloco)"
|
||||
[icon]="deletingInProgress ? 'pi pi-spin pi-spinner' : 'pi pi-trash'"
|
||||
[loading]="deletingInProgress"
|
||||
[disabled]="deletingInProgress"
|
||||
[label]="deletingInProgress() ? t('deleting') : ('common.delete' | transloco)"
|
||||
[icon]="deletingInProgress() ? 'pi pi-spin pi-spinner' : 'pi pi-trash'"
|
||||
[loading]="deletingInProgress()"
|
||||
[disabled]="deletingInProgress()"
|
||||
(onClick)="confirmDelete()"
|
||||
severity="danger"></p-button>
|
||||
</div>
|
||||
|
||||
+3
-3
@@ -89,7 +89,7 @@ describe('MetadataManagerComponent', () => {
|
||||
const component = createComponent();
|
||||
TestBed.flushEffects();
|
||||
|
||||
expect(component.loading).toBe(false);
|
||||
expect(component.loading()).toBe(false);
|
||||
expect(component.authors[0]).toEqual({value: 'Alice', count: 2, bookIds: [1, 2], selected: false});
|
||||
expect(component.categories[0]).toEqual({value: 'Fantasy', count: 2, bookIds: [1, 2], selected: false});
|
||||
expect(component.series).toEqual([{value: 'Series A', count: 2, bookIds: [1, 2], selected: false}]);
|
||||
@@ -110,13 +110,13 @@ describe('MetadataManagerComponent', () => {
|
||||
const component = createComponent();
|
||||
TestBed.flushEffects();
|
||||
|
||||
expect(component.loading).toBe(true);
|
||||
expect(component.loading()).toBe(true);
|
||||
expect(component.authors).toEqual([]);
|
||||
|
||||
isBooksLoading.set(false);
|
||||
TestBed.flushEffects();
|
||||
|
||||
expect(component.loading).toBe(false);
|
||||
expect(component.loading()).toBe(false);
|
||||
expect(component.authors).toEqual([{value: 'Alice', count: 1, bookIds: [1], selected: false}]);
|
||||
});
|
||||
|
||||
|
||||
+23
-23
@@ -1,4 +1,4 @@
|
||||
import {Component, effect, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Component, effect, inject, OnDestroy, OnInit, signal} from '@angular/core';
|
||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {Button} from 'primeng/button';
|
||||
@@ -75,7 +75,7 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
||||
private routeSub!: Subscription;
|
||||
private readonly syncMetadataEffect = effect(() => {
|
||||
const isLoading = this.bookService.isBooksLoading();
|
||||
this.loading = isLoading;
|
||||
this.loading.set(isLoading);
|
||||
|
||||
if (isLoading) {
|
||||
return;
|
||||
@@ -100,9 +100,9 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
||||
selectAllPublishers = false;
|
||||
selectAllLanguages = false;
|
||||
|
||||
loading = false;
|
||||
mergingInProgress = false;
|
||||
deletingInProgress = false;
|
||||
loading = signal(false);
|
||||
mergingInProgress = signal(false);
|
||||
deletingInProgress = signal(false);
|
||||
showMergeDialog = false;
|
||||
showRenameDialog = false;
|
||||
showDeleteDialog = false;
|
||||
@@ -322,8 +322,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
||||
? `"${targetValues[0]}"`
|
||||
: `${targetValues.length} values`;
|
||||
|
||||
this.loading = true;
|
||||
this.mergingInProgress = true;
|
||||
this.loading.set(true);
|
||||
this.mergingInProgress.set(true);
|
||||
this.bookMetadataManageService.consolidateMetadata(this.currentMergeType, targetValues, [oldValue]).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
@@ -339,8 +339,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
||||
this.showRenameDialog = false;
|
||||
this.currentRenameItem = null;
|
||||
this.renameTarget = '';
|
||||
this.mergingInProgress = false;
|
||||
this.loading = false;
|
||||
this.mergingInProgress.set(false);
|
||||
this.loading.set(false);
|
||||
},
|
||||
error: (error) => {
|
||||
this.messageService.add({
|
||||
@@ -352,8 +352,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
||||
? this.t.translate('metadata.manager.toast.renameFailedDetail')
|
||||
: this.t.translate('metadata.manager.toast.splitFailedDetail'))
|
||||
});
|
||||
this.loading = false;
|
||||
this.mergingInProgress = false;
|
||||
this.loading.set(false);
|
||||
this.mergingInProgress.set(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -397,8 +397,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
||||
const affectedBooks = this.getTotalAffectedBooks(selected);
|
||||
const operation = targetValues.length === 1 ? 'merge' : 'merge/split';
|
||||
|
||||
this.loading = true;
|
||||
this.mergingInProgress = true;
|
||||
this.loading.set(true);
|
||||
this.mergingInProgress.set(true);
|
||||
this.bookMetadataManageService.consolidateMetadata(this.currentMergeType, targetValues, valuesToMerge).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
@@ -414,8 +414,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
||||
this.showMergeDialog = false;
|
||||
this.mergeTarget = '';
|
||||
this.clearSelection(this.currentMergeType);
|
||||
this.mergingInProgress = false;
|
||||
this.loading = false;
|
||||
this.mergingInProgress.set(false);
|
||||
this.loading.set(false);
|
||||
},
|
||||
error: (error) => {
|
||||
this.messageService.add({
|
||||
@@ -427,8 +427,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
||||
? this.t.translate('metadata.manager.toast.mergeFailedDetail')
|
||||
: this.t.translate('metadata.manager.toast.mergeSplitFailedDetail'))
|
||||
});
|
||||
this.loading = false;
|
||||
this.mergingInProgress = false;
|
||||
this.loading.set(false);
|
||||
this.mergingInProgress.set(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -456,8 +456,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
||||
? this.currentDeleteItem.count
|
||||
: this.getTotalAffectedBooks(this.getSelectedItems(this.currentMergeType));
|
||||
|
||||
this.loading = true;
|
||||
this.deletingInProgress = true;
|
||||
this.loading.set(true);
|
||||
this.deletingInProgress.set(true);
|
||||
this.bookMetadataManageService.deleteMetadata(this.currentMergeType, valuesToDelete).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
@@ -469,8 +469,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
||||
this.showDeleteDialog = false;
|
||||
this.currentDeleteItem = null;
|
||||
this.clearSelection(this.currentMergeType);
|
||||
this.deletingInProgress = false;
|
||||
this.loading = false;
|
||||
this.deletingInProgress.set(false);
|
||||
this.loading.set(false);
|
||||
},
|
||||
error: (error) => {
|
||||
this.messageService.add({
|
||||
@@ -478,8 +478,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
||||
summary: this.t.translate('metadata.manager.toast.deleteFailedSummary'),
|
||||
detail: error?.error?.message || this.t.translate('metadata.manager.toast.deleteFailedDetail')
|
||||
});
|
||||
this.loading = false;
|
||||
this.deletingInProgress = false;
|
||||
this.loading.set(false);
|
||||
this.deletingInProgress.set(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
@if (!loading) {
|
||||
@if (!loading()) {
|
||||
<div class="dialog-content">
|
||||
@if (currentProposal?.metadataJson; as proposed) {
|
||||
<app-metadata-picker
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ describe('MetadataReviewDialogComponent', () => {
|
||||
expect(getTaskWithProposals).toHaveBeenCalledWith('task-1');
|
||||
expect(component.currentProposal).toEqual(createProposal({proposalId: 5}));
|
||||
expect(component.currentBook()).toEqual({id: 11, title: 'Book 11'});
|
||||
expect(component.loading).toBe(false);
|
||||
expect(component.loading()).toBe(false);
|
||||
});
|
||||
|
||||
it('closes when loading the task proposals fails', () => {
|
||||
|
||||
+2
-2
@@ -31,7 +31,7 @@ export class MetadataReviewDialogComponent implements OnInit {
|
||||
private bookService = inject(BookService);
|
||||
private progressService = inject(MetadataProgressService);
|
||||
|
||||
loading = true;
|
||||
loading = signal(true);
|
||||
readonly proposals = signal<FetchedProposal[]>([]);
|
||||
readonly currentIndex = signal(0);
|
||||
readonly currentBook = computed<Book | null>(() => {
|
||||
@@ -52,7 +52,7 @@ export class MetadataReviewDialogComponent implements OnInit {
|
||||
|
||||
const bookIds = new Set(proposals.map(proposal => proposal.bookId));
|
||||
const matchedBooks = this.bookService.books().filter(book => bookIds.has(book.id));
|
||||
this.loading = matchedBooks.length !== bookIds.size;
|
||||
this.loading.set(matchedBooks.length !== bookIds.size);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user