Wave/Wave/Components/Layout/NavMenu.razor

71 lines
2 KiB
Plaintext

@implements IDisposable
@inject NavigationManager NavigationManager
<header>
<div class="navbar bg-base-200">
<div class="navbar-start">
<picture class="h-12">
<source type="image/jxl" srcset="img/logo.jxl" />
<source type="image/webp" srcset="img/logo.webp" />
<source type="image/svg+xml" scrset="img/logo.svg" />
<img class="max-h-full object-contain object-left" src="img/logo.png" alt="Wave" />
</picture>
</div>
<div class="navbar-center"></div>
<div class="navbar-end">
<ul class="menu menu-horizontal">
<AuthorizeView>
<Authorized>
<li>
<NavLink ActiveClass="tab-active" class="tab" href="Account/Manage">@context.User.Identity?.Name</NavLink>
</li>
<li>
<form action="Account/Logout" method="post">
<AntiforgeryToken />
<input type="hidden" name="ReturnUrl" value="@_currentUrl" />
<button type="submit" class="">Logout</button>
</form>
</li>
</Authorized>
<NotAuthorized>
<li>
<NavLink href="Account/Login">Login</NavLink>
</li>
<li>
<NavLink href="Account/Register">Register</NavLink>
</li>
</NotAuthorized>
</AuthorizeView>
</ul>
</div>
</div>
<div class="flex justify-center bg-base-300">
<nav class="tabs tabs-bordered">
<NavLink ActiveClass="tab-active" class="tab" href="" Match="NavLinkMatch.All">Home</NavLink>
<NavLink ActiveClass="tab-active" class="tab" href="weather">Weather</NavLink>
<NavLink ActiveClass="tab-active" class="tab" href="auth">Auth Required</NavLink>
</nav>
</div>
</header>
@code {
private string? _currentUrl;
protected override void OnInitialized() {
_currentUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
NavigationManager.LocationChanged += OnLocationChanged;
}
private void OnLocationChanged(object? sender, LocationChangedEventArgs e) {
_currentUrl = NavigationManager.ToBaseRelativePath(e.Location);
StateHasChanged();
}
public void Dispose() {
NavigationManager.LocationChanged -= OnLocationChanged;
}
}