feat: add admin reset action for active question answers with attendee answer clear#66
Conversation
📝 WalkthroughWalkthroughA new admin capability to reset answers for the active question is introduced. The feature includes a server API endpoint that clears answers and broadcasts a WebSocket event, client-side handlers to restore or clear stored answers, and admin UI controls in the questions and results pages with confirmation dialogs and localized labels. ChangesAnswer Reset Feature
Sequence DiagramsequenceDiagram
actor Admin
participant Questions Page
participant API Endpoint
participant Storage
participant WebSocket
participant Client Composable
Admin->>Questions Page: Click "Reset Answers"
Questions Page->>Questions Page: Show confirmation dialog
Admin-->>Questions Page: Confirm
Questions Page->>API Endpoint: POST /api/answers/reset
API Endpoint->>Storage: clearAnswersForQuestion(questionId)
Storage->>Storage: Delete all answers for question
API Endpoint->>WebSocket: Broadcast answers-reset event
WebSocket->>Client Composable: answers-reset message
Client Composable->>Client Composable: clearStoredAnswer(questionId)
API Endpoint->>WebSocket: Broadcast results-update event
WebSocket->>Client Composable: results-update message
API Endpoint-->>Questions Page: { success: true, questionId }
Questions Page->>Questions Page: Reload questions
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Review rate limit: 3/5 reviews remaining, refill in 12 minutes and 26 seconds. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
app/pages/admin/questions.vue (1)
270-295: ⚡ Quick winAdd a brief JSDoc for
resetAnswers().The function is good; it just needs a short doc comment for consistency with repo standards.
As per coding guidelines, "Brief JSDoc on all functions."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/pages/admin/questions.vue` around lines 270 - 295, Add a brief JSDoc block above the async function resetAnswers() that summarizes its purpose (prompts the user, posts to /api/answers/reset, reloads questions, and handles errors), documents that it is asynchronous and returns a Promise<void>, and notes side effects (uses window.confirm, updates isResettingAnswers.value, calls loadQuestions(), and may show an alert). Keep the comment concise (one- or two-line summary plus `@returns` Promise<void> and an optional `@throws/notes` line about error handling).app/composables/useQuizSocket.ts (1)
12-32: ⚡ Quick winAdd brief JSDoc for the new helper functions.
Both newly introduced helpers are clear, but they should include short JSDoc to match repo standards.
Suggested update
+/** Clear in-memory and session-stored answer for a question. */ function clearStoredAnswer(questionId: string) { selectedAnswer.value = null if (import.meta.client) { sessionStorage.removeItem(`answer-${questionId}`) } } +/** Restore a previously stored answer for a question from session storage. */ function restoreStoredAnswer(questionId: string) { if (!import.meta.client) { selectedAnswer.value = null return }As per coding guidelines, "Brief JSDoc on all functions."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/composables/useQuizSocket.ts` around lines 12 - 32, Add brief JSDoc comments for the two helper functions clearStoredAnswer and restoreStoredAnswer: above clearStoredAnswer describe that it clears the in-memory selectedAnswer and removes the sessionStorage key for the provided questionId (include `@param` {string} questionId), and above restoreStoredAnswer describe that it reads the sessionStorage key for questionId, parses it to an integer, validates non-negative integer and sets selectedAnswer accordingly or null (include `@param` {string} questionId and `@returns` {void} or note no return). Also mention the client-only behavior (checks import.meta.client) in the JSDoc to clarify server vs client side effects.app/pages/admin/results.vue (1)
208-230: ⚡ Quick winAdd a brief JSDoc for
resetAnswers().Please add a short doc comment above this new function to align with project conventions.
As per coding guidelines, "Brief JSDoc on all functions."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/pages/admin/results.vue` around lines 208 - 230, Add a brief JSDoc block immediately above the async function resetAnswers() describing its purpose (resets all answers after user confirmation), noting it is asynchronous and returns a Promise<void>, and listing side effects such as updating isResettingAnswers.value, calling the /api/answers/reset via $fetch, invoking refreshResults(), and handling errors (logged via logger_error); keep it short (one to three lines) and follow the project's JSDoc style.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@app/composables/useQuizSocket.ts`:
- Around line 12-32: Add brief JSDoc comments for the two helper functions
clearStoredAnswer and restoreStoredAnswer: above clearStoredAnswer describe that
it clears the in-memory selectedAnswer and removes the sessionStorage key for
the provided questionId (include `@param` {string} questionId), and above
restoreStoredAnswer describe that it reads the sessionStorage key for
questionId, parses it to an integer, validates non-negative integer and sets
selectedAnswer accordingly or null (include `@param` {string} questionId and
`@returns` {void} or note no return). Also mention the client-only behavior
(checks import.meta.client) in the JSDoc to clarify server vs client side
effects.
In `@app/pages/admin/questions.vue`:
- Around line 270-295: Add a brief JSDoc block above the async function
resetAnswers() that summarizes its purpose (prompts the user, posts to
/api/answers/reset, reloads questions, and handles errors), documents that it is
asynchronous and returns a Promise<void>, and notes side effects (uses
window.confirm, updates isResettingAnswers.value, calls loadQuestions(), and may
show an alert). Keep the comment concise (one- or two-line summary plus `@returns`
Promise<void> and an optional `@throws/notes` line about error handling).
In `@app/pages/admin/results.vue`:
- Around line 208-230: Add a brief JSDoc block immediately above the async
function resetAnswers() describing its purpose (resets all answers after user
confirmation), noting it is asynchronous and returns a Promise<void>, and
listing side effects such as updating isResettingAnswers.value, calling the
/api/answers/reset via $fetch, invoking refreshResults(), and handling errors
(logged via logger_error); keep it short (one to three lines) and follow the
project's JSDoc style.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 7fa5572e-6e84-42de-ad63-5974cc04a421
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml,!pnpm-lock.yaml
📒 Files selected for processing (8)
app/composables/useQuizSocket.tsapp/pages/admin/questions.vueapp/pages/admin/results.vuedocs/api.mddocs/websocket.mdpackage.jsonserver/api/answers/reset.post.tsserver/utils/storage.ts
💤 Files with no reviewable changes (1)
- package.json
Summary by CodeRabbit
New Features
Documentation
Chores