Skip to content

Fixed : Reset Code Button - #172

Merged
aviralsaxena16 merged 1 commit into
OpenLake:mainfrom
Eashan-H:fix-reset-code
May 22, 2026
Merged

Fixed : Reset Code Button#172
aviralsaxena16 merged 1 commit into
OpenLake:mainfrom
Eashan-H:fix-reset-code

Conversation

@Eashan-H

@Eashan-H Eashan-H commented May 22, 2026

Copy link
Copy Markdown
Contributor

Related Issue


Changes Introduced

  • Fixed: Reset button in the code editor now correctly restores the editor to the original template code.

Why This Change?

  • Problem: The Reset button in the IDE code editor was non-functional clicking it had no effect, leaving users unable to restore starter code.
  • Solution: Fixed the Reset button logic so it correctly resets the editor content back to the default template code.
  • Impact: All users of the code editor can now reliably reset their code to the starter template when needed.

🖼️ Screenshots / Loom Video (if applicable)

|
image

image |

Summary by CodeRabbit

  • New Features
    • Added code reset capability to the editor that restores the default code snippet for the currently selected language and displays a success confirmation to the user.

Review Change Stack

@Eashan-H
Eashan-H requested a review from aviralsaxena16 as a code owner May 22, 2026 08:55
@vercel

vercel Bot commented May 22, 2026

Copy link
Copy Markdown

@Eashan-H is attempting to deploy a commit to the aviralsaxena16's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown

🎉 Thanks for Your Contribution to CanonForces! ☺️

We'll review it as soon as possible. In the meantime, please:

  • ✅ Double-check the file changes.
  • ✅ Ensure that all commits are clean and meaningful.
  • ✅ Link the PR to its related issue (e.g., Closes #123).
  • ✅ Resolve any unaddressed review comments promptly.

💬 Need help or want faster feedback?
Join our Discord 👉 CanonForces Discord

Thanks again for contributing 🙌 – @Eashan-H!
cc: @aviralsaxena16

@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown

Walkthrough

CodeEditor component now accepts an optional onResetCode callback that fires when the reset button is clicked. The questions page implements handleResetCode to restore code to the default template snippet and display a success toast, wiring it to CodeEditor via the new prop.

Changes

Code editor reset callback wiring

Layer / File(s) Summary
CodeEditor onResetCode callback support
src/common/components/CodeEditor/CodeEditor.tsx
CodeEditor Props type adds optional onResetCode?: () => void. The prop is destructured and invoked in the resetCode handler, replacing console logging.
Questions page reset handler and integration
src/pages/questions/[id].tsx
handleResetCode resets codeValue to the default snippet for the current language and displays a success toast. The handler is passed to CodeEditor via onResetCode prop.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A button once broken, now springs to life,
Resetting the code with minimal strife,
From editor to page, the callback flows free,
Templates restored for all coders to see! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fixed : Reset Code Button' directly relates to the main change in the PR, which is fixing the non-functional reset button in the code editor.
Description check ✅ Passed The PR description covers the key required sections: related issue link, changes introduced, problem/solution/impact explanation, and screenshots demonstrating the fix with the success notification.
Linked Issues check ✅ Passed The code changes fully address the requirements in issue #171 by implementing the reset button functionality to restore editor content to the original template code.
Out of Scope Changes check ✅ Passed All changes in CodeEditor.tsx and [id].tsx are directly scoped to implementing the reset code functionality as specified in issue #171, with no unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/pages/questions/[id].tsx (1)

120-123: ⚡ Quick win

Clear stale output/submission state when resetting code.

After reset, previous run/submission results remain visible, which can make reset look partial. Consider resetting those panes in the same handler.

Suggested patch
   const handleResetCode = () => {
     setCodeValue(CODE_SNIPPETS[language as keyof typeof CODE_SNIPPETS]);
+    setOutput(null);
+    setSubmissionResult(null);
     toast.success('Code reset to default')
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/questions/`[id].tsx around lines 120 - 123, The handleResetCode
handler only resets code and shows a toast but leaves prior run/submission state
visible; update handleResetCode to also clear any related UI state (e.g. output
pane, run/submission results, running flags) by calling the relevant setters
used in this component (for example, setOutput, setSubmission, setRunResults,
setIsRunning or whatever your state variables are named) immediately after
setCodeValue(CODE_SNIPPETS[language as keyof typeof CODE_SNIPPETS]) so the UI
fully returns to its initial state when toast.success('Code reset to default')
is shown.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/pages/questions/`[id].tsx:
- Around line 120-123: The handleResetCode handler only resets code and shows a
toast but leaves prior run/submission state visible; update handleResetCode to
also clear any related UI state (e.g. output pane, run/submission results,
running flags) by calling the relevant setters used in this component (for
example, setOutput, setSubmission, setRunResults, setIsRunning or whatever your
state variables are named) immediately after setCodeValue(CODE_SNIPPETS[language
as keyof typeof CODE_SNIPPETS]) so the UI fully returns to its initial state
when toast.success('Code reset to default') is shown.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f85c19f2-b81d-422a-9ea1-bd7777dd9d98

📥 Commits

Reviewing files that changed from the base of the PR and between 89072b4 and 9e95673.

📒 Files selected for processing (2)
  • src/common/components/CodeEditor/CodeEditor.tsx
  • src/pages/questions/[id].tsx

@aviralsaxena16
aviralsaxena16 merged commit b0d3513 into OpenLake:main May 22, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Clicking the Reset button in the code editor does not reset the code to its original template code.

2 participants