fix(ui): use signals to unfreeze library loading component (#964)

This commit is contained in:
James Ward
2026-04-28 08:50:13 -04:00
committed by GitHub
parent da9978864c
commit 4001b042b3
3 changed files with 37 additions and 35 deletions
@@ -1,6 +1,8 @@
import { Component } from '@angular/core';
import { computed, signal, Component } from '@angular/core';
import {TranslocoDirective} from '@jsverse/transloco';
const MAX_TITLE_LENGTH = 50;
@Component({
selector: 'app-library-loading',
standalone: true,
@@ -9,27 +11,26 @@ import {TranslocoDirective} from '@jsverse/transloco';
styleUrl: './library-loading.component.scss'
})
export class LibraryLoadingComponent {
bookTitle = '';
current = 0;
total = 0;
isComplete = false;
bookTitle = signal('');
current = signal(0);
total = signal(0);
isComplete = signal(false);
get percentage(): number {
return this.total > 0 ? Math.round((this.current / this.total) * 100) : 0;
}
readonly percentage = computed(() => this.total() > 0 ? Math.round((this.current() / this.total()) * 100) : 0);
get truncatedTitle(): string {
const maxLength = 50;
return this.bookTitle.length <= maxLength
? this.bookTitle
: this.bookTitle.substring(0, maxLength) + '...';
truncateTitle(title: string): string {
if (title.length > MAX_TITLE_LENGTH) {
return title.substring(0, MAX_TITLE_LENGTH) + "...";
}
return title;
}
updateProgress(bookTitle: string, current: number, total: number): void {
this.bookTitle = bookTitle;
this.current = current;
this.total = total;
this.isComplete = current >= total;
this.bookTitle.set(this.truncateTitle(bookTitle));
this.current.set(current);
this.total.set(total);
this.isComplete.set(current >= total);
}
onReload(): void {