WIP: Begins creating some project views.
This commit is contained in:
59
Sources/ViewController/Live.swift
Normal file
59
Sources/ViewController/Live.swift
Normal file
@@ -0,0 +1,59 @@
|
||||
import Elementary
|
||||
import ManualDCore
|
||||
|
||||
extension ViewController.Request {
|
||||
|
||||
func render() async throws -> AnySendableHTML {
|
||||
switch route {
|
||||
case .project(let route):
|
||||
return try await route.renderView(isHtmxRequest: isHtmxRequest)
|
||||
default:
|
||||
// FIX: FIX
|
||||
return mainPage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension SiteRoute.View.ProjectRoute {
|
||||
func renderView(isHtmxRequest: Bool) async throws -> AnySendableHTML {
|
||||
switch self {
|
||||
case .index:
|
||||
return mainPage
|
||||
case .form:
|
||||
return MainPage {
|
||||
ProjectForm()
|
||||
}
|
||||
case .create:
|
||||
return mainPage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private let mainPage: AnySendableHTML = {
|
||||
MainPage {
|
||||
div {
|
||||
h1 { "It works!" }
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@Sendable
|
||||
private func render<C: HTML>(
|
||||
_ mainPage: (C) async throws -> AnySendableHTML,
|
||||
_ isHtmxRequest: Bool,
|
||||
@HTMLBuilder html: () -> C
|
||||
) async rethrows -> AnySendableHTML where C: Sendable {
|
||||
guard isHtmxRequest else {
|
||||
return try await mainPage(html())
|
||||
}
|
||||
return html()
|
||||
}
|
||||
|
||||
@Sendable
|
||||
private func render<C: HTML>(
|
||||
_ mainPage: (C) async throws -> AnySendableHTML,
|
||||
_ isHtmxRequest: Bool,
|
||||
_ html: @autoclosure @escaping () -> C
|
||||
) async rethrows -> AnySendableHTML where C: Sendable {
|
||||
try await render(mainPage, isHtmxRequest) { html() }
|
||||
}
|
||||
Reference in New Issue
Block a user