Skip to content

Commit

Permalink
Cache settings
Browse files Browse the repository at this point in the history
  • Loading branch information
1ilit committed Nov 8, 2024
1 parent f27fbaa commit d7d3cdc
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/context/SettingsContext.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext, useState } from "react";
import { createContext, useEffect, useState } from "react";
import { tableWidth } from "../data/constants";

export const SettingsContext = createContext({
const defaultSettings = {
strictMode: false,
showFieldSummary: true,
showGrid: true,
Expand All @@ -11,20 +11,23 @@ export const SettingsContext = createContext({
showCardinality: true,
tableWidth: tableWidth,
showDebugCoordinates: false,
});
};

export const SettingsContext = createContext(defaultSettings);

export default function SettingsContextProvider({ children }) {
const [settings, setSettings] = useState({
strictMode: false,
showFieldSummary: true,
showGrid: true,
mode: "light",
autosave: true,
panning: true,
showCardinality: true,
tableWidth: tableWidth,
showDebugCoordinates: false,
});
const [settings, setSettings] = useState(defaultSettings);

useEffect(() => {
const settings = localStorage.getItem("settings");
if (settings) {
setSettings(JSON.parse(settings));
}
}, []);

useEffect(() => {
localStorage.setItem("settings", JSON.stringify(settings));
}, [settings]);

return (
<SettingsContext.Provider value={{ settings, setSettings }}>
Expand Down

0 comments on commit d7d3cdc

Please sign in to comment.