diff --git a/Sources/PressureEstimationsFeature/EstimationsForm.swift b/Sources/PressureEstimationsFeature/EstimationsForm.swift index 840a4de..238e7c4 100644 --- a/Sources/PressureEstimationsFeature/EstimationsForm.swift +++ b/Sources/PressureEstimationsFeature/EstimationsForm.swift @@ -35,7 +35,7 @@ public struct EstimationForm { self.coolingCapacity = coolingCapacity self.name = name } - + public var airflow: Double { let cfmTextField = Double(self.cfmTextField ?? 0) switch airflowSelection { diff --git a/Sources/PressureEstimationsFeature/FlaggedMeasurementsList.swift b/Sources/PressureEstimationsFeature/FlaggedMeasurementsList.swift index b154679..fa699b2 100644 --- a/Sources/PressureEstimationsFeature/FlaggedMeasurementsList.swift +++ b/Sources/PressureEstimationsFeature/FlaggedMeasurementsList.swift @@ -51,7 +51,7 @@ public struct FlaggedMeasurementsList: Sendable { @CasePathable public enum ReceiveAction: Sendable { case existingFlaggedMeasurement(EquipmentMeasurement.FlaggedMeasurement) - case estimatedFlaggedMeasurement(name: String, measurement: EquipmentMeasurement.FlaggedMeasurement) + case estimatedFlaggedMeasurement(SharedPressureEstimationState.FlaggedEstimationContainer) } @CasePathable @@ -81,14 +81,8 @@ public struct FlaggedMeasurementsList: Sendable { state.sharedSettings.flaggedEquipmentMeasurement = measurement return .none - case let .estimatedFlaggedMeasurement(name: name, measurement: measurement): - state.flaggedEstimations.append( - .init( - id: uuid(), - name: name, - flaggedMeasurement: measurement - ) - ) + case let .estimatedFlaggedMeasurement(container): + state.flaggedEstimations[id: container.id] = container return .none } } @@ -203,7 +197,11 @@ public struct FlaggedMeasurementsList: Sendable { tons: form.coolingCapacity ) - return .estimatedFlaggedMeasurement(name: form.name, measurement: flaggedMeasurement) + return .estimatedFlaggedMeasurement(.init( + id: form.id ?? uuid(), + estimationState: .init(state: form), + flaggedMeasurement: flaggedMeasurement + )) } } @@ -241,7 +239,7 @@ public struct FlaggedMeasurementListView: View { ) } header: { HStack { - Text(measurement.name) + Text(measurement.displayName) Spacer() Menu { EditButton { send(.editButtonTapped(id: measurement.id)) } @@ -301,7 +299,10 @@ private let flaggedMeasurements = IdentifiedArrayOf(dynamicMember keyPath: WritableKeyPath) -> T { + get { estimationState[keyPath: keyPath] } + set { estimationState[keyPath: keyPath] = newValue } + } + + public subscript(dynamicMember keyPath: KeyPath) -> T { + get { estimationState[keyPath: keyPath] } + } + public struct EstimationState: Equatable, Sendable { public var cfm: CFMContainer public var filterPressureDrop: Double? @@ -67,6 +77,14 @@ public struct SharedPressureEstimationState: Equatable, Sendable { self.name = name } + internal init(state: EstimationForm.State) { + self.init( + cfm: .init(state: state), + filterPressureDrop: state.filterPressureDrop, + name: state.name.isEmpty ? nil : state.name + ) + } + var displayName: String { guard let name else { return "@\(Int(cfm.airflow)) CFM" @@ -78,6 +96,15 @@ public struct SharedPressureEstimationState: Equatable, Sendable { case cfm(Int) case cfmPerTon(Int, EquipmentMetadata.CoolingCapacity) + init(state: EstimationForm.State) { + switch state.airflowSelection { + case .cfmPerTon: + self = .cfmPerTon(state.cfmTextField ?? 0, state.coolingCapacity) + case .cfm: + self = .cfm(state.cfmTextField ?? 0) + } + } + var airflow: Double { switch self { case let .cfm(cfm):