1
0
mirror of synced 2024-12-01 09:37:21 +01:00
TaikoLocalServer/TaikoWebUI/Components/NavMenu.razor
2024-05-16 23:32:46 +01:00

100 lines
3.7 KiB
Plaintext

@inject AuthService AuthService
@inject NavigationManager NavigationManager
@inject IDialogService DialogService
@using TaikoWebUI.Pages.Dialogs;
<MudNavMenu Rounded="true" Class="pa-2" Margin="Margin.Dense" Color="Color.Primary">
<MudNavLink Href="/" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Dashboard">@Localizer["Dashboard"]</MudNavLink>
@if (AuthService.IsAdmin || !AuthService.LoginRequired)
{
<MudNavLink Href="/Users" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.People">@Localizer["Users"]</MudNavLink>
}
@{
var baid = AuthService.GetLoggedInBaid();
if (AuthService.LoginRequired && !AuthService.OnlyAdmin && !AuthService.IsLoggedIn) {
<MudDivider />
<MudNavLink Href="/Login" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Login">@Localizer["Log In"]</MudNavLink>
<MudNavLink Href="/Register" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.AddCard">@Localizer["Register"]</MudNavLink>
}
if (AuthService.IsLoggedIn)
{
<MudDivider />
<MudNavLink Href="@($"Users/{baid}/Profile")" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Person">@Localizer["Profile"]</MudNavLink>
<MudNavGroup Title=@Localizer["Play Data"] Expanded="true" Icon="@Icons.Material.Filled.EmojiEvents">
<MudNavLink Href="@($"Users/{baid}/Songs")" Match="NavLinkMatch.All">@Localizer["Song List"]</MudNavLink>
<MudNavLink Href="@($"Users/{baid}/HighScores")" Match="NavLinkMatch.All">@Localizer["High Scores"]</MudNavLink>
<MudNavLink Href="@($"Users/{baid}/PlayHistory")" Match="NavLinkMatch.All">@Localizer["Play History"]</MudNavLink>
<MudNavLink Href="@($"Users/{baid}/DaniDojo")" Match="NavLinkMatch.All">@Localizer["Dani Dojo"]</MudNavLink>
</MudNavGroup>
<MudNavGroup Title=@Localizer["Settings"] Expanded="settingsOpen" Icon="@Icons.Material.Filled.Settings">
<MudNavLink OnClick="ShowQrCode">@Localizer["Show QR Code"]</MudNavLink>
<MudNavLink Href="/ChangePassword" Match="NavLinkMatch.All">@Localizer["Change Password"]</MudNavLink>
<MudNavLink Href="@($"Users/{baid}/AccessCode")" Match="NavLinkMatch.All">@Localizer["Access Codes"]</MudNavLink>
</MudNavGroup>
}
if (AuthService.IsLoggedIn)
{
<MudDivider />
<MudNavLink Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Logout" IconColor="Color.Error" OnClick="Logout">@Localizer["Log Out"]</MudNavLink>
}
}
</MudNavMenu>
@code {
private bool settingsOpen = false;
protected override void OnInitialized()
{
AuthService.LoginStatusChanged += HandleAuthStatusChanged;
}
private void HandleAuthStatusChanged(object? sender, EventArgs e)
{
StateHasChanged();
}
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
AuthService.LoginStatusChanged += HandleAuthStatusChanged;
}
}
private async Task ShowQrCode()
{
var user = await AuthService.GetLoggedInUser();
if (user == null) return;
var parameters = new DialogParameters
{
["user"] = user
};
var options = new DialogOptions { DisableBackdropClick = true };
await DialogService.ShowAsync<UserQrCodeDialog>(Localizer["QR Code"], parameters, options);
// Prevent the settings menu from closing
settingsOpen = true;
}
private async Task Logout()
{
var result = await DialogService.ShowMessageBox(
"Log Out",
"Are you sure you want to log out?",
yesText: "Log Out",
noText: "Cancel");
if (result == true)
{
await AuthService.Logout();
NavigationManager.NavigateTo("/");
}
}
}