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

Save/restore drawer state to local storage

This commit is contained in:
shiibe 2024-03-26 23:25:37 -04:00
parent e6fdc08de7
commit 4aa7e6596d
2 changed files with 18 additions and 6 deletions

View File

@ -47,7 +47,7 @@ public partial class HighScores
// Set last selected tab from local storage
selectedDifficultyTab = await localStorage.GetItemAsync<int>($"HighScoresTab_{Baid}");
selectedDifficultyTab = await localStorage.GetItemAsync<int>($"highScoresTab_{Baid}");
// Breadcrumbs
if (LoginService.IsLoggedIn && !LoginService.IsAdmin)
@ -80,6 +80,6 @@ public partial class HighScores
private async Task OnTabChanged(int index)
{
selectedDifficultyTab = index;
await localStorage.SetItemAsync($"HighScoresTab_{Baid}", selectedDifficultyTab);
await localStorage.SetItemAsync($"highScoresTab_{Baid}", selectedDifficultyTab);
}
}

View File

@ -1,4 +1,5 @@
@inherits LayoutComponentBase
@inject Blazored.LocalStorage.ILocalStorageService localStorage
<MudThemeProvider />
<MudDialogProvider />
@ -6,11 +7,11 @@
<MudLayout>
<MudAppBar Elevation="0">
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@((e) => DrawerToggle())" />
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="DrawerToggle" />
<MudSpacer />
<ChooseLanguage />
</MudAppBar>
<MudDrawer @bind-Open="_drawerOpen" Elevation="0" Style="border-right:1px solid #ededf0">
<MudDrawer Elevation="0" Style="border-right:1px solid #ededf0" Open="@_drawerOpen">
<MudDrawerHeader>
<MudText Typo="Typo.h6">TaikoWebUI</MudText>
</MudDrawerHeader>
@ -30,8 +31,19 @@
@code {
bool _drawerOpen = true;
void DrawerToggle()
protected override async Task OnInitializedAsync()
{
_drawerOpen = !_drawerOpen;
var hasLocalStorage = await localStorage.ContainKeyAsync("drawerOpen");
if (hasLocalStorage)
{
_drawerOpen = await localStorage.GetItemAsync<bool>("drawerOpen");
}
}
private async Task DrawerToggle()
{
_drawerOpen = !_drawerOpen;
await localStorage.SetItemAsync("drawerOpen", _drawerOpen);
}
}