feat: Updates form routes and database routes to use id's in the url path.

This commit is contained in:
2026-01-09 09:25:37 -05:00
parent 9356ccb1c9
commit 30fddb9dce
27 changed files with 677 additions and 322 deletions

View File

@@ -18,14 +18,19 @@ struct ProjectForm: HTML, Sendable {
self.project = project
}
var route: String {
SiteRoute.View.router.path(for: .project(.index))
.appendingPath(project?.id)
}
var body: some HTML {
ModalForm(id: Self.id, dismiss: dismiss) {
h1(.class("text-3xl font-bold pb-6 ps-2")) { "Project" }
form(
.class("space-y-4 p-4"),
project == nil
? .hx.post(route: .project(.index))
: .hx.patch(route: .project(.index)),
? .hx.post(route)
: .hx.patch(route),
.hx.target("body"),
.hx.swap(.outerHTML)
) {

View File

@@ -5,8 +5,6 @@ import ElementaryHTMX
import ManualDCore
import Styleguide
// TODO: Make view async and load based on the active tab.
struct ProjectView: HTML, Sendable {
@Dependency(\.database) var database
@@ -58,7 +56,10 @@ struct ProjectView: HTML, Sendable {
case .frictionRate:
try await FrictionRateView(
equipmentInfo: database.equipment.fetch(projectID),
componentLosses: database.componentLoss.fetch(projectID), projectID: projectID)
componentLosses: database.componentLoss.fetch(projectID),
equivalentLengths: database.effectiveLength.fetchMax(projectID),
projectID: projectID
)
case .ductSizing:
div { "FIX ME!" }
@@ -75,135 +76,135 @@ struct ProjectView: HTML, Sendable {
}
}
// TODO: Update to use DaisyUI drawer.
struct Sidebar: HTML {
extension ProjectView {
let active: SiteRoute.View.ProjectRoute.DetailRoute.Tab
let projectID: Project.ID
let completedSteps: Project.CompletedSteps
struct Sidebar: HTML {
var body: some HTML {
let active: SiteRoute.View.ProjectRoute.DetailRoute.Tab
let projectID: Project.ID
let completedSteps: Project.CompletedSteps
div(.class("drawer-side is-drawer-close:overflow-visible")) {
label(
.for("my-drawer-1"), .init(name: "aria-label", value: "close sidebar"),
.class("drawer-overlay")
) {}
var body: some HTML {
div(
.class(
"""
flex min-h-full flex-col items-start bg-base-200
is-drawer-close:min-w-[80px] is-drawer-open:min-w-[340px]
"""
)
) {
div(.class("drawer-side is-drawer-close:overflow-visible")) {
label(
.for("my-drawer-1"), .init(name: "aria-label", value: "close sidebar"),
.class("drawer-overlay")
) {}
ul(.class("w-full")) {
div(
.class(
"""
flex min-h-full flex-col items-start bg-base-200
is-drawer-close:min-w-[80px] is-drawer-open:min-w-[340px]
"""
)
) {
li(.class("w-full")) {
div(
.class("w-full is-drawer-close:tooltip is-drawer-close:tooltip-right"),
.data("tip", value: "All Projects")
) {
a(
.class(
"""
flex btn btn-secondary btn-square btn-block
is-drawer-close:items-center
"""
),
.hx.get(route: .project(.index)),
.hx.target("body"),
.hx.pushURL(true),
.hx.swap(.outerHTML),
ul(.class("w-full")) {
li(.class("w-full")) {
div(
.class("w-full is-drawer-close:tooltip is-drawer-close:tooltip-right"),
.data("tip", value: "All Projects")
) {
div(.class("flex is-drawer-open:space-x-4")) {
span { "<" }
span(.class("is-drawer-close:hidden")) { "All Projects" }
a(
.class(
"""
flex btn btn-secondary btn-square btn-block
is-drawer-close:items-center
"""
),
.hx.get(route: .project(.index)),
.hx.target("body"),
.hx.pushURL(true),
.hx.swap(.outerHTML),
) {
div(.class("flex is-drawer-open:space-x-4")) {
span { "<" }
span(.class("is-drawer-close:hidden")) { "All Projects" }
}
}
}
}
}
// FIX: Move to user profile / settings page.
li(.class("w-full is-drawer-close:hidden")) {
div(.class("flex justify-between p-4")) {
Label("Theme")
input(.type(.checkbox), .class("toggle theme-controller"), .value("light"))
// FIX: Move to user profile / settings page.
li(.class("w-full is-drawer-close:hidden")) {
div(.class("flex justify-between p-4")) {
Label("Theme")
input(.type(.checkbox), .class("toggle theme-controller"), .value("light"))
}
}
}
li(.class("w-full")) {
row(
title: "Project",
icon: .mapPin,
route: .project(.detail(projectID, .index(tab: .project))),
isComplete: true
)
.attributes(.class("btn-active"), when: active == .project)
}
li(.class("w-full")) {
row(
title: "Project",
icon: .mapPin,
route: .project(.detail(projectID, .index(tab: .project))),
isComplete: true
)
.attributes(.class("btn-active"), when: active == .project)
}
li(.class("w-full")) {
row(
title: "Rooms",
icon: .doorClosed,
route: .project(.detail(projectID, .rooms(.index))),
isComplete: completedSteps.rooms
)
.attributes(.class("btn-active"), when: active == .rooms)
}
li(.class("w-full")) {
row(
title: "Rooms",
icon: .doorClosed,
route: .project(.detail(projectID, .rooms(.index))),
isComplete: completedSteps.rooms
)
.attributes(.class("btn-active"), when: active == .rooms)
}
li(.class("w-full")) {
row(
title: "Equivalent Lengths",
icon: .rulerDimensionLine,
route: .project(.detail(projectID, .equivalentLength(.index))),
isComplete: completedSteps.equivalentLength
)
.attributes(.class("btn-active"), when: active == .equivalentLength)
li(.class("w-full")) {
row(
title: "Equivalent Lengths",
icon: .rulerDimensionLine,
route: .project(.detail(projectID, .equivalentLength(.index))),
isComplete: completedSteps.equivalentLength
)
.attributes(.class("btn-active"), when: active == .equivalentLength)
}
li(.class("w-full")) {
row(
title: "Friction Rate",
icon: .squareFunction,
route: .project(.detail(projectID, .frictionRate(.index))),
isComplete: completedSteps.frictionRate
)
.attributes(.class("btn-active"), when: active == .frictionRate)
}
li(.class("w-full")) {
row(
title: "Friction Rate",
icon: .squareFunction,
route: .project(.detail(projectID, .frictionRate(.index))),
isComplete: completedSteps.frictionRate
)
.attributes(.class("btn-active"), when: active == .frictionRate)
}
li(.class("w-full")) {
row(
title: "Duct Sizes", icon: .wind, href: "#", isComplete: false, hideIsComplete: true
)
.attributes(.class("btn-active"), when: active == .ductSizing)
}
li(.class("w-full")) {
row(
title: "Duct Sizes", icon: .wind, href: "#", isComplete: false, hideIsComplete: true
)
.attributes(.class("btn-active"), when: active == .ductSizing)
}
}
}
}
}
}
// TODO: Use SiteRoute.View routes as href.
private func row(
title: String,
icon: SVG.Key,
href: String,
isComplete: Bool,
hideIsComplete: Bool = false
) -> some HTML<HTMLTag.div> {
div(
.class(
"w-full is-drawer-close:tooltip is-drawer-close:tooltip-right"
),
.data("tip", value: title)
) {
// TODO: Use SiteRoute.View routes as href.
private func row(
title: String,
icon: SVG.Key,
href: String,
isComplete: Bool,
hideIsComplete: Bool = false
) -> some HTML<HTMLTag.a> {
a(
.class(
"flex btn btn-soft btn-square btn-block is-drawer-open:justify-between is-drawer-close:items-center"
"""
flex w-full btn btn-soft btn-square btn-block
is-drawer-open:justify-between is-drawer-close:items-center
is-drawer-close:tooltip is-drawer-close:tooltip-right
"""
),
.href(href)
.href(href),
.data("tip", value: title)
) {
div(.class("flex is-drawer-open:space-x-4")) {
SVG(icon)
@@ -226,18 +227,18 @@ struct Sidebar: HTML {
.attributes(.class("is-drawer-close:text-green-400"), when: isComplete)
.attributes(.class("is-drawer-close:text-error"), when: !isComplete && !hideIsComplete)
}
}
private func row(
title: String,
icon: SVG.Key,
route: SiteRoute.View,
isComplete: Bool,
hideIsComplete: Bool = false
) -> some HTML<HTMLTag.div> {
row(
title: title, icon: icon, href: SiteRoute.View.router.path(for: route),
isComplete: isComplete, hideIsComplete: hideIsComplete
)
private func row(
title: String,
icon: SVG.Key,
route: SiteRoute.View,
isComplete: Bool,
hideIsComplete: Bool = false
) -> some HTML<HTMLTag.a> {
row(
title: title, icon: icon, href: SiteRoute.View.router.path(for: route),
isComplete: isComplete, hideIsComplete: hideIsComplete
)
}
}
}