66 lines
3.9 KiB
Plaintext
66 lines
3.9 KiB
Plaintext
package shared
|
|
|
|
import (
|
|
"fmt"
|
|
"gitea.zokki.net/zokki/uni/web43-diary/context"
|
|
"gitea.zokki.net/zokki/uni/web43-diary/internal/session"
|
|
)
|
|
|
|
templ header(context *context.Context) {
|
|
{{ sess := session.GetSession(context) }}
|
|
<header class="sticky top-0 bg-surface-container shadow-[0_.5rem_.5rem_#00000080]">
|
|
<nav class="max-w-screen-2xl flex flex-wrap items-center justify-between mx-auto px-2 py-1 gap-4">
|
|
<a href="/" class="flex flex-center p-2 gap-4">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="2rem" height="2rem" viewBox="0 0 16 16">
|
|
<g fill="currentColor">
|
|
<path d="M5 10.5a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 0 1h-2a.5.5 0 0 1-.5-.5m0-2a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5m0-2a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5m0-2a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5"></path>
|
|
<path d="M3 0h10a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2v-1h1v1a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1H3a1 1 0 0 0-1 1v1H1V2a2 2 0 0 1 2-2"></path>
|
|
<path d="M1 5v-.5a.5.5 0 0 1 1 0V5h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1zm0 3v-.5a.5.5 0 0 1 1 0V8h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1zm0 3v-.5a.5.5 0 0 1 1 0v.5h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1z"></path>
|
|
</g>
|
|
</svg>
|
|
<h1 class="text-2xl m-0">WEB43 Diary</h1>
|
|
</a>
|
|
<div class="flex items-center m:order-2 gap-4">
|
|
<label class="inline-flex items-center cursor-pointer">
|
|
<input type="checkbox" id="theme-switcher" class="sr-only peer" checked?={ sess.GetTheme().IsLightTheme() }/>
|
|
<div class="relative w-11 h-6 bg-dark-450 rounded-full peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-bright after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-dark-600"></div>
|
|
</label>
|
|
if user := sess.GetUser(); user.ID > 0 {
|
|
<button type="button" class="flex text-highl flex-center bg-surface-variant rounded-full overflow-hidden w-10 h-10" id="user-menu-button" aria-expanded="false" data-dropdown-toggle="user-dropdown" data-dropdown-placement="bottom">
|
|
<span class="sr-only">Nutzermenu öffnen</span>
|
|
<span class="font-medium">{ user.Initials() }</span>
|
|
</button>
|
|
} else {
|
|
{{
|
|
redirectURL := context.Request.URL.RawQuery
|
|
if redirectURL == "" {
|
|
redirectURL = context.Request.URL.Path
|
|
}
|
|
}}
|
|
<a href={ templ.SafeURL(fmt.Sprintf("/user/login/?%s", redirectURL)) } class="text-on-bg bg-primary hover:bg-primary-650 font-medium rounded-lg text-sm px-5 py-2.5">Login</a>
|
|
<a href={ templ.SafeURL(fmt.Sprintf("/user/register/?%s", redirectURL)) } class="text-on-bg bg-secondary hover:bg-secondary-650 font-medium rounded-lg text-sm px-5 py-2.5">Registrieren</a>
|
|
}
|
|
</div>
|
|
</nav>
|
|
</header>
|
|
if user := sess.GetUser(); user.ID > 0 {
|
|
<!-- Dropdown menu -->
|
|
<div class="z-50 w-64 hidden bg-surface-container-highest divide-y divide-bright/50 rounded-lg shadow" id="user-dropdown">
|
|
<div class="flex flex-center gap-2 px-4 py-3">
|
|
<div class="flex flex-col">
|
|
<span class="font-medium line-clamp-2">{ user.Username }</span>
|
|
<span class="text-sm text-dark-350 line-clamp-2">{ user.FullName() }</span>
|
|
</div>
|
|
<a href="/settings" class="size-10 p-2 text-bright/80 rounded-full hover:bg-dark/35"><i class="ic--outline-settings size-full"></i></a>
|
|
</div>
|
|
<ul class="py-2 text-bright/80 text-sm" aria-labelledby="user-menu-button">
|
|
<li><a href="/" class="block px-4 py-2 hover:bg-dark/35">Startseite</a></li>
|
|
<li><a href={ templ.URL(fmt.Sprintf("/?owners=%d", user.ID)) } class="block px-4 py-2 hover:bg-dark/35">Meine Einträge</a></li>
|
|
</ul>
|
|
<ul class="py-2 text-sm" aria-labelledby="user-menu-button">
|
|
<li><a href={ templ.URL(fmt.Sprintf("/user/%d/logout", user.ID)) } class="block px-4 py-2 text-red-600 hover:bg-dark/35">Ausloggen</a></li>
|
|
</ul>
|
|
</div>
|
|
}
|
|
}
|