File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 1414}
1515
1616<!DOCTYPE html>
17- <html lang =" en" >
17+ <html lang =" en" data-bs-theme = " @Themes.ActiveTheme.BootstrapThemeMode " >
1818<head >
1919 <meta charset =" utf-8" />
2020 <meta name =" viewport" content =" width=device-width, initial-scale=1.0" />
3838</head >
3939<body >
4040 <div id =" switcher-container" data-permanent ></div >
41- <Routes ></Routes >
41+ <Routes ></Routes >
4242 <script src =" _framework/blazor.web.js" ></script >
4343</body >
4444
Original file line number Diff line number Diff line change 1- @inject ThemeService Themes
1+ @implements IDisposable
2+ @inject ThemeService Themes
3+ @inject PersistentComponentState ApplicationState
4+
25@rendermode InteractiveServer
36<ThemeJsChangeDispatcher InitialThemeName =" blazor-berry" ></ThemeJsChangeDispatcher >
47<div class =" @GetHeaderContainerCss()" >
1619@code {
1720 string _themeName ;
1821 bool _themeSwitcherShown ;
22+ PersistingComponentStateSubscription _persistingSubscription ;
1923
2024 protected string ThemeName {
2125 get { return _themeName ; }
3943 }
4044 }
4145 protected override void OnInitialized () {
42- ThemeName = Themes .ActiveTheme ? .Name ?? string .Empty ;
46+ _persistingSubscription = ApplicationState .RegisterOnPersisting (PersistData );
47+ if (ApplicationState .TryTakeFromJson <string >(" ThemeName" , out var themeName ) && themeName != null )
48+ ThemeName = themeName ;
49+ else
50+ ThemeName = Themes .ActiveTheme ? .Name ?? string .Empty ;
4351 }
4452 void ToggleThemeSwitcherPanel () {
4553 ThemeSwitcherShown = ! ThemeSwitcherShown ;
5462 cssClasses .Add (" theme-external" );
5563 return string .Join (" " , cssClasses );
5664 }
65+ Task PersistData () {
66+ ApplicationState .PersistAsJson (" ThemeName" , ThemeName );
67+ return Task .CompletedTask ;
68+ }
69+ void IDisposable .Dispose () {
70+ _persistingSubscription .Dispose ();
71+ }
5772}
You can’t perform that action at this time.
0 commit comments