add reset code functionality to restore original starter code in CodeChallenge component
This commit is contained in:
@@ -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 = () => {
|
||||
<option value="C++">C++</option>
|
||||
<option value="C">C</option>
|
||||
</select>
|
||||
<button className="reset-code-btn">
|
||||
<button
|
||||
className="reset-code-btn"
|
||||
onClick={handleResetCode}
|
||||
disabled={isRunning}
|
||||
title="Reset code to original starter template"
|
||||
>
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polyline points="16 18 22 12 16 6"></polyline>
|
||||
<polyline points="8 6 2 12 8 18"></polyline>
|
||||
|
||||
Reference in New Issue
Block a user