feat: Adds TCA Helpers, some are wip.
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import ComposableArchitecture
|
||||
import DependenciesAdditions
|
||||
import EstimatedPressureDependency
|
||||
import SharedModels
|
||||
import Styleguide
|
||||
import SwiftUI
|
||||
import TCAHelpers
|
||||
|
||||
@Reducer
|
||||
public struct AirflowAtPressureFeature {
|
||||
@@ -34,9 +36,9 @@ public struct AirflowAtPressureFeature {
|
||||
}
|
||||
}
|
||||
|
||||
public enum Action: BindableAction, ViewAction {
|
||||
public enum Action: BindableAction, ReceiveAction, ViewAction {
|
||||
case binding(BindingAction<State>)
|
||||
case receive(ReceiveAction)
|
||||
case receive(TaskResult<ReceiveAction>)
|
||||
case view(View)
|
||||
|
||||
@CasePathable
|
||||
@@ -52,9 +54,9 @@ public struct AirflowAtPressureFeature {
|
||||
case submit
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Dependency(\.estimatedPressuresClient) var estimatedPressuresClient
|
||||
@Dependency(\.logger["\(Self.self)"]) var logger
|
||||
|
||||
public var body: some Reducer<State, Action> {
|
||||
BindingReducer()
|
||||
@@ -63,7 +65,10 @@ public struct AirflowAtPressureFeature {
|
||||
case .binding:
|
||||
return .none
|
||||
|
||||
case let .receive(action):
|
||||
case let .receive(.failure(error)):
|
||||
return .fail(error: error, logger: logger)
|
||||
|
||||
case let .receive(.success(action)):
|
||||
switch action {
|
||||
case let .calculatedAirflow(airflow):
|
||||
state.calculatedAirflow = airflow
|
||||
@@ -86,18 +91,13 @@ public struct AirflowAtPressureFeature {
|
||||
|
||||
case .submit:
|
||||
guard state.isValid else { return .none }
|
||||
return .run { [state] send in
|
||||
await send(
|
||||
.receive(.calculatedAirflow(
|
||||
try? await estimatedPressuresClient.estimatedAirflow(.init(
|
||||
existingAirflow: state.existingAirflow ?? 0,
|
||||
existingPressure: state.existingPressure ?? 0,
|
||||
targetPressure: state.targetPressure ?? 0
|
||||
))
|
||||
))
|
||||
)
|
||||
return .receive(\.calculatedAirflow) { [state] in
|
||||
try await estimatedPressuresClient.estimatedAirflow(.init(
|
||||
existingAirflow: state.existingAirflow ?? 0,
|
||||
existingPressure: state.existingPressure ?? 0,
|
||||
targetPressure: state.targetPressure ?? 0
|
||||
))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user