Skip to content

Commit

Permalink
fix(state-local-storage): add precision just 2 digit float to store i…
Browse files Browse the repository at this point in the history
…n the global state
  • Loading branch information
jerensl committed Jul 19, 2024
1 parent d558246 commit 97c5b94
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ const PlaygroundtLayoutContext = createContext<

const localStorageInitializer = (initialValue = initialState) => {
if (typeof window !== 'undefined') {
const resizablePercentageOpen = JSON.parse(localStorage.getItem(LocalStorageKey)!) ?? 0.5;
const newValue = {
...initialValue,
editorSize: resizablePercentageOpen
};
const resizablePercentageOpen = localStorage.getItem(LocalStorageKey);

return newValue;
if (resizablePercentageOpen !== null) {
const size = JSON.parse(resizablePercentageOpen);
const newValue = {
...initialValue,
editorSize: parseFloat(size.editorSize)
};

return newValue;
}
}

return initialValue;
Expand Down Expand Up @@ -57,7 +61,7 @@ function PlaygroundLayoutProvider({ children }: PlaygroundtProviderProps) {

useEffect(() => {
localStorage.setItem(LocalStorageKey, JSON.stringify({ editorSize: state.editorSize }));
}, [state]);
}, [state.editorSize]);

useEffect(() => {
if (width !== null) {
Expand Down
2 changes: 1 addition & 1 deletion modelina-website/src/components/playground/Resizable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Resizable({ leftComponent, rightComponent }: ResizableComponentProps) {
if (containerWidth !== null) {
const visibleView = value / containerWidth;

dispatch({ type: 'resizable-size', total: visibleView });
dispatch({ type: 'resizable-size', total: parseFloat(visibleView.toFixed(2)) });
}

return `${value + 0.5 * 4}px`;
Expand Down

0 comments on commit 97c5b94

Please sign in to comment.