2023-09-09 14:58:20 +02:00
|
|
|
@inherits LayoutComponentBase
|
2024-05-01 17:13:47 +02:00
|
|
|
@inject Blazored.LocalStorage.ILocalStorageService LocalStorage
|
2024-05-17 00:32:46 +02:00
|
|
|
@inject AuthService AuthService
|
2024-08-13 17:07:39 +02:00
|
|
|
@inject BreadcrumbsStateContainer BreadcrumbsStateContainer
|
|
|
|
|
2024-06-06 04:29:26 +02:00
|
|
|
@using Microsoft.Extensions.Options;
|
|
|
|
@using TaikoWebUI.Settings;
|
2023-09-09 14:58:20 +02:00
|
|
|
|
2024-08-13 17:07:39 +02:00
|
|
|
|
|
|
|
|
2024-05-01 17:13:47 +02:00
|
|
|
<MudThemeProvider IsDarkMode="@isDarkMode" Theme="@taikoWebUiTheme" />
|
2024-03-09 00:42:56 +01:00
|
|
|
<MudDialogProvider />
|
|
|
|
<MudSnackbarProvider />
|
2023-09-09 14:58:20 +02:00
|
|
|
|
|
|
|
<MudLayout>
|
2024-03-14 05:44:15 +01:00
|
|
|
<MudAppBar Elevation="0">
|
2024-03-27 17:49:27 +01:00
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="DrawerToggle" Size="Size.Small" />
|
2024-08-13 17:07:39 +02:00
|
|
|
<MudBreadcrumbs Items="BreadcrumbsStateContainer.breadcrumbs" Class="p-0"></MudBreadcrumbs>
|
2024-03-09 00:42:56 +01:00
|
|
|
<MudSpacer />
|
2024-05-27 00:06:51 +02:00
|
|
|
<MudStack Spacing="3" Row="true">
|
2024-06-02 23:33:33 +02:00
|
|
|
<LanguageToggle />
|
2024-05-27 01:49:14 +02:00
|
|
|
<MudIconButton Icon="@DarkModeIcon" Size="Size.Small" Color="Color.Inherit" OnClick="ToggleDarkMode" />
|
2024-03-27 17:49:27 +01:00
|
|
|
</MudStack>
|
2023-09-09 14:58:20 +02:00
|
|
|
</MudAppBar>
|
2024-05-01 17:13:47 +02:00
|
|
|
<MudDrawer Elevation="0" Style="border-right:1px solid #ededf0" @bind-Open="drawerOpen">
|
2023-09-09 14:58:20 +02:00
|
|
|
<MudDrawerHeader>
|
2024-06-06 04:29:26 +02:00
|
|
|
<MudText Typo="Typo.h6">@title</MudText>
|
2023-09-09 14:58:20 +02:00
|
|
|
</MudDrawerHeader>
|
2024-03-09 00:42:56 +01:00
|
|
|
<NavMenu />
|
2023-09-09 14:58:20 +02:00
|
|
|
</MudDrawer>
|
|
|
|
<MudMainContent>
|
2024-03-27 19:02:12 +01:00
|
|
|
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="my-8 pb-8">
|
2023-09-09 14:58:20 +02:00
|
|
|
@Body
|
|
|
|
|
|
|
|
<MudScrollToTop>
|
2024-03-10 00:20:25 +01:00
|
|
|
<MudFab Color="Color.Secondary" StartIcon="@Icons.Material.Filled.ArrowCircleUp" />
|
2023-09-09 14:58:20 +02:00
|
|
|
</MudScrollToTop>
|
|
|
|
</MudContainer>
|
|
|
|
</MudMainContent>
|
|
|
|
</MudLayout>
|
|
|
|
|
|
|
|
@code {
|
2024-05-01 17:13:47 +02:00
|
|
|
bool drawerOpen = true;
|
|
|
|
bool isDarkMode = false;
|
2024-06-06 04:29:26 +02:00
|
|
|
string title = "TaikoWebUI";
|
2023-09-09 14:58:20 +02:00
|
|
|
|
2024-06-06 04:29:26 +02:00
|
|
|
[Inject]
|
|
|
|
IOptions<WebUiSettings> UiSettings { get; set; } = default!;
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
{
|
|
|
|
title = UiSettings.Value.Title;
|
|
|
|
}
|
2024-08-13 17:07:39 +02:00
|
|
|
|
2024-03-27 04:25:37 +01:00
|
|
|
protected override async Task OnInitializedAsync()
|
2023-09-09 14:58:20 +02:00
|
|
|
{
|
2024-08-13 17:07:39 +02:00
|
|
|
await base.OnInitializedAsync();
|
|
|
|
|
|
|
|
BreadcrumbsStateContainer.OnChange += StateHasChanged;
|
|
|
|
|
|
|
|
|
2024-05-01 17:13:47 +02:00
|
|
|
var hasDrawerOpenEntry = await LocalStorage.ContainKeyAsync("drawerOpen");
|
2024-03-27 04:25:37 +01:00
|
|
|
|
2024-03-27 19:02:12 +01:00
|
|
|
if (hasDrawerOpenEntry)
|
2024-03-27 17:49:27 +01:00
|
|
|
{
|
2024-05-01 17:13:47 +02:00
|
|
|
drawerOpen = await LocalStorage.GetItemAsync<bool>("drawerOpen");
|
2024-03-27 17:49:27 +01:00
|
|
|
}
|
|
|
|
|
2024-05-01 17:13:47 +02:00
|
|
|
var hasDarkModeEntry = await LocalStorage.ContainKeyAsync("isDarkMode");
|
2024-03-27 17:49:27 +01:00
|
|
|
|
2024-03-27 19:02:12 +01:00
|
|
|
if (hasDarkModeEntry)
|
2024-03-27 17:49:27 +01:00
|
|
|
{
|
2024-05-01 17:13:47 +02:00
|
|
|
isDarkMode = await LocalStorage.GetItemAsync<bool>("isDarkMode");
|
|
|
|
}
|
|
|
|
|
2024-05-25 19:12:30 +02:00
|
|
|
if (AuthService.LoginRequired && !AuthService.IsLoggedIn)
|
2024-05-01 17:13:47 +02:00
|
|
|
{
|
|
|
|
// If not logged in, attempt to use JwtToken from local storage to log in
|
2024-05-17 00:32:46 +02:00
|
|
|
await AuthService.LoginWithAuthToken();
|
2024-03-27 17:49:27 +01:00
|
|
|
}
|
2023-09-09 14:58:20 +02:00
|
|
|
}
|
2024-03-27 04:25:37 +01:00
|
|
|
|
|
|
|
private async Task DrawerToggle()
|
2024-08-13 17:07:39 +02:00
|
|
|
{
|
|
|
|
drawerOpen = !drawerOpen;
|
|
|
|
await LocalStorage.SetItemAsync("drawerOpen", drawerOpen);
|
|
|
|
}
|
2024-03-27 05:03:55 +01:00
|
|
|
|
2024-03-27 17:49:27 +01:00
|
|
|
private async Task ToggleDarkMode()
|
2024-08-13 17:07:39 +02:00
|
|
|
{
|
|
|
|
isDarkMode = !isDarkMode;
|
|
|
|
await LocalStorage.SetItemAsync("isDarkMode", isDarkMode);
|
|
|
|
}
|
2024-03-27 17:49:27 +01:00
|
|
|
|
2024-05-01 17:13:47 +02:00
|
|
|
private string DarkModeIcon => isDarkMode ? Icons.Material.Filled.BrightnessLow : Icons.Material.Filled.Brightness2;
|
2024-03-27 19:02:12 +01:00
|
|
|
|
2024-05-01 17:13:47 +02:00
|
|
|
readonly MudTheme taikoWebUiTheme = new()
|
2024-03-27 19:02:12 +01:00
|
|
|
{
|
|
|
|
Palette = new PaletteLight()
|
|
|
|
{
|
|
|
|
Primary = Colors.Indigo.Default,
|
|
|
|
PrimaryLighten = Colors.Indigo.Lighten2,
|
|
|
|
PrimaryDarken = Colors.Indigo.Darken2,
|
|
|
|
AppbarBackground = Colors.Indigo.Darken3,
|
|
|
|
},
|
|
|
|
PaletteDark = new PaletteDark()
|
|
|
|
{
|
|
|
|
Primary = Colors.Indigo.Accent1,
|
|
|
|
PrimaryLighten = Colors.Indigo.Lighten4,
|
|
|
|
PrimaryDarken = Colors.Indigo.Accent1,
|
|
|
|
},
|
|
|
|
};
|
2024-08-13 17:07:39 +02:00
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
BreadcrumbsStateContainer.OnChange -= StateHasChanged;
|
|
|
|
}
|
2023-09-09 14:58:20 +02:00
|
|
|
}
|