From c232f2451fe8636776ade31dc8f3c03a6a6f8842 Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Wed, 1 Jun 2022 16:09:43 +0200 Subject: [PATCH] Implement basic error view --- .../Sources/ErrorFeature/ErrorFeature.swift | 6 ++++- .../Sources/ErrorFeature/ErrorView.swift | 27 ++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Example/ExampleApp/Sources/ErrorFeature/ErrorFeature.swift b/Example/ExampleApp/Sources/ErrorFeature/ErrorFeature.swift index 7490e1da..756260a9 100644 --- a/Example/ExampleApp/Sources/ErrorFeature/ErrorFeature.swift +++ b/Example/ExampleApp/Sources/ErrorFeature/ErrorFeature.swift @@ -2,7 +2,11 @@ import ComposableArchitecture import SwiftUI public struct ErrorState: Equatable { - public init() {} + public init(error: NSError) { + self.error = error + } + + var error: NSError } public enum ErrorAction: Equatable {} diff --git a/Example/ExampleApp/Sources/ErrorFeature/ErrorView.swift b/Example/ExampleApp/Sources/ErrorFeature/ErrorView.swift index bc86d99c..35d9b847 100644 --- a/Example/ExampleApp/Sources/ErrorFeature/ErrorView.swift +++ b/Example/ExampleApp/Sources/ErrorFeature/ErrorView.swift @@ -7,14 +7,33 @@ public struct ErrorView: View { } let store: Store<ErrorState, ErrorAction> + @Environment(\.dismiss) var dismiss struct ViewState: Equatable { - init(state: ErrorState) {} + let error: NSError + + init(state: ErrorState) { + error = state.error + } } public var body: some View { WithViewStore(store.scope(state: ViewState.init)) { viewStore in - Text("ErrorView") + NavigationView { + Form { + Text("\(viewStore.error)") + } + .navigationTitle("Error") + .toolbar { + ToolbarItem(placement: .cancellationAction) { + Button { + dismiss() + } label: { + Image(systemName: "xmark") + } + } + } + } } } } @@ -23,7 +42,9 @@ public struct ErrorView: View { public struct ErrorView_Previews: PreviewProvider { public static var previews: some View { ErrorView(store: .init( - initialState: .init(), + initialState: .init( + error: NSError(domain: "preview", code: 1234) + ), reducer: .empty, environment: () )) -- GitLab