fix(loading): update loading checks to use signal() for reactive state management (#727)
This commit is contained in:
+4
-4
@@ -16,7 +16,7 @@
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (isUploading) {
|
||||
@if (isUploading()) {
|
||||
<p-progressSpinner class="upload-spinner" strokeWidth="4" fill="transparent" animationDuration=".8s"></p-progressSpinner>
|
||||
}
|
||||
|
||||
@@ -123,9 +123,9 @@
|
||||
<p-divider layout="vertical"/>
|
||||
<p-button
|
||||
type="submit"
|
||||
[label]="isSaving ? t('saving') : t('saveBtn')"
|
||||
[icon]="isSaving ? 'pi pi-spin pi-spinner' : 'pi pi-check'"
|
||||
[disabled]="isSaving">
|
||||
[label]="isSaving() ? t('saving') : t('saveBtn')"
|
||||
[icon]="isSaving() ? 'pi pi-spin pi-spinner' : 'pi pi-check'"
|
||||
[disabled]="isSaving()">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+7
-7
@@ -145,7 +145,7 @@ describe('AuthorEditorComponent', () => {
|
||||
|
||||
component.onSave();
|
||||
|
||||
expect(component.isSaving).toBe(true);
|
||||
expect(component.isSaving()).toBe(true);
|
||||
expect(updateAuthor).toHaveBeenCalledWith(9, {
|
||||
name: undefined,
|
||||
description: 'Updated description',
|
||||
@@ -159,7 +159,7 @@ describe('AuthorEditorComponent', () => {
|
||||
save$.next(updatedAuthor);
|
||||
save$.complete();
|
||||
|
||||
expect(component.isSaving).toBe(false);
|
||||
expect(component.isSaving()).toBe(false);
|
||||
expect(emitSpy).toHaveBeenCalledWith(updatedAuthor);
|
||||
expect(translate).toHaveBeenCalledWith('authorBrowser.editor.toast.successSummary');
|
||||
expect(translate).toHaveBeenCalledWith('authorBrowser.editor.toast.successDetail');
|
||||
@@ -179,7 +179,7 @@ describe('AuthorEditorComponent', () => {
|
||||
|
||||
component.onSave();
|
||||
|
||||
expect(component.isSaving).toBe(false);
|
||||
expect(component.isSaving()).toBe(false);
|
||||
expect(emitSpy).not.toHaveBeenCalled();
|
||||
expect(translate).toHaveBeenCalledWith('authorBrowser.editor.toast.errorSummary');
|
||||
expect(translate).toHaveBeenCalledWith('authorBrowser.editor.toast.errorDetail');
|
||||
@@ -224,12 +224,12 @@ describe('AuthorEditorComponent', () => {
|
||||
const emitSpy = vi.spyOn(component.authorUpdated, 'emit');
|
||||
const nowSpy = vi.spyOn(Date, 'now').mockReturnValue(999);
|
||||
|
||||
component.isUploading = true;
|
||||
component.isUploading.set(true);
|
||||
component.hasPhoto = false;
|
||||
|
||||
component.onUpload();
|
||||
|
||||
expect(component.isUploading).toBe(false);
|
||||
expect(component.isUploading()).toBe(false);
|
||||
expect(component.hasPhoto).toBe(true);
|
||||
expect(component.photoTimestamp).toBe(999);
|
||||
expect(emitSpy).toHaveBeenCalledWith(component.author);
|
||||
@@ -243,11 +243,11 @@ describe('AuthorEditorComponent', () => {
|
||||
|
||||
it('clears upload progress and shows an error toast when upload fails', () => {
|
||||
const component = createComponent();
|
||||
component.isUploading = true;
|
||||
component.isUploading.set(true);
|
||||
|
||||
component.onUploadError();
|
||||
|
||||
expect(component.isUploading).toBe(false);
|
||||
expect(component.isUploading()).toBe(false);
|
||||
expect(messageService.add).toHaveBeenCalledWith({
|
||||
severity: 'error',
|
||||
summary: 'authorBrowser.editor.toast.errorSummary',
|
||||
|
||||
+10
-10
@@ -1,4 +1,4 @@
|
||||
import {Component, EventEmitter, inject, Input, OnChanges, OnInit, Output, SimpleChanges} from '@angular/core';
|
||||
import {Component, EventEmitter, inject, Input, OnChanges, OnInit, Output, signal, SimpleChanges} from '@angular/core';
|
||||
import {FormControl, FormGroup, ReactiveFormsModule} from '@angular/forms';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {Button} from 'primeng/button';
|
||||
@@ -46,8 +46,8 @@ export class AuthorEditorComponent implements OnInit, OnChanges {
|
||||
private t = inject(TranslocoService);
|
||||
|
||||
form!: FormGroup;
|
||||
isSaving = false;
|
||||
isUploading = false;
|
||||
isSaving = signal(false);
|
||||
isUploading = signal(false);
|
||||
hasPhoto = true;
|
||||
photoTimestamp = Date.now();
|
||||
|
||||
@@ -152,11 +152,11 @@ export class AuthorEditorComponent implements OnInit, OnChanges {
|
||||
}
|
||||
|
||||
onBeforeUpload(): void {
|
||||
this.isUploading = true;
|
||||
this.isUploading.set(true);
|
||||
}
|
||||
|
||||
onUpload(): void {
|
||||
this.isUploading = false;
|
||||
this.isUploading.set(false);
|
||||
this.photoTimestamp = Date.now();
|
||||
this.hasPhoto = true;
|
||||
this.authorUpdated.emit(this.author);
|
||||
@@ -168,7 +168,7 @@ export class AuthorEditorComponent implements OnInit, OnChanges {
|
||||
}
|
||||
|
||||
onUploadError(): void {
|
||||
this.isUploading = false;
|
||||
this.isUploading.set(false);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('authorBrowser.editor.toast.errorSummary'),
|
||||
@@ -177,8 +177,8 @@ export class AuthorEditorComponent implements OnInit, OnChanges {
|
||||
}
|
||||
|
||||
private saveMetadata(): void {
|
||||
if (this.isSaving) return;
|
||||
this.isSaving = true;
|
||||
if (this.isSaving()) return;
|
||||
this.isSaving.set(true);
|
||||
|
||||
const formValue = this.form.getRawValue();
|
||||
const request = {
|
||||
@@ -193,7 +193,7 @@ export class AuthorEditorComponent implements OnInit, OnChanges {
|
||||
|
||||
this.authorService.updateAuthor(this.authorId, request).subscribe({
|
||||
next: (updated) => {
|
||||
this.isSaving = false;
|
||||
this.isSaving.set(false);
|
||||
this.authorUpdated.emit(updated);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
@@ -202,7 +202,7 @@ export class AuthorEditorComponent implements OnInit, OnChanges {
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.isSaving = false;
|
||||
this.isSaving.set(false);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('authorBrowser.editor.toast.errorSummary'),
|
||||
|
||||
Reference in New Issue
Block a user