Skip to content

Commit

Permalink
Refactor of autoSave and setAutoSave in canvas-view-settings-provider…
Browse files Browse the repository at this point in the history
….tsx
  • Loading branch information
Ivanruii committed Apr 9, 2024
1 parent 3b04103 commit 8a49f8b
Showing 1 changed file with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,17 @@ export const CanvasViewSettingsProvider: React.FC<Props> = props => {
y: 0,
});

const savedSettingsString = retrieveValueFromLocalStorage(USERSAVE_KEY);
const savedSettings = savedSettingsString
? savedSettingsString
: { autoSave: true };
const savedSettingsObject = retrieveValueFromLocalStorage(USERSAVE_KEY);

const [autoSave, setAutoSave] = React.useState<boolean>(savedSettings);
const initialValue =
savedSettingsObject && savedSettingsObject.autoSave !== undefined
? savedSettingsObject.autoSave
: true;

React.useEffect(() => {
if (
savedSettings &&
typeof savedSettings === 'object' &&
'autoSave' in savedSettings
) {
setAutoSave(savedSettings.autoSave);
}
}, []);
const [autoSave, setAutoSave] = React.useState<boolean>(initialValue);

React.useEffect(() => {
saveValueToLocalStorage(USERSAVE_KEY, { autoSave });
saveValueToLocalStorage(USERSAVE_KEY, { autoSave: autoSave });
}, [autoSave]);

const zoomIn = () =>
Expand Down

0 comments on commit 8a49f8b

Please sign in to comment.