Controllers+Views+Routes: Add ScriptAfterLoad functionality

This commit is contained in:
Riyyi
2024-11-22 21:32:49 +01:00
parent 7f1e78fa08
commit f0cb958ea2
8 changed files with 88 additions and 14 deletions
@@ -0,0 +1,30 @@
import Elementary
import ElementaryHTMX
import ElementaryHTMXSSE
import ElementaryHTMXWS
import Fluent
import Vapor
import VaporElementary
struct TestController: RouteCollection {
func boot(routes: RoutesBuilder) throws {
routes.group("test") { test in
test.get("toast", use: toast)
}
}
@Sendable
func toast(req: Request) async throws -> HTMLResponse {
let state = try getState(request: req)
state.toast = ToastState(message: "Wow!",
title: "This is my title",
level: ToastState.Level.success)
throw Abort(.badRequest, headers: ["HX-Trigger": "toast"])
// return HTMLResponse { }
}
}
@@ -27,6 +27,8 @@ struct TodoController: RouteCollection {
MainLayout(title: "Todos") {
TodosTableComponent(name: "todos", todos: todos)
TodosFormComponent(name: "todos-form", target: "todos")
button(.class("btn btn-primary"), .type(.button), .hx.get("/test/toast")) { "Toast" }
}
}
}