1
0
mirror of synced 2024-11-29 00:44:27 +01:00
TaikoLocalServer/TaikoWebUI/Components/MainLayout.razor
2024-03-27 12:49:27 -04:00

73 lines
2.2 KiB
Plaintext

@inherits LayoutComponentBase
@inject Blazored.LocalStorage.ILocalStorageService localStorage
<MudThemeProvider IsDarkMode="@_isDarkMode" />
<MudDialogProvider />
<MudSnackbarProvider />
<MudLayout>
<MudAppBar Elevation="0">
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="DrawerToggle" Size="Size.Small" />
<MudSpacer />
<MudStack Spacing="2" Row="true">
<MudIconButton Icon="@DarkModeIcon" Size="Size.Small" Color="Color.Inherit" OnClick="ToggleDarkMode" />
<ChooseLanguage />
</MudStack>
</MudAppBar>
<MudDrawer Elevation="0" Style="border-right:1px solid #ededf0" @bind-Open="_drawerOpen">
<MudDrawerHeader>
<MudText Typo="Typo.h6">TaikoWebUI</MudText>
</MudDrawerHeader>
<NavMenu />
</MudDrawer>
<MudMainContent>
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="my-8">
@Body
<MudScrollToTop>
<MudFab Color="Color.Secondary" StartIcon="@Icons.Material.Filled.ArrowCircleUp" />
</MudScrollToTop>
</MudContainer>
</MudMainContent>
</MudLayout>
@code {
bool _drawerOpen = true;
bool _isDarkMode = false;
protected override async Task OnInitializedAsync()
{
var hasLocalStorage = await localStorage.ContainKeyAsync("drawerOpen");
if (hasLocalStorage)
{
_drawerOpen = await localStorage.GetItemAsync<bool>("drawerOpen");
}
var hasDarkMode = await localStorage.ContainKeyAsync("isDarkMode");
if (hasDarkMode)
{
_isDarkMode = await localStorage.GetItemAsync<bool>("isDarkMode");
}
}
private async Task DrawerToggle()
{
_drawerOpen = !_drawerOpen;
await localStorage.SetItemAsync("drawerOpen", _drawerOpen);
}
private void ToggleDrawer()
{
_drawerOpen = !_drawerOpen;
}
private async Task ToggleDarkMode()
{
_isDarkMode = !_isDarkMode;
await localStorage.SetItemAsync("isDarkMode", _isDarkMode);
}
private string DarkModeIcon => _isDarkMode ? Icons.Material.Filled.BrightnessLow : Icons.Material.Filled.Brightness2;
}