Skip to content

Commit e8c3de6

Browse files
committed
wip
1 parent 594eff1 commit e8c3de6

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

Examples/TicTacToe/tic-tac-toe/Sources/TwoFactorCore/TwoFactorCore.swift

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Dispatch
55

66
public struct TwoFactor: ReducerProtocol, Sendable {
77
public struct State: Equatable {
8-
@PresentationState public var alert: AlertState<Never>?
8+
@PresentationState public var alert: AlertState<Action.Alert>?
99
@BindingState public var code = ""
1010
public var isFormValid = false
1111
public var isTwoFactorRequestInFlight = false
@@ -16,29 +16,44 @@ public struct TwoFactor: ReducerProtocol, Sendable {
1616
}
1717
}
1818

19-
public enum Action: BindableAction, Equatable {
20-
case alert(PresentationAction<Never>)
21-
case binding(BindingAction<State>)
22-
case submitButtonTapped
19+
public enum Action: Equatable {
20+
case alert(PresentationAction<Alert>)
2321
case twoFactorResponse(TaskResult<AuthenticationResponse>)
22+
case view(View)
23+
24+
public enum Alert: Equatable {}
25+
26+
public enum View: BindableAction, Equatable {
27+
case binding(BindingAction<State>)
28+
case submitButtonTapped
29+
}
2430
}
2531

2632
@Dependency(\.authenticationClient) var authenticationClient
2733

2834
public init() {}
2935

3036
public var body: some ReducerProtocol<State, Action> {
31-
BindingReducer()
37+
BindingReducer(action: /Action.view)
3238
Reduce { state, action in
3339
switch action {
3440
case .alert:
3541
return .none
3642

37-
case .binding:
43+
case let .twoFactorResponse(.failure(error)):
44+
state.alert = AlertState { TextState(error.localizedDescription) }
45+
state.isTwoFactorRequestInFlight = false
46+
return .none
47+
48+
case .twoFactorResponse(.success):
49+
state.isTwoFactorRequestInFlight = false
50+
return .none
51+
52+
case .view(.binding):
3853
state.isFormValid = state.code.count >= 4
3954
return .none
4055

41-
case .submitButtonTapped:
56+
case .view(.submitButtonTapped):
4257
state.isTwoFactorRequestInFlight = true
4358
return .task { [code = state.code, token = state.token] in
4459
.twoFactorResponse(
@@ -47,15 +62,6 @@ public struct TwoFactor: ReducerProtocol, Sendable {
4762
}
4863
)
4964
}
50-
51-
case let .twoFactorResponse(.failure(error)):
52-
state.alert = AlertState { TextState(error.localizedDescription) }
53-
state.isTwoFactorRequestInFlight = false
54-
return .none
55-
56-
case .twoFactorResponse(.success):
57-
state.isTwoFactorRequestInFlight = false
58-
return .none
5965
}
6066
}
6167
.ifLet(\.$alert, action: /Action.alert)

Examples/TicTacToe/tic-tac-toe/Sources/TwoFactorSwiftUI/TwoFactorView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public struct TwoFactorView: View {
77
let store: StoreOf<TwoFactor>
88

99
struct ViewState: Equatable {
10-
var alert: AlertState<Never>?
10+
var alert: AlertState<TwoFactor.Action.Alert>?
1111
@BindingViewState var code: String
1212
var isActivityIndicatorVisible: Bool
1313
var isFormDisabled: Bool
@@ -27,7 +27,7 @@ public struct TwoFactorView: View {
2727
}
2828

2929
public var body: some View {
30-
WithViewStore(self.store, observe: ViewState.init) { viewStore in
30+
WithViewStore(self.store, observe: ViewState.init, send: { .view($0) }) { viewStore in
3131
Form {
3232
Text(#"To confirm the second factor enter "1234" into the form."#)
3333

Examples/TicTacToe/tic-tac-toe/Sources/TwoFactorUIKit/TwoFactorViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public final class TwoFactorViewController: UIViewController {
99
private var cancellables: Set<AnyCancellable> = []
1010

1111
struct ViewState: Equatable {
12-
let alert: AlertState<Never>?
12+
let alert: AlertState<TwoFactor.Action.Alert>?
1313
let code: String?
1414
let isActivityIndicatorHidden: Bool
1515
let isLoginButtonEnabled: Bool
@@ -124,9 +124,9 @@ extension TwoFactor.Action {
124124
case .alertDismissed:
125125
self = .alert(.dismiss)
126126
case let .codeChanged(code):
127-
self = .set(\.$code, code ?? "")
127+
self = .view(.set(\.$code, code ?? ""))
128128
case .loginButtonTapped:
129-
self = .submitButtonTapped
129+
self = .view(.submitButtonTapped)
130130
}
131131
}
132132
}

0 commit comments

Comments
 (0)