Skip to content

[Feature] Preserve in-progress quiz answers across modal close and page refresh #38

Closed

Description

@spandan11106

All quiz answers live only in React component state, so a single page refresh, accidental back-button, or closing the modal throws away the attempt in progress.

Details

  • frontend/src/components/DayModal.jsx keeps answers and step in useState. handleAnswer auto-advances and only calls onSubmit on the last question — so for any quiz longer than a couple of questions there is a real window where a refresh loses everything.
  • Closing the modal unmounts the component and resets all state.
  • The backend allows exactly one scored attempt per quiz (quizController.submitQuiz returns 409 [CONFLICT] This quiz can only be submitted once.), so the user's only option after a refresh is to start the quiz over from scratch and lose whatever they had selected.

Tasks / Requirements

  • Persist the in-progress draft (selected answers + current step) to sessionStorage keyed by quiz/day id, and restore it when the modal reopens or the page reloads.
  • Clear the draft immediately after a successful submit (and on "Start over", if offered) so a stale draft can never be replayed against a taken quiz.
  • Never send the draft to the server — the one-attempt rule and server-side grading in quizController.submitQuiz must stay authoritative.
  • Guard against corrupted/older drafts (question count changed, malformed JSON) by falling back to a fresh attempt.
  • Keep the existing "already attempted → results view" behaviour for quizzes in progress.attemptedQuizIds.

Activity

  1. adityamukesh commented on Oct 8, 2026

    @adityamukesh

    Hey team! I can implement persistence for in-progress quiz answers to prevent accidental data loss.

    Proposed Implementation:

    1. In frontend/src/components/DayModal.jsx, synchronize answers and step state with localStorage (keyed by quiz_progress_${quizId}_${userId}).
    2. On component mount, initialize state by hydrating from storage if a valid unsubmitted attempt exists.
    3. Clear the stored draft upon successful quiz submission.
    4. Add an optional "Resume quiz?" indicator or clear button if the student wants to start fresh.

    This will protect students from lost progress on modal close or browser reload. May I be assigned this issue?

  2. spandan11106 commented on Oct 9, 2026

    @spandan11106
    CollaboratorAuthor

    Thanks for volunteering, @adityamukesh! Assigning this to you. Please go ahead with the persistence approach. Just make sure the draft only clears on a genuinely successful submit, and validate/ignore stale or malformed drafts. Feel free to open a WIP PR if you want early feedback

  3. spandan11106 commented on Oct 21, 2026

    @spandan11106
    CollaboratorAuthor

    @adityamukesh any updates on this. Also before you raise a pr register on the Hacktober website to get on the leaderboard.

  4. added a commit that references this issue on Oct 27, 2026
    ff91283
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions