From 33b9e2fe382291ee0cbfca513db2066db8698605 Mon Sep 17 00:00:00 2001 From: ishikabhoyar Date: Mon, 3 Nov 2025 20:02:01 +0530 Subject: [PATCH] add reset code functionality to restore original starter code in CodeChallenge component --- Frontend/src/components/CodeChallenge.jsx | 33 ++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/Frontend/src/components/CodeChallenge.jsx b/Frontend/src/components/CodeChallenge.jsx index fba04df..801af45 100644 --- a/Frontend/src/components/CodeChallenge.jsx +++ b/Frontend/src/components/CodeChallenge.jsx @@ -621,6 +621,32 @@ const CodeChallenge = () => { } }; + // Handle reset code + const handleResetCode = () => { + const currentQuestion = getCurrentQuestion(); + if (!currentQuestion) return; + + const confirmReset = window.confirm( + 'Are you sure you want to reset the code? This will restore the original starter code and you will lose all your current changes.' + ); + + if (!confirmReset) return; + + // Clear saved submission from localStorage + if (test && currentQuestion) { + localStorage.removeItem(`submission_${test.id}_${currentQuestion.id}`); + } + + // Reset to original code template + const originalCode = currentQuestion.code_template || getDefaultTemplate(currentQuestion.programming_language || language); + setCode(originalCode); + + // Clear terminal output + setTerminalOutput([ + { type: 'system', content: '✓ Code reset to original starter code' } + ]); + }; + // Handle final test submission const handleSubmitTest = async () => { if (!test) { @@ -883,7 +909,12 @@ const CodeChallenge = () => { -