Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions src/pages/EditorComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Copy link

Copilot AI Oct 31, 2025

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.

Suggested change
} }, [currentLanguage, enqueueSnackbar]);
}}, [currentLanguage, enqueueSnackbar]);

Copilot uses AI. Check for mistakes.

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
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The auto-save logic removes code from localStorage when code is empty/falsy, but empty string is a valid code state. This means users cannot save an empty editor state and will always get the HELLO_WORLD template instead. Consider checking for null/undefined specifically: if (code !== null && code !== undefined).

Copilot uses AI. Check for mistakes.
} 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
Copy link

Copilot AI Oct 31, 2025

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. There should be proper formatting with the closing brace on a new line or a single space.

Suggested change
} }, 500); // 500ms debounce
} }, 500); // 500ms debounce

Copilot uses AI. Check for mistakes.

return () => {
clearTimeout(handler);
};
}, [code, currentLanguage, enqueueSnackbar]);

const handleEditorThemeChange = async (_, theme) => {
if (["light", "vs-dark"].includes(theme.ID)) {
Expand Down