Skip to content

Commit

Permalink
Store compressed editor code in local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleect committed Nov 7, 2023
1 parent d3b346d commit d479df3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions playground/src/pages/playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,17 @@ const Playground: React.FC = () => {
return;
}

const hash = `#/code=${compressToEncodedURIComponent(editorText)}`;
const compressedText = compressToEncodedURIComponent(editorText);

const hash = `#/code=${compressedText}`;

if (history.replaceState) {
history.replaceState(null, '', hash);
} else {
location.hash = hash;
}

LocalStorage.editorText = editorText;
LocalStorage.editorText = compressedText;
}, [editorText]);

useEffect(() => {
Expand All @@ -84,7 +86,10 @@ const Playground: React.FC = () => {
userCode = decompressFromEncodedURIComponent(decodeURIComponent(code));
setEditorText(userCode);
} else if (LocalStorage.editorText) {
setEditorText(LocalStorage.editorText);
const decompressedCode = decompressFromEncodedURIComponent(
LocalStorage.editorText,
);
setEditorText(decompressedCode);
}
}, []);

Expand Down

0 comments on commit d479df3

Please sign in to comment.