WIP: Begins creating some project views.

This commit is contained in:
2025-12-30 17:05:37 -05:00
parent 2bbff896c9
commit f67c3ef847
7 changed files with 167 additions and 10 deletions

View 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() }
}