From 0aee97995e0435d01ef8a9a4fa42e79f34a8eefe Mon Sep 17 00:00:00 2001 From: itskovacs Date: Wed, 13 Aug 2025 22:07:00 +0200 Subject: [PATCH] :zap: Fix multiple requests on trip sharing --- src/src/app/components/trip/trip.component.ts | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/src/app/components/trip/trip.component.ts b/src/src/app/components/trip/trip.component.ts index a619316..1457e2e 100644 --- a/src/src/app/components/trip/trip.component.ts +++ b/src/src/app/components/trip/trip.component.ts @@ -32,6 +32,7 @@ import { combineLatest, forkJoin, Observable, + of, switchMap, take, tap, @@ -1082,16 +1083,18 @@ export class TripComponent implements AfterViewInit { this.apiService.postTripDayItem(item, this.trip!.id!, item.day_id), ); - forkJoin(obs$).subscribe({ - next: (items: TripItem[]) => { - const index = this.trip!.days.findIndex((d) => d.id == day_id); - if (index === -1) return; + forkJoin(obs$) + .pipe(take(1)) + .subscribe({ + next: (items: TripItem[]) => { + const index = this.trip!.days.findIndex((d) => d.id == day_id); + if (index === -1) return; - const td: TripDay = this.trip!.days[index]!; - td.items.push(...items); - this.flattenTripDayItems(); - }, - }); + const td: TripDay = this.trip!.days[index]!; + td.items.push(...items); + this.flattenTripDayItems(); + }, + }); }, }); } @@ -1210,8 +1213,9 @@ export class TripComponent implements AfterViewInit { .createSharedTrip(this.trip?.id!) .pipe(take(1)) .subscribe({ - next: () => { + next: (url) => { this.trip!.shared = true; + this.tripSharedURL$ = of(url); }, }); }