fix: Fixes calculate at feature for new info view, updates static pressure test
This commit is contained in:
@@ -9,18 +9,25 @@ import TCAExtras
|
|||||||
@Reducer
|
@Reducer
|
||||||
public struct CalculateAtFeature {
|
public struct CalculateAtFeature {
|
||||||
|
|
||||||
|
@Reducer(state: .equatable)
|
||||||
|
public enum Destination {
|
||||||
|
case infoView(InfoViewFeature)
|
||||||
|
}
|
||||||
|
|
||||||
@ObservableState
|
@ObservableState
|
||||||
@dynamicMemberLookup
|
@dynamicMemberLookup
|
||||||
public struct State: Equatable {
|
public struct State: Equatable {
|
||||||
|
@Presents public var destination: Destination.State?
|
||||||
public var focus: Focus? = nil
|
public var focus: Focus? = nil
|
||||||
public var isPresentingInfoView: Bool = false
|
|
||||||
public var values: ValueContainer
|
public var values: ValueContainer
|
||||||
public var calculationType: CalculationType
|
public var calculationType: CalculationType
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
|
destination: Destination.State? = nil,
|
||||||
values: ValueContainer = .init(),
|
values: ValueContainer = .init(),
|
||||||
calculationType: CalculationType = .airflowAtNewPressure
|
calculationType: CalculationType = .airflowAtNewPressure
|
||||||
) {
|
) {
|
||||||
|
self.destination = destination
|
||||||
self.values = values
|
self.values = values
|
||||||
self.calculationType = calculationType
|
self.calculationType = calculationType
|
||||||
}
|
}
|
||||||
@@ -133,6 +140,7 @@ public struct CalculateAtFeature {
|
|||||||
|
|
||||||
public enum Action: BindableAction, ReceiveAction, ViewAction {
|
public enum Action: BindableAction, ReceiveAction, ViewAction {
|
||||||
case binding(BindingAction<State>)
|
case binding(BindingAction<State>)
|
||||||
|
case destination(PresentationAction<Destination.Action>)
|
||||||
case receive(TaskResult<ReceiveAction>)
|
case receive(TaskResult<ReceiveAction>)
|
||||||
case view(View)
|
case view(View)
|
||||||
|
|
||||||
@@ -143,7 +151,6 @@ public struct CalculateAtFeature {
|
|||||||
|
|
||||||
@CasePathable
|
@CasePathable
|
||||||
public enum View {
|
public enum View {
|
||||||
case dismissInfoViewButtonTapped
|
|
||||||
case infoButtonTapped
|
case infoButtonTapped
|
||||||
case onAppear
|
case onAppear
|
||||||
case resetButtonTapped
|
case resetButtonTapped
|
||||||
@@ -166,6 +173,9 @@ public struct CalculateAtFeature {
|
|||||||
case .binding:
|
case .binding:
|
||||||
return .none
|
return .none
|
||||||
|
|
||||||
|
case .destination:
|
||||||
|
return .none
|
||||||
|
|
||||||
case let .receive(.success(.calculatedValue(calculatedAirflow))):
|
case let .receive(.success(.calculatedValue(calculatedAirflow))):
|
||||||
state.calculatedValue = calculatedAirflow?.positiveValue
|
state.calculatedValue = calculatedAirflow?.positiveValue
|
||||||
return .none
|
return .none
|
||||||
@@ -175,12 +185,9 @@ public struct CalculateAtFeature {
|
|||||||
|
|
||||||
case let .view(action):
|
case let .view(action):
|
||||||
switch action {
|
switch action {
|
||||||
case .dismissInfoViewButtonTapped:
|
|
||||||
state.isPresentingInfoView = false
|
|
||||||
return .none
|
|
||||||
|
|
||||||
case .infoButtonTapped:
|
case .infoButtonTapped:
|
||||||
state.isPresentingInfoView = true
|
state.destination = .infoView(.init(calculationType: state.calculationType))
|
||||||
return .none
|
return .none
|
||||||
|
|
||||||
case .onAppear:
|
case .onAppear:
|
||||||
@@ -200,6 +207,7 @@ public struct CalculateAtFeature {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onFailure(.log(logger: logger))
|
.onFailure(.log(logger: logger))
|
||||||
|
.ifLet(\.$destination, action: \.destination)
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculate(state: State) -> Effect<Action> {
|
func calculate(state: State) -> Effect<Action> {
|
||||||
@@ -230,7 +238,7 @@ public struct CalculateAtView: View {
|
|||||||
|
|
||||||
@FocusState private var focus: CalculateAtFeature.State.Focus?
|
@FocusState private var focus: CalculateAtFeature.State.Focus?
|
||||||
|
|
||||||
@Perception.Bindable
|
@Bindable
|
||||||
public var store: StoreOf<CalculateAtFeature>
|
public var store: StoreOf<CalculateAtFeature>
|
||||||
|
|
||||||
let allowChangingCalculationType: Bool
|
let allowChangingCalculationType: Bool
|
||||||
@@ -341,24 +349,23 @@ public struct CalculateAtView: View {
|
|||||||
}
|
}
|
||||||
.bind($focus, to: $store.focus)
|
.bind($focus, to: $store.focus)
|
||||||
.onAppear { focus = .existingAirflow }
|
.onAppear { focus = .existingAirflow }
|
||||||
.sheet(isPresented: $store.isPresentingInfoView) {
|
.sheet(
|
||||||
|
item: $store.scope(state: \.destination?.infoView, action: \.destination.infoView)
|
||||||
|
) { store in
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
InfoView(calculationType: store.calculationType)
|
InfoView(store: store)
|
||||||
.toolbar {
|
|
||||||
Button("Done") { send(.dismissInfoViewButtonTapped) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate extension InfoView {
|
fileprivate extension InfoViewFeature.State {
|
||||||
|
|
||||||
init(calculationType: CalculateAtFeature.State.CalculationType) {
|
init(calculationType: CalculateAtFeature.State.CalculationType) {
|
||||||
switch calculationType {
|
switch calculationType {
|
||||||
case .airflowAtNewPressure:
|
case .airflowAtNewPressure:
|
||||||
self.init(
|
self.init(
|
||||||
heading: """
|
title: """
|
||||||
Calculate the airflow at the target pressure from the existing airflow and existing pressure.
|
Calculate the airflow at the target pressure from the existing airflow and existing pressure.
|
||||||
""",
|
""",
|
||||||
body: """
|
body: """
|
||||||
@@ -367,7 +374,7 @@ fileprivate extension InfoView {
|
|||||||
)
|
)
|
||||||
case .pressureAtNewAirflow:
|
case .pressureAtNewAirflow:
|
||||||
self.init(
|
self.init(
|
||||||
heading: """
|
title: """
|
||||||
Calculate the pressure at the target airflow from the existing airflow and existing pressure.
|
Calculate the pressure at the target airflow from the existing airflow and existing pressure.
|
||||||
""",
|
""",
|
||||||
body: """
|
body: """
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import Foundation
|
|||||||
|
|
||||||
#warning("Make values non-optional")
|
#warning("Make values non-optional")
|
||||||
#warning("Need to make air handler external static handle large filter pressure drops.")
|
#warning("Need to make air handler external static handle large filter pressure drops.")
|
||||||
|
#warning("Add an exterenal static pressure strategy for if the filter is built-in or external")
|
||||||
public enum EquipmentMeasurement: Equatable {
|
public enum EquipmentMeasurement: Equatable {
|
||||||
|
|
||||||
case airHandler(AirHandler)
|
case airHandler(AirHandler)
|
||||||
@@ -59,8 +60,9 @@ public enum EquipmentMeasurement: Equatable {
|
|||||||
public var externalStaticPressure: Double {
|
public var externalStaticPressure: Double {
|
||||||
var postFilterAdder = 0.0
|
var postFilterAdder = 0.0
|
||||||
if let postFilterPressure = $postFilterPressure.positiveValue,
|
if let postFilterPressure = $postFilterPressure.positiveValue,
|
||||||
postFilterPressure > 0.1 {
|
postFilterPressure > 0.1
|
||||||
postFilterAdder = postFilterAdder - 0.1
|
{
|
||||||
|
postFilterAdder = postFilterPressure - 0.1
|
||||||
}
|
}
|
||||||
return ($returnPlenumPressure.positiveValue ?? 0)
|
return ($returnPlenumPressure.positiveValue ?? 0)
|
||||||
+ postFilterAdder
|
+ postFilterAdder
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ final class PositiveNumericTests: XCTestCase {
|
|||||||
)
|
)
|
||||||
|
|
||||||
sut = envelope.externalStaticPressure
|
sut = envelope.externalStaticPressure
|
||||||
XCTAssertEqual(round(sut * 10) / 10, 0.5)
|
XCTAssertEqual(round(sut * 10) / 10, 0.7)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user