Skip to content

Commit

Permalink
fix: reloading state on reservations
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablito2020 committed Nov 22, 2023
1 parent 00572af commit dbd1408
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions app/src/app/pages/reservations/reservations.store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentStore, tapResponse } from '@ngrx/component-store';
import { concatMap, EMPTY, Observable, of, switchMap } from 'rxjs';
import { concatMap, EMPTY, Observable, of, switchMap, tap } from 'rxjs';
import { Injectable } from '@angular/core';
import { DeviceErrors } from '../../schemas/errors/device';
import {
Expand Down Expand Up @@ -96,13 +96,13 @@ export class ReservationsComponentStore extends ComponentStore<ReservationsState
return this.userReservationService
.getReservationsGroupedByRefugeForUser(userId)
.pipe(
tap(() => this.patchState({ isLoading: false })),
tapResponse(
(reservations) => {
this.patchState({ reservations, isLoading: false });
this.patchState({ reservations });
onUpdate(reservations);
},
() => {
this.patchState({ isLoading: false });
this.store.dispatch(
minorError({ error: DeviceErrors.NOT_CONNECTED }),
);
Expand Down Expand Up @@ -133,10 +133,10 @@ export class ReservationsComponentStore extends ComponentStore<ReservationsState
private deleteReservationForUser(reservationId: string) {
this.patchState({ isLoading: true });
return this.reservationService.deleteReservation(reservationId).pipe(
tap(() => this.patchState({ isLoading: false })),
tapResponse(
(reservation) => this.onDeleteReservationResponse(reservation),
() => {
this.patchState({ isLoading: false });
this.store.dispatch(
minorError({ error: DeviceErrors.NOT_CONNECTED }),
);
Expand All @@ -159,12 +159,10 @@ export class ReservationsComponentStore extends ComponentStore<ReservationsState
res.reservation.id,
state.reservations,
),
isLoading: false,
};
});
})
.with({ status: 'error' }, (err) => {
this.patchState({ isLoading: false });
this.store.dispatch(minorError({ error: err.error }));
});
}
Expand Down Expand Up @@ -202,6 +200,7 @@ export class ReservationsComponentStore extends ComponentStore<ReservationsState
...reservation,
})
.pipe(
tap(() => this.patchState({ isLoading: false })),
tapResponse(
(reservations) => {
match(reservations)
Expand Down

0 comments on commit dbd1408

Please sign in to comment.