@inherits LayoutComponentBase @inject Blazored.LocalStorage.ILocalStorageService LocalStorage @inject AuthService AuthService @inject BreadcrumbsStateContainer BreadcrumbsStateContainer @using Microsoft.Extensions.Options; @using TaikoWebUI.Settings; @title @Body @code { bool drawerOpen = true; bool isDarkMode = false; string title = "TaikoWebUI"; [Inject] IOptions UiSettings { get; set; } = default!; protected override void OnInitialized() { title = UiSettings.Value.Title; } protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); BreadcrumbsStateContainer.OnChange += StateHasChanged; var hasDrawerOpenEntry = await LocalStorage.ContainKeyAsync("drawerOpen"); if (hasDrawerOpenEntry) { drawerOpen = await LocalStorage.GetItemAsync("drawerOpen"); } var hasDarkModeEntry = await LocalStorage.ContainKeyAsync("isDarkMode"); if (hasDarkModeEntry) { isDarkMode = await LocalStorage.GetItemAsync("isDarkMode"); } if (AuthService.LoginRequired && !AuthService.IsLoggedIn) { // If not logged in, attempt to use JwtToken from local storage to log in await AuthService.LoginWithAuthToken(); } } 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; readonly MudTheme taikoWebUiTheme = new() { 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, }, }; public void Dispose() { BreadcrumbsStateContainer.OnChange -= StateHasChanged; } }