1
0
mirror of synced 2024-12-12 14:51:08 +01:00
TaikoLocalServer/TaikoWebUI/Components/NavMenu.razor

100 lines
3.7 KiB
Plaintext
Raw Normal View History

2024-05-17 00:32:46 +02:00
@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>
2024-05-17 00:32:46 +02:00
@if (AuthService.IsAdmin || !AuthService.LoginRequired)
{
<MudNavLink Href="/Users" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.People">@Localizer["Users"]</MudNavLink>
}
@{
2024-05-17 00:32:46 +02:00
var baid = AuthService.GetLoggedInBaid();
if (AuthService.LoginRequired && !AuthService.OnlyAdmin && !AuthService.IsLoggedIn) {
<MudDivider />
2024-03-09 19:45:20 +01:00
<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>
}
2024-05-17 00:32:46 +02:00
if (AuthService.IsLoggedIn)
{
<MudDivider />
2024-05-17 00:32:46 +02:00
<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">
2024-05-17 00:32:46 +02:00
<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>
2024-05-17 00:32:46 +02:00
<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>
2024-05-17 00:32:46 +02:00
<MudNavLink Href="@($"Users/{baid}/AccessCode")" Match="NavLinkMatch.All">@Localizer["Access Codes"]</MudNavLink>
</MudNavGroup>
}
2024-05-17 00:32:46 +02:00
if (AuthService.IsLoggedIn)
{
<MudDivider />
<MudNavLink Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Logout" IconColor="Color.Error" OnClick="Logout">@Localizer["Log Out"]</MudNavLink>
}
}
</MudNavMenu>
@code {
2024-05-17 00:32:46 +02:00
private bool settingsOpen = false;
protected override void OnInitialized()
{
2024-05-17 00:32:46 +02:00
AuthService.LoginStatusChanged += HandleAuthStatusChanged;
}
2024-05-17 00:32:46 +02:00
private void HandleAuthStatusChanged(object? sender, EventArgs e)
{
StateHasChanged();
}
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
2024-05-17 00:32:46 +02:00
AuthService.LoginStatusChanged += HandleAuthStatusChanged;
}
}
2024-05-17 00:32:46 +02:00
private async Task ShowQrCode()
{
2024-05-17 00:32:46 +02:00
var user = await AuthService.GetLoggedInUser();
if (user == null) return;
var parameters = new DialogParameters
{
2024-05-17 00:32:46 +02:00
["user"] = user
};
2024-05-17 00:32:46 +02:00
var options = new DialogOptions { DisableBackdropClick = true };
await DialogService.ShowAsync<UserQrCodeDialog>(Localizer["QR Code"], parameters, options);
// Prevent the settings menu from closing
2024-05-17 00:32:46 +02:00
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)
{
2024-05-17 00:32:46 +02:00
await AuthService.Logout();
NavigationManager.NavigateTo("/");
}
}
}