fix(loading): update loading checks to use signal() for reactive state management (#727)

This commit is contained in:
brios
2026-04-22 17:27:43 -04:00
committed by Zach Yale
parent 7a88b12430
commit 284e7bec49
59 changed files with 577 additions and 345 deletions
@@ -1,6 +1,6 @@
<div class="book-notes-container">
<div class="notes-content">
@if (loading) {
@if (loading()) {
<div class="loading-state">
<p-progressSpinner/>
<span class="loading-text">Loading notes...</span>
@@ -85,7 +85,7 @@ describe('BookNotesComponent', () => {
component.loadNotes();
expect(bookNoteService.getNotesForBook).not.toHaveBeenCalled();
expect(component.loading).toBe(false);
expect(component.loading()).toBe(false);
});
it('loads notes and orders them by most recent update first', () => {
@@ -98,7 +98,7 @@ describe('BookNotesComponent', () => {
expect(bookNoteService.getNotesForBook).toHaveBeenCalledWith(42);
expect(component.notes.map(note => note.id)).toEqual([2, 3, 1]);
expect(component.loading).toBe(false);
expect(component.loading()).toBe(false);
});
it('shows an error toast when loading notes fails', () => {
@@ -106,7 +106,7 @@ describe('BookNotesComponent', () => {
component.loadNotes();
expect(component.loading).toBe(false);
expect(component.loading()).toBe(false);
expect(messageService.add).toHaveBeenCalledWith({
severity: 'error',
summary: 'common.error',
@@ -1,4 +1,4 @@
import {Component, DestroyRef, inject, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
import {Component, DestroyRef, inject, Input, OnChanges, OnInit, signal, SimpleChanges} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {Button} from 'primeng/button';
@@ -38,7 +38,7 @@ export class BookNotesComponent implements OnInit, OnChanges {
private readonly t = inject(TranslocoService);
notes: BookNote[] = [];
loading = false;
loading = signal(false);
showCreateDialog = false;
showEditDialog = false;
selectedNote: BookNote | null = null;
@@ -70,7 +70,7 @@ export class BookNotesComponent implements OnInit, OnChanges {
loadNotes(): void {
if (!this.bookId) return;
this.loading = true;
this.loading.set(true);
this.bookNoteService.getNotesForBook(this.bookId)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe({
@@ -78,11 +78,11 @@ export class BookNotesComponent implements OnInit, OnChanges {
this.notes = notes.sort((a, b) =>
new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
);
this.loading = false;
this.loading.set(false);
},
error: (error) => {
console.error('Failed to load notes:', error);
this.loading = false;
this.loading.set(false);
this.messageService.add({
severity: 'error',
summary: this.t.translate('common.error'),