feat: Moves vendor branch views to their own files, starts to implement snapshot testing for html

This commit is contained in:
2025-01-21 09:51:11 -05:00
parent 40726c8bd7
commit 97b231767e
15 changed files with 231 additions and 71 deletions

View File

@@ -0,0 +1,34 @@
import Elementary
import ElementaryHTMX
import SharedModels
struct VendorBranchForm: HTML {
let vendorID: Vendor.ID
var content: some HTML {
form(
.id(.branch(.form)),
.hx.post(route: .vendorBranch(.index())),
.hx.target(.id(.branch(.list))),
.hx.swap(.beforeEnd),
.hx.on(.afterRequest, .ifSuccessful(.resetForm))
) {
input(.type(.hidden), .name("vendorID"), .value(vendorID.uuidString))
input(
.type(.text), .class("col-9"), .name("name"), .placeholder("Add branch..."), .required,
// .hx.post(route: .vendorBranch(.index())),
.hx.trigger(.event(.keyup).changed().delay("800ms")) // ,
// .hx.target(.id(.branch(.list))),
// .hx.swap(.beforeEnd),
// .custom(name: "hx-on::after-request", value: "if(event.detail.successful) this.reset();")
)
button(
.type(.submit),
.class("btn-secondary"),
.style("float: right; padding: 10px 50px;"),
.hx.target(.id(.branch(.list))),
.hx.swap(.beforeEnd)
) { "+" }
}
}
}

View File

@@ -0,0 +1,46 @@
import Elementary
import ElementaryHTMX
import SharedModels
struct VendorBranchList: HTML {
let vendorID: Vendor.ID
let branches: [VendorBranch]?
var content: some HTML {
if let branches {
ul(.id(.branch(.list))) {
for branch in branches {
Row(branch: branch)
}
}
} else {
div(
.hx.get(route: .vendorBranch(.index(for: vendorID))),
.hx.target(.this),
.hx.indicator(".hx-indicator"),
.hx.trigger(.event(.revealed))
) {
Img.spinner().attributes(.class("hx-indicator"))
}
}
}
struct Row: HTML {
let branch: VendorBranch
var content: some HTML<HTMLTag.li> {
li(.id(.branch(.row(id: branch.id))), .class("branch-row")) {
span(.class("label")) { branch.name.capitalized }
button(
.class("btn"),
.hx.delete(route: .vendorBranch(.delete(id: branch.id))),
.hx.target(.id(.branch(.row(id: branch.id)))),
.hx.swap(.outerHTML.transition(true).swap("0.5s"))
) {
Img.trashCan().attributes(.style("margin-top: 5px;"))
}
}
}
}
}