Skip to content

Commit f614aa1

Browse files
committed
refactor, move oldvalue to inside onChange
we only trigger item load when onChange value changed to be .eligible, however, if eligibility was already .eligible when view appeared (like with mocked data, as is instant), onChange never fired which would make items to never load
1 parent 669be56 commit f614aa1

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Modules/Sources/PointOfSale/Presentation/PointOfSaleDashboardView.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ struct PointOfSaleDashboardView: View {
150150
}
151151
}
152152
.onChange(of: posModel.entryPointController.eligibilityState) { oldValue, newValue in
153-
guard newValue == .eligible else { return }
154-
loadItemsIfEligible()
153+
guard case .eligible = newValue, oldValue != newValue else { return }
154+
loadItemsWhenEligible()
155155
}
156156
.ignoresSafeArea(.keyboard)
157157
.onAppear {
158158
trackTimeForInitialLoadingState()
159-
loadItemsIfEligible()
159+
loadItemsWhenEligible()
160160
}
161161
.onChange(of: viewState) { oldValue, newValue in
162162
if newValue == .content && oldValue != newValue {
@@ -247,8 +247,7 @@ private extension PointOfSaleDashboardView {
247247
}
248248
}
249249

250-
func loadItemsIfEligible() {
251-
guard posModel.entryPointController.eligibilityState == .eligible else { return }
250+
func loadItemsWhenEligible() {
252251
Task { @MainActor in
253252
await posModel.purchasableItemsController.loadItems(base: .root)
254253
await posModel.couponsController.loadItems(base: .root)

0 commit comments

Comments
 (0)