package baseview import ( "context" "git.haelnorr.com/h/oslstats/internal/contexts" "git.haelnorr.com/h/oslstats/internal/db" ) type NavItem struct { Name string Href string } type ProfileItem struct { Name string Href string } // Main navigation items (centralized) func getNavItems() []NavItem { return []NavItem{ {Name: "Seasons", Href: "/seasons"}, {Name: "Leagues", Href: "/leagues"}, {Name: "Teams", Href: "/teams"}, } } // 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{ Name: "Admin Panel", Href: "/admin", }) } return items } // Main navbar component templ Navbar() { {{ navItems := getNavItems() }} {{ user := db.CurrentUser(ctx) }} {{ profileItems := getProfileItems(ctx) }}
Viewing as: { previewRole.DisplayName }