File tree 1 file changed +17
-14
lines changed
1 file changed +17
-14
lines changed Original file line number Diff line number Diff line change 1
- import { createContext , useState } from "react" ;
1
+ import { createContext , useEffect , useState } from "react" ;
2
2
import { tableWidth } from "../data/constants" ;
3
3
4
- export const SettingsContext = createContext ( {
4
+ const defaultSettings = {
5
5
strictMode : false ,
6
6
showFieldSummary : true ,
7
7
showGrid : true ,
@@ -11,20 +11,23 @@ export const SettingsContext = createContext({
11
11
showCardinality : true ,
12
12
tableWidth : tableWidth ,
13
13
showDebugCoordinates : false ,
14
- } ) ;
14
+ } ;
15
+
16
+ export const SettingsContext = createContext ( defaultSettings ) ;
15
17
16
18
export default function SettingsContextProvider ( { children } ) {
17
- const [ settings , setSettings ] = useState ( {
18
- strictMode : false ,
19
- showFieldSummary : true ,
20
- showGrid : true ,
21
- mode : "light" ,
22
- autosave : true ,
23
- panning : true ,
24
- showCardinality : true ,
25
- tableWidth : tableWidth ,
26
- showDebugCoordinates : false ,
27
- } ) ;
19
+ const [ settings , setSettings ] = useState ( defaultSettings ) ;
20
+
21
+ useEffect ( ( ) => {
22
+ const settings = localStorage . getItem ( "settings" ) ;
23
+ if ( settings ) {
24
+ setSettings ( JSON . parse ( settings ) ) ;
25
+ }
26
+ } , [ ] ) ;
27
+
28
+ useEffect ( ( ) => {
29
+ localStorage . setItem ( "settings" , JSON . stringify ( settings ) ) ;
30
+ } , [ settings ] ) ;
28
31
29
32
return (
30
33
< SettingsContext . Provider value = { { settings, setSettings } } >
You can’t perform that action at this time.
0 commit comments