feat: Refactoring route declarations.

This commit is contained in:
2025-01-19 10:52:15 -05:00
parent d27a19863a
commit 1c8748211c
20 changed files with 954 additions and 644 deletions

View File

@@ -15,14 +15,15 @@ struct VendorDetail: HTML {
} closeButton: {
Button.close(id: "float")
.attributes(
.hx.get("/vendors"),
.hx.get(route: .vendor(.shared(.index(withBranches: true)))),
.hx.pushURL(true),
.hx.target("body"),
.hx.target(.body),
.hx.swap(.outerHTML)
)
}
}
// TODO: What route for here??
var branchForm: some HTML {
form(
.id("branch-form"),
@@ -33,7 +34,7 @@ struct VendorDetail: HTML {
) {
input(
.type(.text), .class("col-9"), .name("name"), .placeholder("Add branch..."), .required,
.hx.post("/vendors/\(vendor.id)/branches"),
.hx.post(route: .vendorBranch(.index(for: vendor.id))),
.hx.trigger(.event(.keyup).changed().delay("800ms")),
.hx.target("#branches"),
.hx.swap(.beforeEnd) // ,
@@ -65,7 +66,7 @@ struct VendorDetail: HTML {
span(.class("label")) { branch.name.capitalized }
button(
.class("btn"),
.hx.delete("/api/v1/vendors/branches/\(branch.id)"),
.hx.delete(route: .vendorBranch(.delete(id: branch.id))),
.hx.target("#branch_\(branch.id)"),
.hx.swap(.outerHTML.transition(true).swap("0.5s"))
) {

View File

@@ -41,7 +41,7 @@ struct VendorForm: HTML {
func makeForm(vendor: Vendor?) -> some HTML {
form(
.id("vendor-form"),
vendor != nil ? .hx.put(targetURL) : .hx.post(targetURL),
vendor != nil ? .hx.put(route: targetURL) : .hx.post(route: targetURL),
.hx.target("#content"),
.hx.swap(.outerHTML)
) {
@@ -53,7 +53,7 @@ struct VendorForm: HTML {
.name("name"),
.value(vendor?.name ?? ""),
.placeholder("Vendor Name"),
vendor != nil ? .hx.put(targetURL) : .hx.post(targetURL),
vendor != nil ? .hx.put(route: targetURL) : .hx.post(route: targetURL),
.hx.trigger(.event(.keyup).changed().delay("500ms")),
.required
)
@@ -61,7 +61,7 @@ struct VendorForm: HTML {
button(
.class("danger"),
.style("font-size: 1.25em; padding: 10px 20px; border-radius: 10px;"),
.hx.delete("/api/v1/vendors/\(vendor.id)"),
.hx.delete(route: .vendor(.delete(id: vendor.id))),
.hx.confirm("Are you sure you want to delete this vendor?"),
.hx.target("#vendor_\(vendor.id)"),
.hx.swap(.outerHTML.transition(true).swap("1s")),
@@ -85,8 +85,8 @@ struct VendorForm: HTML {
return "Update"
}
var targetURL: String {
guard let vendor else { return "/vendors" }
return "/vendors/\(vendor.id)"
var targetURL: SharedModels.ViewRoute {
guard let vendor else { return .vendor(.shared(.index(withBranches: true))) }
return .vendor(.shared(.get(id: vendor.id)))
}
}

View File

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