feat: Cleans up routes.

This commit is contained in:
2025-01-19 13:33:01 -05:00
parent 1c8748211c
commit b23dc6bf07
32 changed files with 958 additions and 1786 deletions

View File

@@ -2,6 +2,7 @@ import Elementary
import ElementaryHTMX
import SharedModels
// TODO: Lazy Load branches when view appears.
struct VendorDetail: HTML {
let vendor: Vendor
@@ -15,7 +16,7 @@ struct VendorDetail: HTML {
} closeButton: {
Button.close(id: "float")
.attributes(
.hx.get(route: .vendor(.shared(.index(withBranches: true)))),
.hx.get(route: .vendor(.index)),
.hx.pushURL(true),
.hx.target(.body),
.hx.swap(.outerHTML)
@@ -25,6 +26,7 @@ struct VendorDetail: HTML {
// TODO: What route for here??
var branchForm: some HTML {
// TODO: Add hidden input field with vendor id.
form(
.id("branch-form"),
.hx.post("/vendors/\(vendor.id)/branches"),
@@ -34,7 +36,8 @@ struct VendorDetail: HTML {
) {
input(
.type(.text), .class("col-9"), .name("name"), .placeholder("Add branch..."), .required,
.hx.post(route: .vendorBranch(.index(for: vendor.id))),
// FIX: route
// .hx.post(route: .vendorBranch(.index(for: vendor.id))),
.hx.trigger(.event(.keyup).changed().delay("800ms")),
.hx.target("#branches"),
.hx.swap(.beforeEnd) // ,

View File

@@ -86,7 +86,7 @@ struct VendorForm: HTML {
}
var targetURL: SharedModels.ViewRoute {
guard let vendor else { return .vendor(.shared(.index(withBranches: true))) }
return .vendor(.shared(.get(id: vendor.id)))
guard let vendor else { return .vendor(.index) }
return .vendor(.get(id: vendor.id))
}
}

View File

@@ -41,7 +41,7 @@ struct VendorTable: HTML {
Button.detail()
.attributes(
.style("padding-left: 15px;"),
.hx.get(route: .vendor(.shared(.get(id: vendor.id)))),
.hx.get(route: .vendor(.get(id: vendor.id))),
.hx.target("#float"),
.hx.pushURL(true),
.hx.swap(.outerHTML)