Save/restore drawer state to local storage
This commit is contained in:
parent
e6fdc08de7
commit
4aa7e6596d
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user