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