File tree Expand file tree Collapse file tree 1 file changed +17
-14
lines changed Expand file tree Collapse file tree 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" ;
22import { tableWidth } from "../data/constants" ;
33
4- export const SettingsContext = createContext ( {
4+ const defaultSettings = {
55 strictMode : false ,
66 showFieldSummary : true ,
77 showGrid : true ,
@@ -11,20 +11,23 @@ export const SettingsContext = createContext({
1111 showCardinality : true ,
1212 tableWidth : tableWidth ,
1313 showDebugCoordinates : false ,
14- } ) ;
14+ } ;
15+
16+ export const SettingsContext = createContext ( defaultSettings ) ;
1517
1618export 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 ] ) ;
2831
2932 return (
3033 < SettingsContext . Provider value = { { settings, setSettings } } >
You can’t perform that action at this time.
0 commit comments