@@ -6,15 +6,18 @@ import { JsonServiceClient, ResponseStatus } from '@servicestack/client';
66import { Booking , QueryBookings } from 'src/dtos' ;
77import { SrcPageComponent } from 'src/shared/src-page.component' ;
88import { PageComponent } from '../page.component' ;
9- import { tailwindComponents } from 'src/components' ;
9+ import { ApiState , provideApiState , tailwindComponents } from 'src/components' ;
1010
1111@Component ( {
1212 selector : 'app-booking-list' ,
1313 templateUrl : './booking-list.component.html' ,
14+ providers : [
15+ ...provideApiState ( )
16+ ] ,
1417 imports : [
15- CommonModule ,
18+ CommonModule ,
1619 FormsModule ,
17- DatePipe ,
20+ DatePipe ,
1821 CurrencyPipe ,
1922 PageComponent ,
2023 SrcPageComponent ,
@@ -24,30 +27,26 @@ import { tailwindComponents } from 'src/components';
2427export class BookingListComponent implements OnInit {
2528 private router = inject ( Router ) ;
2629 private client = inject ( JsonServiceClient ) ;
30+ api = inject ( ApiState ) ;
2731
2832 // Signals for state
2933 allBookings = signal < Booking [ ] > ( [ ] ) ;
30-
31- loading = signal < boolean > ( true ) ;
32- error = signal < ResponseStatus | undefined > ( undefined ) ;
3334
3435 ngOnInit ( ) : void {
3536 this . loadBookings ( ) ;
3637 }
3738
3839 async loadBookings ( ) : Promise < void > {
39- this . loading . set ( true ) ;
40- this . error . set ( undefined ) ;
40+ this . api . begin ( ) ;
4141
4242 const api = await this . client . api ( new QueryBookings ( {
43- orderByDesc :'BookingStartDate' ,
43+ orderByDesc : 'BookingStartDate' ,
4444 } ) ) ;
4545 if ( api . succeeded ) {
4646 this . allBookings . set ( api . response ! . results ) ;
47- } else if ( api . error ) {
48- this . error . set ( api . error ) ;
4947 }
50- this . loading . set ( false ) ;
48+
49+ this . api . complete ( api . error ) ;
5150 }
5251
5352 navigateToCreate ( ) : void {
0 commit comments