Skip to content

Commit d36bd87

Browse files
committed
12.15 Deleting Bookings
1 parent b54d131 commit d36bd87

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/app/bookings/booking.service.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,21 @@ export class BookingService {
7171
}
7272

7373
cancelBooking(bookingId: string) {
74-
return this.bookings.pipe(
75-
take(1),
76-
delay(1000),
77-
tap((bookings) => {
78-
this._bookings.next(
79-
bookings.filter((booking) => booking.id !== bookingId)
80-
);
81-
})
82-
);
74+
return this.http
75+
.delete(
76+
`https://ionic-angular-backend-66c35-default-rtdb.asia-southeast1.firebasedatabase.app/bookings/${bookingId}.json`
77+
)
78+
.pipe(
79+
switchMap(() => {
80+
return this.bookings;
81+
}),
82+
take(1),
83+
tap((bookings) => {
84+
this._bookings.next(
85+
bookings.filter((booking) => booking.id !== bookingId)
86+
);
87+
})
88+
);
8389
}
8490

8591
fetchBookings() {

src/app/bookings/bookings.page.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
<ion-list>
2424
<ion-item-sliding *ngFor="let booking of loadedBookings" #slidingBooking>
2525
<ion-item>
26+
<ion-avatar slot="start">
27+
<ion-img [src]="booking.placeImage"></ion-img>
28+
</ion-avatar>
2629
<ion-label>
2730
<h5>{{booking.placeTitle}}</h5>
2831
<p>Guest: {{booking.guestnumber}}</p>
2932
</ion-label>
3033
</ion-item>
31-
<ion-item-options side="start">
34+
<ion-item-options side="end">
3235
<ion-item-option color="danger" (click)="onCancelBooking(booking.id, slidingBooking)">
3336
<ion-icon name="trash" slot="icon-only"></ion-icon>
3437
</ion-item-option>

0 commit comments

Comments
 (0)