Files
HostKeeper/app/backend/views/nav.html
T
swanadiva cdc8b3afd0 fix: nav highlight follows current page via Alpine.js client-side state
- Server-side {{if eq $.View .ID}} only works on initial page load
- HTMX swaps #main-content only, nav never re-renders → stale highlight
- Add x-data page state + @after-settle.window listener to track current route
- Nav items use :class binding to apply active style based on Alpine state
2026-07-07 15:37:16 +07:00

39 lines
1.9 KiB
HTML

{{define "nav"}}
<nav class="w-[260px] min-h-screen bg-white/70 backdrop-blur-md border-r border-outline-variant/30 flex flex-col shrink-0"
x-data="{ page: '{{.View}}' }" @after-settle.window="page = location.pathname.slice(1) || 'hosts'">
<div class="p-3 border-b border-outline-variant/20">
<div class="flex items-center gap-2">
<div class="w-8 h-8 rounded-lg bg-primary flex items-center justify-center text-white text-sm font-bold">K</div>
<span class="font-bold text-lg text-on-surface">Hostkeeper</span>
</div>
</div>
<div class="flex-1 px-3 py-4 space-y-0.5">
{{range .NavItems}}
<a href="/{{.ID}}"
hx-get="/{{.ID}}" hx-target="#main-content" hx-push-url="true"
:class="page === '{{.ID}}' ? 'bg-primary/10 text-primary font-medium' : 'text-on-surface-variant hover:bg-surface-container-low hover:text-on-surface'"
class="flex items-center gap-3 px-3 py-2 rounded-lg transition-colors text-sm">
<span class="w-5 h-5 flex items-center justify-center">{{svg .Icon}}</span>
<span>{{.Label}}</span>
</a>
{{end}}
</div>
<div class="px-3 py-3 border-t border-outline-variant/20">
<p class="text-xs font-medium text-on-surface-variant uppercase tracking-wide mb-2 px-3">Transfers</p>
<div class="px-3 py-2 rounded-lg bg-surface-container-low/50 text-xs text-on-surface-variant flex items-center gap-2">
<span class="w-1.5 h-1.5 rounded-full bg-on-surface-variant/30"></span>
No active transfers
</div>
</div>
<div class="p-4 border-t border-outline-variant/20">
<div class="flex items-center gap-3">
<div class="w-8 h-8 rounded-full bg-tertiary/20 flex items-center justify-center text-tertiary text-sm font-semibold">U</div>
<div class="flex-1 min-w-0">
<p class="text-sm font-medium text-on-surface truncate">User</p>
<p class="text-xs text-on-surface-variant truncate">Local</p>
</div>
</div>
</div>
</nav>
{{end}}