-
-
Notifications
You must be signed in to change notification settings - Fork 63
feat: Implement automatic code saving and loading to local storage #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b64690e
d2facc1
699b131
fcfcce7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -133,8 +133,39 @@ function EditorComponent() { | |||||
| DEFAULT_LANGUAGE: selectedLanguage.DEFAULT_LANGUAGE, | ||||||
| NAME: selectedLanguage.NAME, | ||||||
| }); | ||||||
| setCode(selectedLanguage.HELLO_WORLD); | ||||||
| }, [currentLanguage]); | ||||||
| let savedCode = null; | ||||||
| try { | ||||||
| savedCode = localStorage.getItem(`code-${selectedLanguage.DEFAULT_LANGUAGE}`); | ||||||
| } catch (e) { | ||||||
| enqueueSnackbar("Failed to load saved code. Local storage might be unavailable.", { variant: "error" }); | ||||||
| console.error("Local storage load error:", e); | ||||||
| } | ||||||
|
|
||||||
| if (savedCode !== null) { | ||||||
| setCode(savedCode); | ||||||
| } else { | ||||||
| setCode(selectedLanguage.HELLO_WORLD); | ||||||
| } }, [currentLanguage, enqueueSnackbar]); | ||||||
|
|
||||||
| useEffect(() => { | ||||||
| if (isImportingRef.current) return; | ||||||
|
|
||||||
| const handler = setTimeout(() => { | ||||||
| try { | ||||||
| if (code) { | ||||||
| localStorage.setItem(`code-${currentLanguage}`, code); | ||||||
| } else { | ||||||
| localStorage.removeItem(`code-${currentLanguage}`); | ||||||
| } | ||||||
|
Comment on lines
+155
to
+159
|
||||||
| } catch (e) { | ||||||
| enqueueSnackbar("Failed to save code automatically. Local storage might be full or unavailable.", { variant: "error" }); | ||||||
| console.error("Local storage save error:", e); | ||||||
| } }, 500); // 500ms debounce | ||||||
|
||||||
| } }, 500); // 500ms debounce | |
| } }, 500); // 500ms debounce |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra whitespace before the closing brace. The closing brace should be on its own line or immediately follow the closing brace of the if-else statement.