feat: Updating id key for usage in views, for typesafe keys
This commit is contained in:
@@ -9,13 +9,13 @@ struct UserDetail: HTML, Sendable {
|
||||
let user: User?
|
||||
|
||||
var content: some HTML {
|
||||
Float(shouldDisplay: user != nil, resetURL: "/users") {
|
||||
Float(shouldDisplay: user != nil, resetURL: .user(.index)) {
|
||||
if let user {
|
||||
form(
|
||||
.hx.post(route: .user(.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';")
|
||||
.hx.target(.id(.user(.row(id: user.id)))),
|
||||
.hx.on(.afterRequest, .toggleContent(.float))
|
||||
) {
|
||||
div(.class("row")) {
|
||||
makeLabel(for: "username", value: "Username:")
|
||||
@@ -39,9 +39,12 @@ struct UserDetail: HTML, Sendable {
|
||||
.hx.delete(route: .user(.get(id: user.id))),
|
||||
.hx.trigger(.event(.click)),
|
||||
.hx.swap(.outerHTML),
|
||||
.hx.target(.user(.row(id: user.id))),
|
||||
.hx.target(.id(.user(.row(id: user.id)))),
|
||||
.hx.confirm("Are you sure you want to delete this user?"),
|
||||
.custom(name: "hx-on::after-request", value: "toggleContent('float'); window.location.href='/users';")
|
||||
.hx.on(
|
||||
.afterRequest,
|
||||
.toggleContent(.float), .setWindowLocation(to: .user(.index))
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,14 @@ struct UserForm: HTML, Sendable {
|
||||
.hx.pushURL(context.pushURL),
|
||||
.hx.target(context.target),
|
||||
.hx.swap(.outerHTML),
|
||||
.custom(
|
||||
name: "hx-on::after-request",
|
||||
value: "if(event.detail.successful) this.reset(); toggleContent('float');"
|
||||
.hx.on(
|
||||
.afterRequest,
|
||||
.ifSuccessful(.resetForm, .toggleContent(.float))
|
||||
)
|
||||
// .custom(
|
||||
// name: "hx-on::after-request",
|
||||
// value: "if(event.detail.successful) this.reset(); toggleContent('float');"
|
||||
// )
|
||||
) {
|
||||
if case let .login(next) = context, let next {
|
||||
input(.type(.hidden), .name("next"), .value(next))
|
||||
@@ -46,9 +50,7 @@ struct UserForm: HTML, Sendable {
|
||||
if context.showConfirmPassword {
|
||||
div(.class("row")) {
|
||||
input(
|
||||
.type(.password),
|
||||
.id("confirmPassword"),
|
||||
.name("confirmPassword"),
|
||||
.type(.password), .id("confirmPassword"), .name("confirmPassword"),
|
||||
.placeholder("Confirm Password"),
|
||||
.required
|
||||
)
|
||||
|
||||
@@ -9,7 +9,7 @@ struct UserTable: HTML {
|
||||
let users: [User]
|
||||
|
||||
var content: some HTML {
|
||||
table(.id(.user(.table()))) {
|
||||
table {
|
||||
thead {
|
||||
tr {
|
||||
th { "Username" }
|
||||
@@ -18,13 +18,13 @@ struct UserTable: HTML {
|
||||
Button.add()
|
||||
.attributes(
|
||||
.hx.get(route: .user(.form)),
|
||||
.hx.target(.float),
|
||||
.hx.target(.id(.float)),
|
||||
.hx.swap(.outerHTML)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
tbody(.id(.user(.table(.body)))) {
|
||||
tbody(.id(.user(.table))) {
|
||||
for user in users {
|
||||
Row(user: user)
|
||||
}
|
||||
@@ -46,7 +46,7 @@ struct UserTable: HTML {
|
||||
td {
|
||||
Button.detail().attributes(
|
||||
.hx.get(route: .user(.get(id: user.id))),
|
||||
.hx.target(.float),
|
||||
.hx.target(.id(.float)),
|
||||
.hx.swap(.outerHTML),
|
||||
.hx.pushURL(true)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user