Repository navigation
Preserve in-progress quiz answers across modal close and reload - #48
Merged
Merged
Conversation
Save the selected answers and current step of an unsubmitted daily quiz to sessionStorage (keyed by day id) and restore them when the quiz is reopened, with "Resume Quiz" and "Start over" options on the start view. The draft is only cleared once the server accepts the submission: handleDayAction now resolves to true/false instead of swallowing the error, so a failed submit keeps the answers for a retry. Drafts are also dropped for quizzes already in progress.attemptedQuizIds, and drafts that are malformed or were taken against a different version of the quiz are ignored. The draft never goes to the server; grading and the one-attempt rule stay in quizController.submitQuiz. Adds node:test coverage for the draft helpers (npm test in frontend/). Closes swciitg#38 Co-Authored-By: Claude Opus 5.5 <[email protected]>
adityamukesh
marked this pull request as ready for review
October 22, 2026 18:03
🤖 CodeAnt AI — Review Status
|
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
| } | ||
|
|
||
| export function getQuizDraftKey(dayId) { | ||
| return `hs.quizDraft.${dayId}`; |
There was a problem hiding this comment.
Suggestion: Because this key omits the user, another account using the same tab can see and resume the prior account’s saved answers for that day.
Assessment: 🟠 Major · 🔁 Occurrence: Rarely · 🏷️ Security
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** frontend/src/utils/quizDraft.js
**Line:** 14:14
**Comment:**
*Security: Because this key omits the user, another account using the same tab can see and resume the prior account’s saved answers for that day.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
CodeAnt Nitpicks2 code suggestions1. If the server saves the attempt but a later score update fails, this retains a draft that the server rejects as already attempted on retry.Api mismatch · 2. When an unregistered learner finishes a quiz, this silently skips submission, while the quiz view still says it was completed although no attempt was recorded.Api mismatch · |
CodeAnt PR Risk: Medium Risk
Assessed commit: |
Author
|
please review it |
Author
|
please review it. |
rgajbhiyee
approved these changes
Oct 27, 2026
Collaborator
|
Thank you @adityamukesh for your contribution, we request you to please register on https://swc.iitg.ac.in/hacktoberfest/ website |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Description
Closes #38
Quiz answers lived only in
DailyQuizcomponent state, so a page refresh, accidental back-navigation, or closing the day modal threw away the attempt in progress.What changes
DailyQuizsaves{ step, answers }tosessionStorageunderhs.quizDraft.<dayId>after each answer and restores it when the quiz mounts again (modal reopened or page reloaded). When a draft exists, the start screen shows "N of M answered", Resume Quiz, and Start over (which deletes the draft).ModuleDetail.handleDayActionused to catch and swallow submit errors, soDayModalcouldn't tell success from failure; it now resolvestrue/false(the error banner behaviour is unchanged). On failure the full draft is kept so the attempt can be retried after reopening.dailyQuizAttempt, fromprogress.attemptedQuizIds/quizScores) never restore a draft, and any leftover draft for them is deleted. The existing results view is unchanged.frontend/src/utils/quizDraft.js. Malformed JSON, an unknown version, answers that aren't valid option indexes, a step that doesn't match the answers, or a quiz whose questions or options changed all fall back to a fresh attempt; the last check uses a fingerprint of question text and options, which also catches question-count changes. Storage errors (disabled storage, quota) are caught, so the quiz still works without a draft.answersarray as before, and grading plus the one-attempt rule stay inquizController.submitQuiz.Notes for reviewers
sessionStorage: it survives reloads and modal close, is scoped to the tab, and disappears when the tab closes.npm testscript infrontend/that runs Node's built-innode --testrunner. No new dependencies. It's easy to drop if you'd rather not have it.Type of change
How has this been tested?
AI assistance: this change was written with Claude Code (an AI coding agent), which also ran the checks and the browser walkthrough below.
Automated
cd frontend && npm testpasses 14/14. The tests cover:The same test file fails against
mainbecause the helper module doesn't exist there.cd frontend && npm run buildsucceeds.cd frontend && npm run lintfails, but identically onmainand on this branch: 55 errors and 4 warnings, with no per-file differences. The new files lint clean. The one error reported inDayModal.jsx(react-hooks/set-state-in-effect) is the existingsetViewMode("results")inside the effect.End-to-end on a local stack (backend, a local MongoDB seeded with one module of two days, a 3-question quiz per day and a registered test user, and the Vite dev server)
userAnswers: [1, 1, 2](including the answers chosen before the reload) with a score of 15/20, and the draft was removed.{not valid json) fell back to a fresh "Start Quiz".No runtime errors appeared in the console. The only console entries were network 401s (this PR adds no requests) and the deliberate 502.
Screenshots
Checklist
maincd frontend && npm run lintpasses (frontend changes): it fails onmainwith the same 55 errors and this PR adds no new lint problems (see above)README.md/backend/.env.example/frontend/.env.exampleif I changed setup, env vars, or API routes: n/a, no setup, env or API route changes.envfiles, ornode_modules🤖 Generated with Claude Code
CodeAnt-AI Description
Preserve unfinished quiz answers across modal closes and reloads
What Changed
Impact
✅ Fewer lost quiz attempts✅ Faster retries after submission errors✅ No stale answers on edited quizzes💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.