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

@@ -12,7 +12,7 @@ struct UserDetail: HTML, Sendable {
Float(shouldDisplay: user != nil, resetURL: "/users") {
if let user {
form(
.hx.post(route: .users(.id(user.id))),
.hx.post(route: .user(.shared(.get(id: user.id)))),
.hx.swap(.outerHTML),
.hx.target(.user(.row(id: user.id))),
.custom(name: "hx-on::after-request", value: "toggleContent('float'); window.location.href='/users';")
@@ -36,7 +36,7 @@ struct UserDetail: HTML, Sendable {
) { "Update" }
Button.danger { "Delete" }
.attributes(
.hx.delete(route: .users(.id(user.id))),
.hx.delete(route: .user(.shared(.get(id: user.id)))),
.hx.trigger(.event(.click)),
.hx.swap(.outerHTML),
.hx.target(.user(.row(id: user.id))),

View File

@@ -99,7 +99,7 @@ struct UserForm: HTML, Sendable {
}
}
// TODO: Return a route container.
// TODO: Return a ViewRoute.
var targetURL: String {
switch self {
case .create:

View File

@@ -17,7 +17,7 @@ struct UserTable: HTML {
th(.style("width: 50px;")) {
Button.add()
.attributes(
.hx.get(route: .users(.create)),
.hx.get(route: .user(.form)),
.hx.target(.float),
.hx.swap(.outerHTML)
)
@@ -45,7 +45,7 @@ struct UserTable: HTML {
td { user.email }
td {
Button.detail().attributes(
.hx.get(route: .users(.id(user.id))),
.hx.get(route: .user(.shared(.get(id: user.id)))),
.hx.target(.float),
.hx.swap(.outerHTML),
.hx.pushURL(true)