1
0
mirror of synced 2024-11-25 07:20:15 +01:00
TaikoLocalServer/TaikoWebUI/Components/MainLayout.razor
2024-03-27 14:02:40 -04:00

85 lines
2.7 KiB
Plaintext

@inherits LayoutComponentBase
@inject Blazored.LocalStorage.ILocalStorageService localStorage
<MudThemeProvider IsDarkMode="@_isDarkMode" Theme="@TaikoWebUiTheme" />
<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 pb-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 hasDrawerOpenEntry = await localStorage.ContainKeyAsync("drawerOpen");
if (hasDrawerOpenEntry)
{
_drawerOpen = await localStorage.GetItemAsync<bool>("drawerOpen");
}
var hasDarkModeEntry = await localStorage.ContainKeyAsync("isDarkMode");
if (hasDarkModeEntry)
{
_isDarkMode = await localStorage.GetItemAsync<bool>("isDarkMode");
}
}
private async Task DrawerToggle()
{
_drawerOpen = !_drawerOpen;
await localStorage.SetItemAsync("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;
MudTheme TaikoWebUiTheme = new MudTheme()
{
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,
},
};
}