WIP: Working signup and login forms, along with initial view auth middleware.
This commit is contained in:
80
Sources/ViewController/Views/Project/ProjectsTable.swift
Normal file
80
Sources/ViewController/Views/Project/ProjectsTable.swift
Normal file
@@ -0,0 +1,80 @@
|
||||
import Elementary
|
||||
import ElementaryHTMX
|
||||
import Fluent
|
||||
import ManualDCore
|
||||
import Styleguide
|
||||
import Vapor
|
||||
|
||||
struct ProjectsTable: HTML, Sendable {
|
||||
|
||||
let userID: User.ID
|
||||
let projects: Page<Project>
|
||||
|
||||
init(userID: User.ID, projects: Page<Project>) {
|
||||
self.userID = userID
|
||||
self.projects = projects
|
||||
}
|
||||
|
||||
var body: some HTML {
|
||||
div {
|
||||
Row {
|
||||
h1(.class("text-2xl font-bold")) { "Projects" }
|
||||
div(
|
||||
.class("tooltip tooltip-left"),
|
||||
.data("tip", value: "Add project")
|
||||
) {
|
||||
button(
|
||||
.class("btn btn-primary w-[40px] text-2xl")
|
||||
) {
|
||||
"+"
|
||||
}
|
||||
}
|
||||
}
|
||||
.attributes(.class("pb-6"))
|
||||
|
||||
div(.class("overflow-x-auto rounded-box border")) {
|
||||
table(.class("table table-zebra")) {
|
||||
thead {
|
||||
tr {
|
||||
th { Label("Date") }
|
||||
th { Label("Name") }
|
||||
th { Label("Address") }
|
||||
}
|
||||
}
|
||||
tbody {
|
||||
Rows(projects: projects)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension ProjectsTable {
|
||||
struct Rows: HTML, Sendable {
|
||||
let projects: Page<Project>
|
||||
|
||||
var body: some HTML {
|
||||
for project in projects.items {
|
||||
tr(.id("\(project.id)")) {
|
||||
td { "\(project.createdAt)" }
|
||||
td { "\(project.name)" }
|
||||
td { "\(project.streetAddress)" }
|
||||
}
|
||||
}
|
||||
// Have a row that when revealed fetches the next page,
|
||||
// if there are more pages left.
|
||||
if projects.metadata.pageCount > projects.metadata.page {
|
||||
tr(
|
||||
.hx.get(route: .project(.page(page: projects.metadata.page + 1, limit: 25))),
|
||||
.hx.trigger(.event(.revealed)),
|
||||
.hx.swap(.outerHTML),
|
||||
.hx.target("this"),
|
||||
.hx.indicator("next .htmx-indicator")
|
||||
) {
|
||||
Indicator(size: .lg)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user