Skip to content

Commit d7d3cdc

Browse files
committed
Cache settings
1 parent f27fbaa commit d7d3cdc

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

Diff for: src/context/SettingsContext.jsx

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { createContext, useState } from "react";
1+
import { createContext, useEffect, useState } from "react";
22
import { 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

1618
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]);
2831

2932
return (
3033
<SettingsContext.Provider value={{ settings, setSettings }}>

0 commit comments

Comments
 (0)