Controllers+Views+Routes: Add ScriptAfterLoad functionality
This commit is contained in:
@@ -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" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user