Files
swift-hvac-toolbox/Sources/ViewController/Views/FeetOfHead.swift
Michael Housh a44cc6975d
Some checks failed
CI / ubuntu (push) Failing after 7m22s
CI / macOS (debug, 16.2) (push) Has been cancelled
CI / macOS (release, 16.2) (push) Has been cancelled
feat: Adds psi to feet of head conversion.
2025-03-07 16:27:03 -05:00

71 lines
1.9 KiB
Swift

import Elementary
import ElementaryHTMX
import PsychrometricClient
import Routes
import Styleguide
struct FeetOfHeadForm: HTML, Sendable {
let response: FeetOfHead.Response?
typealias Key = FeetOfHead.Request.FieldKey
var content: some HTML {
FormHeader(label: "Feet of Head", svg: .footprints)
form(
.hx.post(route: .feetOfHead(.index)),
.hx.target("#result")
) {
div(.class("space-y-6")) {
div(.class("grid grid-cols-2 gap-4")) {
LabeledContent(label: "Pressure (psi)") {
Input(id: Key.pressure, placeholder: "Pressure")
.attributes(.type(.number), .min("0.1"), .step("0.1"), .autofocus, .required)
}
LabeledContent(label: "Water Temperature (\(String.fahrenheit))") {
Input(id: Key.waterTemperature, placeholder: "Temperature (optional)")
.attributes(.type(.number), .min("32.0"), .step("0.1"))
}
}
Note {
"""
If water temperature is not supplied, then calculations will be based on 60\(String.fahrenheit) water.
"""
}
div {
SubmitButton(label: "Feet of Head")
}
}
}
div(.id("result")) {
if let response {
FeetOfHeadResponse(response: response)
}
}
}
}
struct FeetOfHeadResponse: HTML, Sendable {
let response: FeetOfHead.Response
var content: some HTML {
ResultContainer(reset: .feetOfHead(.index)) {
ResultBox {
div(.class("grid grid-cols-2")) {
VerticalGroup(label: "Feet of Head", value: "\(double: response.feetOfHead)", valueLabel: "ft.")
VerticalGroup(
label: "Water Density",
value: "\(double: response.density.value)",
valueLabel: response.density.units.rawValue
)
}
}
WarningBox(warnings: response.warnings)
}
}
}