feat: Working on route and id helpers for views.
This commit is contained in:
@@ -20,7 +20,7 @@ struct EmployeeForm: HTML {
|
||||
Float(shouldDisplay: shouldShow, resetURL: "/employees") {
|
||||
form(
|
||||
employee == nil ? .hx.post(targetURL) : .hx.put(targetURL),
|
||||
employee == nil ? .hx.target("#employee-table") : .hx.target("#employee_\(employee!.id)"),
|
||||
.hx.target(target),
|
||||
employee == nil
|
||||
? .hx.swap(.beforeEnd.transition(true).swap("0.5s"))
|
||||
: .hx.swap(.outerHTML.transition(true).swap("0.5s")),
|
||||
@@ -62,6 +62,13 @@ struct EmployeeForm: HTML {
|
||||
}
|
||||
}
|
||||
|
||||
private var target: HXTarget {
|
||||
guard let employee else {
|
||||
return .employee(.table)
|
||||
}
|
||||
return .employee(.row(id: employee.id))
|
||||
}
|
||||
|
||||
private var buttonLabel: String {
|
||||
guard employee != nil else { return "Create" }
|
||||
return "Update"
|
||||
|
||||
Reference in New Issue
Block a user