feat: Adds logout route and switches user navbar item to dropdown menu.

This commit is contained in:
2026-02-09 12:32:30 -05:00
parent 5a7cf4714b
commit 88af6f722e
5 changed files with 39 additions and 7 deletions

View File

@@ -6681,6 +6681,9 @@
.w-6 {
width: calc(var(--spacing) * 6);
}
.w-52 {
width: calc(var(--spacing) * 52);
}
.w-\[250px\] {
width: 250px;
}
@@ -7625,6 +7628,9 @@
}
}
}
.bg-base-100 {
background-color: var(--color-base-100);
}
.bg-base-200 {
background-color: var(--color-base-200);
}
@@ -8084,6 +8090,9 @@
.px-6 {
padding-inline: calc(var(--spacing) * 6);
}
.px-10 {
padding-inline: calc(var(--spacing) * 10);
}
.py-1 {
padding-block: calc(var(--spacing) * 1);
}

View File

@@ -899,11 +899,16 @@ extension SiteRoute.View {
extension SiteRoute.View {
public enum UserRoute: Equatable, Sendable {
case profile(Profile)
case logout
static let router = OneOf {
Route(.case(Self.profile)) {
Profile.router
}
Route(.case(Self.logout)) {
Path { "logout" }
Method.get
}
}
}
}

View File

@@ -647,7 +647,17 @@ extension SiteRoute.View.ProjectRoute.DuctSizingRoute {
extension SiteRoute.View.UserRoute {
func renderView(on request: ViewController.Request) async -> AnySendableHTML {
@Dependency(\.auth) var auth
switch self {
case .logout:
return await request.view {
await ResultView {
try auth.logout()
} onSuccess: {
LoginForm(next: nil)
}
}
case .profile(let route):
return await route.renderView(on: request)
}

View File

@@ -14,7 +14,8 @@ struct HomeView: HTML, Sendable {
.class("btn btn-ghost btn-secondary text-lg"),
.hx.get(route: .login(.index())),
.hx.target("body"),
.hx.swap(.outerHTML)
.hx.swap(.outerHTML),
.hx.pushURL(true)
) {
"Login"
}

View File

@@ -49,14 +49,21 @@ struct Navbar: HTML, Sendable {
}
if userProfile {
// TODO: Make dropdown
div(.class("flex-none")) {
a(
.href(route: .user(.profile(.index))),
) {
div(.class("flex-none dropdown dropdown-end dropdown-hover")) {
div(.class("btn m-1"), .tabindex(0), .role("button")) {
SVG(.circleUser)
}
.navButton()
.tooltip("Profile")
ul(
.tabindex(-1),
.class("dropdown-content menu bg-base-200 rounded-box z-1 w-52 py-2 shadow-sm")
) {
li {
a(.href(route: .user(.profile(.index)))) { "Profile" }
}
li {
a(.href(route: .user(.logout))) { "Logout" }
}
}
}
}
}