fix(loading): update loading checks to use signal() for reactive state management (#727)
This commit is contained in:
@@ -118,7 +118,7 @@
|
||||
[label]="t('clearBtn')"
|
||||
severity="danger"
|
||||
[outlined]="true"
|
||||
[disabled]="!filesPresent() || isUploading"
|
||||
[disabled]="!filesPresent() || isUploading()"
|
||||
[pTooltip]="t('clearTooltip')"
|
||||
tooltipPosition="top"/>
|
||||
</div>
|
||||
@@ -127,11 +127,11 @@
|
||||
</ng-template>
|
||||
<ng-template #content let-files let-removeFileCallback="removeFileCallback">
|
||||
@if (files?.length > 0) {
|
||||
@if (isUploading || uploadCompleted) {
|
||||
@if (isUploading() || uploadCompleted()) {
|
||||
<div class="upload-progress-summary">
|
||||
<div class="progress-row">
|
||||
<span class="progress-status">
|
||||
@if (isUploading) {
|
||||
@if (isUploading()) {
|
||||
<i class="pi pi-spin pi-spinner"></i>
|
||||
{{ t('uploading') }}
|
||||
} @else {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {ChangeDetectorRef, Component, inject, ViewChild, effect} from '@angular/core';
|
||||
import {ChangeDetectorRef, Component, inject, ViewChild, effect, signal} from '@angular/core';
|
||||
import {FileSelectEvent, FileUpload, FileUploadHandlerEvent} from 'primeng/fileupload';
|
||||
import {Button} from 'primeng/button';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
@@ -47,8 +47,8 @@ export class BookUploaderComponent {
|
||||
@ViewChild(FileUpload) fileUpload!: FileUpload;
|
||||
|
||||
files: UploadingFile[] = [];
|
||||
isUploading: boolean = false;
|
||||
uploadCompleted: boolean = false;
|
||||
isUploading = signal(false);
|
||||
uploadCompleted = signal(false);
|
||||
_selectedLibrary: Library | null = null;
|
||||
selectedPath: LibraryPath | null = null;
|
||||
|
||||
@@ -112,10 +112,14 @@ export class BookUploaderComponent {
|
||||
onClear(clearCallback: () => void): void {
|
||||
clearCallback();
|
||||
this.files = [];
|
||||
this.uploadCompleted.set(false);
|
||||
}
|
||||
|
||||
|
||||
onFilesSelect(event: FileSelectEvent): void {
|
||||
this.uploadCompleted.set(false);
|
||||
if (this.value === 'library' && (!this.selectedLibrary || !this.selectedPath)) {
|
||||
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('shared.bookUploader.toast.noDestinationSummary'),
|
||||
@@ -185,8 +189,8 @@ export class BookUploaderComponent {
|
||||
const filesToUpload = this.files.filter(f => f.status === 'Pending');
|
||||
if (filesToUpload.length === 0) return;
|
||||
|
||||
this.isUploading = true;
|
||||
this.uploadCompleted = false;
|
||||
this.isUploading.set(true);
|
||||
this.uploadCompleted.set(false);
|
||||
const destination = this.value;
|
||||
const libraryId = this.selectedLibrary?.id?.toString();
|
||||
const pathId = this.selectedPath?.id?.toString();
|
||||
@@ -197,9 +201,9 @@ export class BookUploaderComponent {
|
||||
private uploadBatch(files: UploadingFile[], startIndex: number, batchSize: number, destination: string, libraryId?: string, pathId?: string): void {
|
||||
const batch = files.slice(startIndex, startIndex + batchSize);
|
||||
if (batch.length === 0) {
|
||||
this.isUploading = false;
|
||||
this.uploadCompleted = true;
|
||||
this.cdr.detectChanges();
|
||||
this.isUploading.set(false);
|
||||
this.uploadCompleted.set(true);
|
||||
|
||||
if (destination === 'bookdrop') {
|
||||
this.ref.close('uploaded_to_bookdrop');
|
||||
}
|
||||
@@ -266,9 +270,9 @@ export class BookUploaderComponent {
|
||||
|
||||
isChooseDisabled(): boolean {
|
||||
if (this.value === 'bookdrop') {
|
||||
return this.isUploading;
|
||||
return this.isUploading();
|
||||
}
|
||||
return !this.selectedLibrary || !this.selectedPath || this.isUploading;
|
||||
return !this.selectedLibrary || !this.selectedPath || this.isUploading();
|
||||
}
|
||||
|
||||
isUploadDisabled(): boolean {
|
||||
@@ -324,7 +328,7 @@ export class BookUploaderComponent {
|
||||
}
|
||||
|
||||
hasUploadCompleted(): boolean {
|
||||
return this.uploadCompleted;
|
||||
return this.uploadCompleted();
|
||||
}
|
||||
|
||||
closeDialog(): void {
|
||||
|
||||
Reference in New Issue
Block a user