admin page updates

This commit is contained in:
2026-02-13 20:51:39 +11:00
parent ea8b74c5e3
commit 136adabb92
34 changed files with 1737 additions and 164 deletions

View File

@@ -25,13 +25,21 @@ func getNavItems() []NavItem {
}
}
// Profile dropdown items (context-aware for admin)
// Profile dropdown items (context-aware for admin and preview mode)
func getProfileItems(ctx context.Context) []ProfileItem {
items := []ProfileItem{
{Name: "Profile", Href: "/profile"},
{Name: "Account", Href: "/account"},
}
// Check if we're in preview mode
previewRole := contexts.GetPreviewRole(ctx)
if previewRole != nil {
// In preview mode: show stop viewing button instead of admin panel
return items
}
// Not in preview mode: show admin panel if user is admin
cache := contexts.Permissions(ctx)
if cache != nil && cache.Roles["admin"] {
items = append(items, ProfileItem{
@@ -104,6 +112,7 @@ templ userMenu(user *db.User, profileItems []ProfileItem) {
// Profile dropdown (private helper)
templ profileDropdown(user *db.User, items []ProfileItem) {
{{ previewRole := contexts.GetPreviewRole(ctx) }}
<div x-data="{ isActive: false }" class="relative">
<div
class="inline-flex items-center overflow-hidden rounded-lg
@@ -118,7 +127,7 @@ templ profileDropdown(user *db.User, items []ProfileItem) {
</button>
</div>
<div
class="absolute end-0 z-10 mt-2 w-36 divide-y divide-surface2
class="absolute end-0 z-10 mt-2 w-48 divide-y divide-surface2
rounded-lg border border-surface1 bg-surface0 shadow-lg"
role="menu"
x-cloak
@@ -127,6 +136,38 @@ templ profileDropdown(user *db.User, items []ProfileItem) {
x-on:click.away="isActive = false"
x-on:keydown.escape.window="isActive = false"
>
<!-- Preview Mode Stop Buttons -->
if previewRole != nil {
<div class="p-2 bg-yellow/10 border-b border-yellow/30 space-y-2">
<p class="text-xs text-yellow/80 px-2 font-semibold">
Viewing as: { previewRole.DisplayName }
</p>
<div class="flex gap-2">
<form method="POST" action="/admin/roles/preview-stop?stay=true" class="flex-1">
<button
type="submit"
class="w-full rounded-lg px-3 py-2
text-sm text-mantle bg-green font-semibold hover:bg-teal hover:cursor-pointer transition"
role="menuitem"
@click="isActive=false"
>
Stop Preview
</button>
</form>
<form method="POST" action="/admin/roles/preview-stop" class="flex-1">
<button
type="submit"
class="w-full rounded-lg px-3 py-2
text-sm text-mantle bg-blue font-semibold hover:bg-sky hover:cursor-pointer transition"
role="menuitem"
@click="isActive=false"
>
Return to Admin
</button>
</form>
</div>
</div>
}
<!-- Profile links -->
<div class="p-2">
for _, item := range items {