The problem I have is how I can handle errors/success for each view, because sometimes after error or success confirmation I need to do something different for some views. it will not work as I want if I add one sheet in root, let me give you an example:
In PaymentFormView I have button that display OTPView, after user enter code I call addToFavorite endpoint that get favoriteName from that view and if the code is wrong addToFavorite throw error, and when user confirm I need to display again OTPView and if it success I display success popup and after confirmation I need to pop to first view.
In PaymentConfirmView I have other scenario, I call submit endpoint and then I display success popup and after confirmation I need to push to other view
As you can see each view have a different staff to do after popup confirmation, If I add one sheet in root, is impossible to do this.
Is it a good idea to move do catch to view instead of store ??
class PaymentStore: ObservableObject {
@Published var creditors: [Creditor] = []
@Published var form: PaymentForm?
@Published var unpaid: PaymentUnpaid?
private let service: PaymentService
init(service: PaymentService = PaymentService()) {
self.service = service
}
func getPaymentCreditors() async throws {
creditors = try await service.fetchPaymentCreditors()
}
func getPaymentForm() async throws {
form = try await service.fetchPaymentForm()
}
func getPaymentUnpaid() async throws {
unpaid = try await service.fetchPaymentUnpaid()
}
}
struct PaymentCreditorListView: View {
@EnvironmentObject private var store: PaymentStore
@State private var idLoading = false
@State private var popup: Popup?
var body: some View {
VStack {
}
.task {
do {
isLoading = true
try await store.fetchPaymentCreditors()
isLoading = false
} catch {
isLoading = false
popup = .init(error: error)
}
.progress($isLoading)
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: