1
0
mirror of synced 2025-01-19 00:04:05 +01:00

Add Dark Mode toggle

This commit is contained in:
shiibe 2024-03-27 12:49:27 -04:00
parent e5c482941c
commit aa727a98fb
8 changed files with 29 additions and 8 deletions

View File

@ -1,3 +1,5 @@
@using TaikoWebUI.Components;
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />

View File

@ -1,15 +1,18 @@
@inherits LayoutComponentBase
@inject Blazored.LocalStorage.ILocalStorageService localStorage
<MudThemeProvider />
<MudThemeProvider IsDarkMode="@_isDarkMode" />
<MudDialogProvider />
<MudSnackbarProvider />
<MudLayout>
<MudAppBar Elevation="0">
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="DrawerToggle" />
<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>
@ -30,6 +33,7 @@
@code {
bool _drawerOpen = true;
bool _isDarkMode = false;
protected override async Task OnInitializedAsync()
{
@ -39,6 +43,13 @@
{
_drawerOpen = await localStorage.GetItemAsync<bool>("drawerOpen");
}
var hasDarkMode = await localStorage.ContainKeyAsync("isDarkMode");
if (hasDarkMode)
{
_isDarkMode = await localStorage.GetItemAsync<bool>("isDarkMode");
}
}
private async Task DrawerToggle()
@ -51,4 +62,12 @@
{
_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;
}

View File

@ -7,7 +7,7 @@
@inject IJSRuntime JSRuntime
@using TaikoWebUI.Utilities;
@using TaikoWebUI.Pages.Components.Song;
@using TaikoWebUI.Components.Song;
@if (LoginService.LoginRequired && (!LoginService.IsLoggedIn || (LoginService.GetLoggedInUser().Baid != Baid && !LoginService.IsAdmin)))
{

View File

@ -3,7 +3,7 @@
@inject LoginService LoginService
@inject NavigationManager NavigationManager
@using TaikoWebUI.Pages.Components
@using TaikoWebUI.Components
@page "/Users"