Files
swift-estimated-pressures-core/Sources/PressureEstimationsFeature/EstimationsForm.swift

128 lines
3.0 KiB
Swift

import ComposableArchitecture
import SharedModels
import Styleguide
import SwiftUI
#warning("Use shared settings, don't display filter pressure drop if current flagged measurement pressure drop is not set.")
@Reducer
public struct EstimationForm {
public init() { }
@ObservableState
public struct State: Equatable, Sendable {
public var cfmPerTon: Int
public var coolingCapacity: EquipmentMetadata.CoolingCapacity
public var filterPressureDrop: Double?
public var name: String
public init(
cfmPerTon: Int = 350,
coolingCapacity: EquipmentMetadata.CoolingCapacity = .default,
filterPressureDrop: Double? = nil,
name: String = ""
) {
self.cfmPerTon = cfmPerTon
self.filterPressureDrop = filterPressureDrop
self.coolingCapacity = coolingCapacity
self.name = name
}
public var airflow: Double {
Double(cfmPerTon) * coolingCapacity.rawValue
}
public var isValid: Bool { !name.isEmpty }
}
public enum Action: BindableAction {
case binding(BindingAction<State>)
}
public var body: some Reducer<State, Action> {
BindingReducer()
Reduce<State, Action> { state, action in
switch action {
case .binding:
return .none
}
}
}
}
public struct EstimationFormView: View {
@Bindable public var store: StoreOf<EstimationForm>
public var body: some View {
Form {
Section("Estimation Name") {
HStack {
TextLabel("Name")
.padding(.trailing, 40)
TextField(
"Name",
text: $store.name,
prompt: Text("Required")
)
}
}
Section("Airflow") {
Grid(alignment: .leading, horizontalSpacing: 40) {
GridRow {
HStack {
TextLabel("Capacity")
Spacer()
CoolingCapacityPicker(
selection: $store.coolingCapacity
)
}
.gridCellColumns(2)
}
GridRow {
HStack {
TextLabel("CFM / Ton")
Spacer()
TextField(
"CFM / Ton",
value: $store.cfmPerTon,
format: .number,
prompt: Text("CFM")
)
.frame(width: 100)
.numberPad()
}
.gridCellColumns(2)
}
}
}
Section("Filter Pressure Drop") {
HStack {
TextLabel("Pressure Drop")
Spacer()
TextField(
"Filter Drop",
value: $store.filterPressureDrop,
fractionLength: 2,
prompt: Text("Optional")
)
.frame(width: 100)
.decimalPad()
}
}
}
.labelsHidden()
.textLabelStyle(.boldSecondary)
.textFieldStyle(.roundedBorder)
}
}
#Preview {
EstimationFormView(
store: Store(initialState: EstimationForm.State()) {
EstimationForm()
}
)
}