feat: Working on pressure estimations feature, integrating all views and shared settings
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import ComposableArchitecture
|
||||
import DependenciesAdditions
|
||||
import SharedModels
|
||||
import Styleguide
|
||||
import SwiftUI
|
||||
import TCAExtras
|
||||
|
||||
#warning("Fix shared settings.")
|
||||
@Reducer
|
||||
public struct PressureEstimationsFeature {
|
||||
|
||||
@@ -17,17 +19,16 @@ public struct PressureEstimationsFeature {
|
||||
@ObservableState
|
||||
public struct State: Equatable {
|
||||
@Presents public var destination: Destination.State?
|
||||
@Shared(.sharedPressureEstimationSettings) var sharedSettings = SharedPressureEstimationSettings()
|
||||
public var equipmentSettings: EquipmentSettingsForm.State
|
||||
public var equipmentMeasurements: EquipmentMeasurementForm.State?
|
||||
|
||||
|
||||
public init(
|
||||
destination: Destination.State? = nil,
|
||||
equipmentSettings: EquipmentSettingsForm.State = .init(),
|
||||
equipmentMeasurements: EquipmentMeasurementForm.State? = nil
|
||||
sharedSettings: SharedPressureEstimationSettings = .init()
|
||||
) {
|
||||
self.destination = destination
|
||||
self.equipmentSettings = equipmentSettings
|
||||
self.equipmentMeasurements = equipmentMeasurements
|
||||
self._sharedSettings = Shared(sharedSettings)
|
||||
self._equipmentSettings = .init(sharedSettings: self._sharedSettings)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +42,9 @@ public struct PressureEstimationsFeature {
|
||||
case nextButtonTapped
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Dependency(\.logger["\(Self.self)"]) var logger
|
||||
|
||||
public var body: some Reducer<State, Action> {
|
||||
Scope(state: \.equipmentSettings, action: \.equipmentSettings) {
|
||||
EquipmentSettingsForm()
|
||||
@@ -57,13 +60,42 @@ public struct PressureEstimationsFeature {
|
||||
case let .view(action):
|
||||
switch action {
|
||||
case .nextButtonTapped:
|
||||
return .none
|
||||
return handleNextButtonTapped(&state)
|
||||
}
|
||||
}
|
||||
}
|
||||
.ifLet(\.$destination, action: \.destination)
|
||||
}
|
||||
|
||||
|
||||
private func handleNextButtonTapped(_ state: inout State) -> Effect<Action> {
|
||||
guard state.destination == nil else {
|
||||
return .fail(
|
||||
"""
|
||||
Received next button tapped action on equipment settings form, but the destination is not nil.
|
||||
|
||||
This is considered an application logic error.
|
||||
""",
|
||||
logger: logger
|
||||
)
|
||||
}
|
||||
guard state.equipmentSettings.isValid else {
|
||||
return .fail(
|
||||
"""
|
||||
Received next button tapped action on equipment settings form, but the form is invalid.
|
||||
|
||||
This is considered an application logic error.
|
||||
""",
|
||||
logger: logger
|
||||
)
|
||||
}
|
||||
state.destination = .equipmentMeasurements(.init(
|
||||
allowEquipmentTypeSelection: false,
|
||||
sharedSettings: state.$sharedSettings,
|
||||
equipmentType: state.equipmentSettings.equipmentType
|
||||
))
|
||||
return .none
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ViewAction(for: PressureEstimationsFeature.self)
|
||||
@@ -79,5 +111,30 @@ public struct PressureEstimationsView: View {
|
||||
EquipmentSettingsFormView(
|
||||
store: store.scope(state: \.equipmentSettings, action: \.equipmentSettings)
|
||||
)
|
||||
.navigationTitle("Equipment Settings")
|
||||
.toolbar {
|
||||
NextButton { send(.nextButtonTapped) }
|
||||
.nextButtonStyle(.toolbar)
|
||||
.disabled(!store.equipmentSettings.isValid)
|
||||
}
|
||||
.navigationDestination(
|
||||
item: $store.scope(
|
||||
state: \.destination?.equipmentMeasurements,
|
||||
action: \.destination.equipmentMeasurements
|
||||
)
|
||||
) { measurementStore in
|
||||
EquipmentMeasurementFormView(store: measurementStore)
|
||||
.navigationTitle("Existing Measurements")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
NavigationStack {
|
||||
PressureEstimationsView(
|
||||
store: Store(initialState: PressureEstimationsFeature.State()) {
|
||||
PressureEstimationsFeature()._printChanges()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user