@@ -75,52 +75,64 @@ export const useFirecampStyle = createStyles((theme) => ({
7575} ) ) ;
7676
7777const FirecampThemeProvider : FC < IFirecampThemeProvider > = ( {
78- themeVariant = EFirecampThemeVariant . LightPrimary ,
78+ themeVariant,
7979 children,
8080 ...props
8181} ) => {
82- const [ colorScheme , setColorScheme ] = useState < ColorScheme > ( 'light' ) ;
83- const [ themeColor , updatethemeColor ] = useState < EFirecampThemeVariant > (
84- EFirecampThemeVariant . LightPrimary
85- ) ;
8682
87- useEffect ( ( ) => {
88- updateTheme ( themeVariant ) ;
89- } , [ themeVariant ] ) ;
83+ const _initialize = ( ) => {
84+ // on first time load set theme from local storage, if not found then set default
85+ let themeStored = localStorage . getItem ( 'theme' ) as EFirecampThemeVariant ;
86+ if ( ! Object . values ( EFirecampThemeVariant ) . includes ( themeStored ) ) {
87+ themeStored = EFirecampThemeVariant . LightPrimary
88+ }
89+ return themeStored ;
90+ }
9091
91- // update theme colorScheme & primaryColor
92- const updateTheme = ( color : EFirecampThemeVariant ) => {
93- // update the primary color
94- updatethemeColor ( color ) ;
92+ const [ colorScheme , setColorScheme ] = useState < ColorScheme > ( 'light' ) ;
93+ const [ theme , setTheme ] = useState < EFirecampThemeVariant > ( _initialize ) ;
94+
95+ // update theme
96+ const updateTheme = ( theme : EFirecampThemeVariant ) => {
9597
9698 // update the color schema
9799 setColorScheme (
98100 [
99101 EFirecampThemeVariant . LightPrimary ,
100102 EFirecampThemeVariant . LightSecondary ,
101- ] . includes ( color )
103+ ] . includes ( theme )
102104 ? 'light'
103105 : 'dark'
104106 ) ;
105107
108+ // save in local storage
109+ localStorage . setItem ( "theme" , theme ) ;
110+
111+ // update theme
112+ setTheme ( theme ) ;
113+
114+ updateMonacoEditorTheme ( theme )
115+ } ;
116+
117+ const updateMonacoEditorTheme = ( theme : EFirecampThemeVariant ) => {
106118 // update the monaco editor theme
107119 const editorTheme = [
108120 EFirecampThemeVariant . LightPrimary ,
109121 EFirecampThemeVariant . LightSecondary ,
110- ] . includes ( color )
122+ ] . includes ( theme )
111123 ? EEditorTheme . Lite
112124 : EEditorTheme . Dark ;
113125
114126 localStorage . setItem ( 'editorTheme' , editorTheme ) ;
115127 EditorApi . setEditorTheme ( editorTheme ) ;
116- } ;
128+ }
117129
118130 return (
119131 //@ts -ignore
120- < ColorSchemeProvider colorScheme = { themeColor }
121- toggleColorScheme = { ( c : ColorScheme | EFirecampThemeVariant ) =>
122- updateTheme ( c as EFirecampThemeVariant )
123- }
132+ < ColorSchemeProvider colorScheme = { theme }
133+ toggleColorScheme = { ( c : ColorScheme | EFirecampThemeVariant ) => {
134+ updateTheme ( c as EFirecampThemeVariant ) ;
135+ } }
124136 >
125137 < MantineProvider
126138 theme = { {
@@ -438,7 +450,7 @@ const FirecampThemeProvider: FC<IFirecampThemeProvider> = ({
438450 'primary-color' : [
439451 EFirecampThemeVariant . LightPrimary ,
440452 EFirecampThemeVariant . DarkPrimary ,
441- ] . includes ( themeColor )
453+ ] . includes ( theme )
442454 ? primaryColor
443455 : secondaryColor ,
444456 dark : defaultDarkColor ,
0 commit comments