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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,9 @@ struct LoginForm: HTML, Sendable {
|
||||
.id("loginForm"),
|
||||
.class("flex items-center justify-center")
|
||||
) {
|
||||
form {
|
||||
form(
|
||||
.method(.post)
|
||||
) {
|
||||
fieldset(.class("fieldset bg-base-200 border-base-300 rounded-box w-xl border p-4")) {
|
||||
legend(.class("fieldset-legend")) { style.title }
|
||||
|
||||
@@ -24,6 +26,7 @@ struct LoginForm: HTML, Sendable {
|
||||
SVG(.user)
|
||||
input(
|
||||
.type(.text), .required, .placeholder("Username"),
|
||||
.name("username"), .id("username"),
|
||||
.minlength("3"), .pattern(.username)
|
||||
)
|
||||
}
|
||||
@@ -37,7 +40,8 @@ struct LoginForm: HTML, Sendable {
|
||||
label(.class("input validator w-full")) {
|
||||
SVG(.email)
|
||||
input(
|
||||
.type(.email), .placeholder("Email"), .required
|
||||
.type(.email), .placeholder("Email"), .required,
|
||||
.name("email"), .id("email"),
|
||||
)
|
||||
}
|
||||
div(.class("validator-hint hidden")) { "Enter valid email address." }
|
||||
@@ -46,7 +50,8 @@ struct LoginForm: HTML, Sendable {
|
||||
SVG(.key)
|
||||
input(
|
||||
.type(.password), .placeholder("Password"), .required,
|
||||
.pattern(.password), .minlength("8")
|
||||
.pattern(.password), .minlength("8"),
|
||||
.name("password"), .id("password"),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -55,7 +60,8 @@ struct LoginForm: HTML, Sendable {
|
||||
SVG(.key)
|
||||
input(
|
||||
.type(.password), .placeholder("Confirm Password"), .required,
|
||||
.pattern(.password), .minlength("8")
|
||||
.pattern(.password), .minlength("8"),
|
||||
.name("confirmPassword"), .id("confirmPassword"),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -75,7 +81,7 @@ struct LoginForm: HTML, Sendable {
|
||||
button(.class("btn btn-secondary mt-4")) { style.title }
|
||||
a(
|
||||
.class("btn btn-link mt-4"),
|
||||
.href(route: style == .signup ? .login(.index) : .user(.signup(.index)))
|
||||
.href(route: style == .signup ? .login(.index) : .signup(.index))
|
||||
) {
|
||||
style == .login ? "Sign Up" : "Login"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user