fix(ui): use signals to unfreeze library loading component (#964)
This commit is contained in:
+8
-8
@@ -8,12 +8,12 @@
|
|||||||
|
|
||||||
<div class="library-loader-body">
|
<div class="library-loader-body">
|
||||||
<div class="book-title">
|
<div class="book-title">
|
||||||
@if (!isComplete) {
|
@if (!isComplete()) {
|
||||||
<ng-container>
|
<ng-container>
|
||||||
{{ t('processing') }} <strong>{{ truncatedTitle }}</strong>
|
{{ t('processing') }} <strong>{{ bookTitle() }}</strong>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
}
|
}
|
||||||
@if (isComplete) {
|
@if (isComplete()) {
|
||||||
<strong class="complete-message">
|
<strong class="complete-message">
|
||||||
<i class="pi pi-check-circle"></i>
|
<i class="pi pi-check-circle"></i>
|
||||||
{{ t('complete') }}
|
{{ t('complete') }}
|
||||||
@@ -22,15 +22,15 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="progress-info">
|
<div class="progress-info">
|
||||||
<span>{{ current }} / {{ total }}</span>
|
<span>{{ current() }} / {{ total() }}</span>
|
||||||
<span>{{ percentage }}%</span>
|
<span>{{ percentage() }}%</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="progress-bar-container">
|
<div class="progress-bar-container">
|
||||||
<div class="progress-bar-fill" [style.width.%]="percentage"></div>
|
<div class="progress-bar-fill" [style.width.%]="percentage()"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (!isComplete) {
|
@if (!isComplete()) {
|
||||||
<div class="loader-animation">
|
<div class="loader-animation">
|
||||||
<div class="dot"></div>
|
<div class="dot"></div>
|
||||||
<div class="dot"></div>
|
<div class="dot"></div>
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (isComplete) {
|
@if (isComplete()) {
|
||||||
<div class="library-loader-footer">
|
<div class="library-loader-footer">
|
||||||
<button class="reload-button" (click)="onReload()">
|
<button class="reload-button" (click)="onReload()">
|
||||||
<i class="pi pi-bookmark"></i>
|
<i class="pi pi-bookmark"></i>
|
||||||
|
|||||||
+11
-10
@@ -8,11 +8,11 @@ describe('LibraryLoadingComponent', () => {
|
|||||||
|
|
||||||
component.updateProgress('Dune', 2, 3);
|
component.updateProgress('Dune', 2, 3);
|
||||||
|
|
||||||
expect(component.bookTitle).toBe('Dune');
|
expect(component.bookTitle()).toBe('Dune');
|
||||||
expect(component.current).toBe(2);
|
expect(component.current()).toBe(2);
|
||||||
expect(component.total).toBe(3);
|
expect(component.total()).toBe(3);
|
||||||
expect(component.percentage).toBe(67);
|
expect(component.percentage()).toBe(67);
|
||||||
expect(component.isComplete).toBe(false);
|
expect(component.isComplete()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('marks the flow complete when current reaches the total', () => {
|
it('marks the flow complete when current reaches the total', () => {
|
||||||
@@ -20,20 +20,21 @@ describe('LibraryLoadingComponent', () => {
|
|||||||
|
|
||||||
component.updateProgress('Children of Dune', 5, 5);
|
component.updateProgress('Children of Dune', 5, 5);
|
||||||
|
|
||||||
expect(component.isComplete).toBe(true);
|
expect(component.isComplete()).toBe(true);
|
||||||
expect(component.percentage).toBe(100);
|
expect(component.percentage()).toBe(100);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('truncates very long titles for display', () => {
|
it('truncates very long titles for display', () => {
|
||||||
const component = new LibraryLoadingComponent();
|
const component = new LibraryLoadingComponent();
|
||||||
component.bookTitle = 'A'.repeat(60);
|
|
||||||
|
|
||||||
expect(component.truncatedTitle).toBe(`${'A'.repeat(50)}...`);
|
component.updateProgress('A'.repeat(200), 2, 3)
|
||||||
|
|
||||||
|
expect(component.bookTitle()).toBe(`${'A'.repeat(50)}...`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns zero percent when there is no total yet', () => {
|
it('returns zero percent when there is no total yet', () => {
|
||||||
const component = new LibraryLoadingComponent();
|
const component = new LibraryLoadingComponent();
|
||||||
|
|
||||||
expect(component.percentage).toBe(0);
|
expect(component.percentage()).toBe(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+17
-16
@@ -1,6 +1,8 @@
|
|||||||
import { Component } from '@angular/core';
|
import { computed, signal, Component } from '@angular/core';
|
||||||
import {TranslocoDirective} from '@jsverse/transloco';
|
import {TranslocoDirective} from '@jsverse/transloco';
|
||||||
|
|
||||||
|
const MAX_TITLE_LENGTH = 50;
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-library-loading',
|
selector: 'app-library-loading',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
@@ -9,27 +11,26 @@ import {TranslocoDirective} from '@jsverse/transloco';
|
|||||||
styleUrl: './library-loading.component.scss'
|
styleUrl: './library-loading.component.scss'
|
||||||
})
|
})
|
||||||
export class LibraryLoadingComponent {
|
export class LibraryLoadingComponent {
|
||||||
bookTitle = '';
|
bookTitle = signal('');
|
||||||
current = 0;
|
current = signal(0);
|
||||||
total = 0;
|
total = signal(0);
|
||||||
isComplete = false;
|
isComplete = signal(false);
|
||||||
|
|
||||||
get percentage(): number {
|
readonly percentage = computed(() => this.total() > 0 ? Math.round((this.current() / this.total()) * 100) : 0);
|
||||||
return this.total > 0 ? Math.round((this.current / this.total) * 100) : 0;
|
|
||||||
|
truncateTitle(title: string): string {
|
||||||
|
if (title.length > MAX_TITLE_LENGTH) {
|
||||||
|
return title.substring(0, MAX_TITLE_LENGTH) + "...";
|
||||||
}
|
}
|
||||||
|
|
||||||
get truncatedTitle(): string {
|
return title;
|
||||||
const maxLength = 50;
|
|
||||||
return this.bookTitle.length <= maxLength
|
|
||||||
? this.bookTitle
|
|
||||||
: this.bookTitle.substring(0, maxLength) + '...';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateProgress(bookTitle: string, current: number, total: number): void {
|
updateProgress(bookTitle: string, current: number, total: number): void {
|
||||||
this.bookTitle = bookTitle;
|
this.bookTitle.set(this.truncateTitle(bookTitle));
|
||||||
this.current = current;
|
this.current.set(current);
|
||||||
this.total = total;
|
this.total.set(total);
|
||||||
this.isComplete = current >= total;
|
this.isComplete.set(current >= total);
|
||||||
}
|
}
|
||||||
|
|
||||||
onReload(): void {
|
onReload(): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user