Skip to content

Commit 1513389

Browse files
committed
Refactor local cache mutation to fill all trip details
1 parent c483571 commit 1513389

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

final/RocketReserver/DetailViewModel.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,18 @@ class DetailViewModel: ObservableObject {
6969
self.appAlert = .basic(title: "Success!",
7070
message: bookingResult.message ?? "Trip booked successfully")
7171

72-
Network.shared.apollo.store.withinReadWriteTransaction { transaction in
73-
let cacheMutation = MeTripsLocalCacheMutation()
72+
if let bookedTrip = bookingResult.launches?.first ?? nil {
73+
Network.shared.apollo.store.withinReadWriteTransaction { transaction in
74+
let cacheMutation = MeTripsLocalCacheMutation()
7475

75-
try transaction.update(cacheMutation) { data in
76-
data.me?.trips.append(.init(
77-
isBooked: true,
78-
id: id
79-
))
76+
try transaction.update(cacheMutation) { data in
77+
data.me?.trips.append(.init(
78+
isBooked: bookedTrip.isBooked,
79+
id: bookedTrip.id,
80+
site: bookedTrip.site,
81+
mission: bookedTrip.mission
82+
))
83+
}
8084
}
8185
}
8286
} else {

0 commit comments

Comments
 (0)