Show a persistent loader while a large library is being created (#2200)

Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
ACX
2026-01-07 18:10:53 -07:00
committed by GitHub
co-authored by acx10
parent 251fe65ec0
commit c17fe58f4c
17 changed files with 567 additions and 111 deletions
@@ -15,6 +15,8 @@ import {Select} from 'primeng/select';
import {Button} from 'primeng/button';
import {IconDisplayComponent} from '../../shared/components/icon-display/icon-display.component';
import {DialogLauncherService} from '../../shared/services/dialog-launcher.service';
import {switchMap} from 'rxjs/operators';
import {map, of} from 'rxjs';
@Component({
selector: 'app-library-creator',
@@ -147,16 +149,17 @@ export class LibraryCreatorComponent implements OnInit {
const iconValue = this.selectedIcon?.value || 'heart';
const iconType = this.selectedIcon?.type || 'PRIME_NG';
const library: Library = {
name: this.chosenLibraryName,
icon: iconValue,
iconType: iconType,
paths: this.folders.map(folder => ({path: folder})),
watch: this.watch,
scanMode: this.scanMode,
defaultBookFormat: this.defaultBookFormat
};
if (this.mode === 'edit') {
const library: Library = {
name: this.chosenLibraryName,
icon: iconValue,
iconType: iconType,
paths: this.folders.map(folder => ({path: folder})),
watch: this.watch,
scanMode: this.scanMode,
defaultBookFormat: this.defaultBookFormat
};
this.libraryService.updateLibrary(library, this.library?.id).subscribe({
next: () => {
this.messageService.add({severity: 'success', summary: 'Library Updated', detail: 'The library was updated successfully.'});
@@ -168,22 +171,36 @@ export class LibraryCreatorComponent implements OnInit {
}
});
} else {
const library: Library = {
name: this.chosenLibraryName,
icon: iconValue,
iconType: iconType,
paths: this.folders.map(folder => ({path: folder})),
watch: this.watch,
scanMode: this.scanMode,
defaultBookFormat: this.defaultBookFormat
};
this.libraryService.createLibrary(library).subscribe({
next: (createdLibrary) => {
this.router.navigate(['/library', createdLibrary.id, 'books']);
this.messageService.add({severity: 'success', summary: 'Library Created', detail: 'The library was created successfully.'});
this.dynamicDialogRef.close();
this.libraryService.scanLibraryPaths(library).pipe(
switchMap(count => {
if (count < 500) {
return this.libraryService.createLibrary(library).pipe(
map(createdLibrary => ({ createdLibrary, count }))
);
} else {
console.warn(`Library has ${count} processable files (>500). Will use buffered loading.`);
this.libraryService.setLargeLibraryLoading(true, count);
return this.libraryService.createLibrary(library).pipe(
map(createdLibrary => ({ createdLibrary, count }))
);
}
})
).subscribe({
next: ({ createdLibrary, count }) => {
if (createdLibrary) {
this.router.navigate(['/library', createdLibrary.id, 'books']);
this.messageService.add({
severity: 'success',
summary: 'Library Created',
detail: count >= 500
? `Library created with ${count} files. Loading in progress...`
: 'The library was created successfully.'
});
this.dynamicDialogRef.close();
}
},
error: (e) => {
this.libraryService.setLargeLibraryLoading(false, 0);
this.messageService.add({severity: 'error', summary: 'Creation Failed', detail: 'An error occurred while creating the library. Please try again.'});
console.error(e);
}
@@ -0,0 +1,47 @@
import { Injectable, ComponentRef, ApplicationRef, createComponent, EnvironmentInjector } from '@angular/core';
import { LibraryLoadingComponent } from './library-loading/library-loading.component';
@Injectable({
providedIn: 'root'
})
export class LibraryLoadingService {
private componentRef: ComponentRef<LibraryLoadingComponent> | null = null;
constructor(
private appRef: ApplicationRef,
private injector: EnvironmentInjector
) {}
showBookLoadingProgress(bookTitle: string, current: number, total: number): void {
if (this.componentRef) {
this.updateProgress(bookTitle, current, total);
return;
}
this.componentRef = createComponent(LibraryLoadingComponent, {
environmentInjector: this.injector
});
this.componentRef.instance.updateProgress(bookTitle, current, total);
this.appRef.attachView(this.componentRef.hostView);
const domElem = (this.componentRef.hostView as any).rootNodes[0] as HTMLElement;
document.body.appendChild(domElem);
document.body.style.overflow = 'hidden';
}
updateProgress(bookTitle: string, current: number, total: number): void {
if (this.componentRef) {
this.componentRef.instance.updateProgress(bookTitle, current, total);
}
}
hide(): void {
if (this.componentRef) {
this.appRef.detachView(this.componentRef.hostView);
this.componentRef.destroy();
this.componentRef = null;
document.body.style.overflow = '';
}
}
}
@@ -0,0 +1,50 @@
<div class="fullscreen-loader">
<div class="library-loader-content">
<div class="library-loader-header">
<i class="pi pi-book"></i>
<h2>Loading Library</h2>
</div>
<div class="library-loader-body">
<div class="book-title">
@if (!isComplete) {
<ng-container>
Processing: <strong>{{ truncatedTitle }}</strong>
</ng-container>
}
@if (isComplete) {
<strong class="complete-message">
<i class="pi pi-check-circle"></i>
Library Loading Complete!
</strong>
}
</div>
<div class="progress-info">
<span>{{ current }} / {{ total }}</span>
<span>{{ percentage }}%</span>
</div>
<div class="progress-bar-container">
<div class="progress-bar-fill" [style.width.%]="percentage"></div>
</div>
@if (!isComplete) {
<div class="loader-animation">
<div class="dot"></div>
<div class="dot"></div>
<div class="dot"></div>
</div>
}
</div>
@if (isComplete) {
<div class="library-loader-footer">
<button class="reload-button" (click)="onReload()">
<i class="pi pi-bookmark"></i>
Open Library
</button>
</div>
}
</div>
</div>
@@ -0,0 +1,151 @@
.fullscreen-loader {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.85);
backdrop-filter: blur(8px);
display: flex;
justify-content: center;
align-items: center;
z-index: 9999;
}
.library-loader-content {
background: var(--card-background);
padding: 2.5rem;
border-radius: 12px;
width: 550px;
max-width: 90vw;
box-sizing: border-box;
border: 1px solid var(--border-color);
}
.library-loader-header {
text-align: center;
i {
font-size: 3rem;
color: var(--primary-color);
margin-bottom: 1rem;
}
h2 {
margin: 0 0 0.5rem 0;
color: var(--text-color);
font-size: 1.5rem;
}
}
.library-loader-body {
.book-title {
color: var(--text-color-secondary);
margin-bottom: 1.5rem;
margin-top: 2.5rem;
font-size: 0.95rem;
word-break: break-word;
overflow-wrap: break-word;
line-height: 1.4;
display: flex;
align-items: flex-start;
strong {
color: var(--text-color);
}
.complete-message {
color: var(--primary-color);
font-size: 1.1rem;
i {
margin-right: 0.5rem;
}
}
}
.progress-info {
display: flex;
justify-content: space-between;
margin-bottom: 0.5rem;
color: var(--text-color-secondary);
font-size: 0.9rem;
}
.progress-bar-container {
width: 100%;
height: 8px;
background: var(--card-background);
border-radius: 4px;
overflow: hidden;
.progress-bar-fill {
height: 100%;
background: var(--primary-color);
transition: width 0.3s ease;
}
}
.loader-animation {
margin-top: 1.5rem;
display: flex;
justify-content: center;
gap: 0.5rem;
.dot {
width: 8px;
height: 8px;
background: var(--primary-color);
border-radius: 50%;
animation: bounce 1.4s infinite ease-in-out both;
&:nth-child(2) {
animation-delay: 0.2s;
}
&:nth-child(3) {
animation-delay: 0.4s;
}
}
}
}
.library-loader-footer {
margin-top: 3rem;
text-align: center;
.reload-button {
padding: 0.75rem 1.25rem;
background: var(--primary-color);
color: white;
border: none;
border-radius: 6px;
font-size: 1rem;
cursor: pointer;
transition: all 0.3s ease;
font-weight: 700;
i {
margin-right: 0.5rem;
}
&:hover {
background: var(--primary-hover-color);
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
&:active {
transform: translateY(0);
}
}
}
@keyframes bounce {
0%, 80%, 100% {
transform: scale(0);
}
40% {
transform: scale(1);
}
}
@@ -0,0 +1,39 @@
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
@Component({
selector: 'app-library-loading',
standalone: true,
imports: [CommonModule],
templateUrl: './library-loading.component.html',
styleUrl: './library-loading.component.scss'
})
export class LibraryLoadingComponent {
bookTitle = '';
current = 0;
total = 0;
isComplete = false;
get percentage(): number {
return 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) + '...';
}
updateProgress(bookTitle: string, current: number, total: number): void {
this.bookTitle = bookTitle;
this.current = current;
this.total = total;
this.isComplete = current >= total;
}
onReload(): void {
window.location.reload();
}
}