From d253a470ca1a2450b32b1a2898804a537fe5c2a4 Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Thu, 6 Jun 2024 18:39:33 -0400 Subject: [PATCH] fix: Fixes calculate at feature for new info view, updates static pressure test --- .../CalculateAtFeature/CalculateAtView.swift | 39 +++++++++++-------- .../SharedModels/EquipmentMeasurement.swift | 6 ++- .../EstimatedPressureTests.swift | 2 +- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/Sources/CalculateAtFeature/CalculateAtView.swift b/Sources/CalculateAtFeature/CalculateAtView.swift index 2662cec..1497c33 100644 --- a/Sources/CalculateAtFeature/CalculateAtView.swift +++ b/Sources/CalculateAtFeature/CalculateAtView.swift @@ -8,19 +8,26 @@ 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) + case destination(PresentationAction) case receive(TaskResult) case view(View) @@ -143,7 +151,6 @@ public struct CalculateAtFeature { @CasePathable public enum View { - case dismissInfoViewButtonTapped case infoButtonTapped case onAppear case resetButtonTapped @@ -165,6 +172,9 @@ public struct CalculateAtFeature { case .binding: return .none + + case .destination: + return .none case let .receive(.success(.calculatedValue(calculatedAirflow))): state.calculatedValue = calculatedAirflow?.positiveValue @@ -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 { @@ -230,7 +238,7 @@ public struct CalculateAtView: View { @FocusState private var focus: CalculateAtFeature.State.Focus? - @Perception.Bindable + @Bindable public var store: StoreOf 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: """ diff --git a/Sources/SharedModels/EquipmentMeasurement.swift b/Sources/SharedModels/EquipmentMeasurement.swift index d435def..6345bfc 100644 --- a/Sources/SharedModels/EquipmentMeasurement.swift +++ b/Sources/SharedModels/EquipmentMeasurement.swift @@ -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 diff --git a/Tests/EstimatedPressureTests/EstimatedPressureTests.swift b/Tests/EstimatedPressureTests/EstimatedPressureTests.swift index 9c76c9b..ce8b1bd 100644 --- a/Tests/EstimatedPressureTests/EstimatedPressureTests.swift +++ b/Tests/EstimatedPressureTests/EstimatedPressureTests.swift @@ -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) }