Skip to content

fix: improve app-wide code health - #1

Merged
Truella merged 8 commits into
masterfrom
fix/code-health
Jul 22, 2026
Merged

fix: improve app-wide code health#1
Truella merged 8 commits into
masterfrom
fix/code-health

Conversation

@Truella

@Truella Truella commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Summary
Six code health fixes found during grounded gap analysis: CSV parser correctly handles lowercase and whitespace-padded correct answers; useAuth split into its own file; saveProgress and clearProgress wrapped in useCallback; fetchQuizData wrapped in useCallback; DBQuestion/AppQuestion type layer introduced with transforms.ts; and handlers.ts replaced by useCreateQuiz hook.

Changed files

  • src/utils/csvParser.ts
  • src/context/AuthContext.tsx
  • src/hooks/useAuth.ts (new)
  • src/hooks/useQuizProgress.ts
  • src/hooks/useTakeQuiz.ts
  • src/lib/types.ts
  • src/utils/transforms.ts (new)
  • src/utils/helpers.ts
  • src/hooks/useCreateQuiz.ts (new)
  • src/utils/handlers.ts (deleted)
  • src/views/CreateQuiz.tsx
  • src/components/CreateQuizForm.tsx
  • src/components/UploadQuestionsForm.tsx
  • src/components/quiz/QuizResults.tsx

Checklist

  • npx tsc --noEmit passes with zero errors
  • npx next lint passes with zero errors and warnings
  • handlers.ts is deleted
  • CSV quiz creation works end-to-end
  • Quiz taking and scoring work end-to-end
  • No console.log statements left in code
  • Branch up to date with main

Summary by CodeRabbit

  • New Features
    • Added quiz timer support (auto-submit, elapsed/remaining) and a more complete quiz editor with draft persistence.
    • Introduced AI-assisted quiz review and a public quiz bank (publish, browse, ratings).
    • Added a public /docs section and improved accessibility/polish (titles/OG tags, keyboard shortcuts).
  • Bug Fixes
    • CSV upload validation now ignores blanks and normalizes answer labels before checking.
    • Quiz progress now saves more reliably while taking a quiz.
    • Updated question display/review/results to consistently match the stored format.
  • Chores
    • Improved linting/tooling configuration and TypeScript cache ignores.

@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
prep Ready Ready Preview, Comment Jul 22, 2026 5:52pm

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR centralizes quiz creation state, introduces database/application question transformations, updates quiz-taking and review components, extracts useAuth, stabilizes hook effects, improves CSV validation, and updates lint configuration and enhancement documentation.

Changes

Quiz workflow refactor

Layer / File(s) Summary
Question model and validation
src/lib/types.ts, src/utils/transforms.ts, src/utils/csvParser.ts, src/utils/helpers.ts
Adds DBQuestion/AppQuestion separation, bidirectional field transformations, and normalized CSV validation.
Auth and quiz hook extraction
src/context/AuthContext.tsx, src/hooks/useAuth.ts, src/hooks/useQuizProgress.ts, src/hooks/useTakeQuiz.ts, src/components/..., src/views/Auth/AuthForm.tsx
Moves useAuth to its own hook and memoizes quiz loading and progress helpers with updated dependencies.
Centralized quiz creation workflow
src/hooks/useCreateQuiz.ts, src/views/CreateQuiz.tsx, src/components/CreateQuizForm.tsx, src/components/UploadQuestionsForm.tsx
Centralizes quiz creation, CSV loading, question upload, shareable-link generation, and controlled form state.
Application question consumers
src/components/quiz/*
Updates question cards, results, and review rendering and scoring to use AppQuestion fields and indexes.
Lint configuration and enhancement playbook
.gitignore, eslint.config.mjs, package.json, docs/prt.md
Updates ESLint setup and scripts, ignores TypeScript build caches, and expands the enhancement prompt documentation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CreateQuizCSV
  participant useCreateQuiz
  participant csvParser
  participant Supabase
  participant Clipboard
  CreateQuizCSV->>useCreateQuiz: submit quiz metadata
  useCreateQuiz->>Supabase: insert quiz row
  CreateQuizCSV->>useCreateQuiz: select CSV file
  useCreateQuiz->>csvParser: parseAndValidateCSV
  csvParser-->>useCreateQuiz: validated question rows
  useCreateQuiz->>Supabase: insert mapped questions
  useCreateQuiz->>Clipboard: copy shareable quiz URL
Loading
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is related to the PR, but it is too broad and non-descriptive to convey the main changes. Rename it to reflect the primary change, such as updating CSV validation, auth hooks, and quiz type/handler refactors.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/code-health

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 10

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/hooks/useTakeQuiz.ts (1)

31-77: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Prevent stale quiz requests from overwriting the active quiz src/hooks/useTakeQuiz.ts:31-77

A slower request for a previous quizId can still finish after navigation and call setQuiz, setQuestions, setError, or toast.error, leaving the new session with the wrong quiz state. Add cleanup/versioning (or abort the request) and skip updates for stale responses.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useTakeQuiz.ts` around lines 31 - 77, Update fetchQuizData and its
useEffect cleanup so requests for an outdated quizId cannot update quiz state,
loading/error state, or show toast errors after navigation. Track request
activity with an abort signal or request version, invalidate it during effect
cleanup, and guard both success and catch updates while preserving updates for
the active request.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/prt.md`:
- Around line 1489-1495: Update the documented successful upload flow to remove
the "quiz_builder_draft" localStorage entry immediately after the quiz insert
succeeds, ensuring subsequent refreshes cannot restore stale builder questions.
- Line 109: Update the lint verification instructions in docs/prt.md to use npm
run lint instead of npx next lint at all referenced occurrences, while
preserving the surrounding verification steps.
- Around line 588-626: Update the test configuration in vitest.config.ts to set
test.passWithNoTests to true, ensuring the existing npm test and coverage
scripts exit successfully when no test files are present.
- Around line 1513-1527: Update createQuiz() so its Supabase insert payload maps
the local timeLimit state to the database time_limit field, preserving null or
undefined handling as appropriate for optional values.

In `@package.json`:
- Line 10: Update the package.json lint script to run ESLint against the app/
routes in addition to src/, preferably by targeting the repository root with
eslint ..

In `@src/components/CreateQuizForm.tsx`:
- Around line 50-53: Update CreateQuizForm’s form submission flow so pressing
Enter in the title field creates the quiz: attach the existing onSubmit handler
to the form’s onSubmit prop and make the submit button type="submit" instead of
type="button", while preserving its disabled condition.

In `@src/hooks/useCreateQuiz.ts`:
- Around line 101-125: Update uploadQuestions in useCreateQuiz so a successfully
published quiz cannot be submitted again: guard against the existing
published/shareable state before inserting questions, and ensure the related
upload control uses that state to remain disabled after success. Preserve an
explicit replace flow only if one already exists.
- Around line 73-77: Remove the exact file.type === "text/csv" rejection from
setQuestionsFromCSV so files with empty or alternate MIME types reach
parseAndValidateCSV. Preserve the parser’s validation flow and avoid adding a
replacement MIME check.
- Around line 122-125: Update the quiz publishing flow around the clipboard
write in useCreateQuiz so navigator.clipboard.writeText is awaited before
showing the success toast. Preserve the shareableLink state update, and add
separate rejection handling so denied clipboard permissions do not produce an
unhandled promise or success notification.

In `@src/lib/types.ts`:
- Around line 53-64: Update the AppQuestion.correctIndex property to use the
literal union type 0 | 1 | 2 | 3, ensuring appToDBQuestion() can only pass valid
option indexes to indexToLetter().

---

Outside diff comments:
In `@src/hooks/useTakeQuiz.ts`:
- Around line 31-77: Update fetchQuizData and its useEffect cleanup so requests
for an outdated quizId cannot update quiz state, loading/error state, or show
toast errors after navigation. Track request activity with an abort signal or
request version, invalidate it during effect cleanup, and guard both success and
catch updates while preserving updates for the active request.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b7dc4787-f2aa-4634-8b7a-e9043b02c219

📥 Commits

Reviewing files that changed from the base of the PR and between be353d8 and 3c92c3c.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (24)
  • .gitignore
  • docs/prt.md
  • eslint.config.mjs
  • package.json
  • src/components/CreateQuizForm.tsx
  • src/components/DashboardLayout.tsx
  • src/components/RequireAuth.tsx
  • src/components/UploadQuestionsForm.tsx
  • src/components/auth/AuthPageClient.tsx
  • src/components/quiz/QuestionCard.tsx
  • src/components/quiz/QuizResults.tsx
  • src/components/quiz/QuizReview.tsx
  • src/context/AuthContext.tsx
  • src/hooks/useAuth.ts
  • src/hooks/useCreateQuiz.ts
  • src/hooks/useQuizProgress.ts
  • src/hooks/useTakeQuiz.ts
  • src/lib/types.ts
  • src/utils/csvParser.ts
  • src/utils/handlers.ts
  • src/utils/helpers.ts
  • src/utils/transforms.ts
  • src/views/Auth/AuthForm.tsx
  • src/views/CreateQuiz.tsx
💤 Files with no reviewable changes (1)
  • src/utils/handlers.ts

Comment thread docs/prt.md
Comment thread docs/prt.md
Comment thread docs/prt.md
Comment thread docs/prt.md
Comment thread package.json
Comment thread src/components/CreateQuizForm.tsx Outdated
Comment thread src/hooks/useCreateQuiz.ts Outdated
Comment thread src/hooks/useCreateQuiz.ts
Comment thread src/hooks/useCreateQuiz.ts
Comment thread src/lib/types.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/views/CreateQuiz.tsx (1)

42-48: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Disable form fields while creation is in flight.

isLoading disables only the submit button; the inputs remain editable because disabled excludes isCreatingQuiz. Since createQuiz captures state before awaiting Supabase, edits made during the request are not persisted but remain visible afterward.

Proposed fix
-						disabled={!!quiz.id}
+						disabled={!!quiz.id || isCreatingQuiz}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/views/CreateQuiz.tsx` around lines 42 - 48, Update the form props in
CreateQuiz so the disabled state includes isCreatingQuiz as well as the existing
quiz.id condition, preventing title and description edits while createQuiz is in
flight.
src/hooks/useCreateQuiz.ts (1)

43-62: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Clear loading flags in finally blocks.

A rejected Supabase call or thrown transformation bypasses the current cleanup, leaving isCreatingQuiz or isUploadingQuestions permanently enabled. Wrap both operations with try/finally while preserving the existing error handling.

Also applies to: 107-119

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useCreateQuiz.ts` around lines 43 - 62, Update the quiz-creation
flow around the Supabase calls in the hook’s creation method and the
corresponding question-upload operation so each sets its loading flag back to
false in a finally block. Preserve the existing authentication and operation
error handling, while ensuring rejected calls or thrown transformations cannot
leave isCreatingQuiz or isUploadingQuestions enabled.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/hooks/useCreateQuiz.ts`:
- Around line 43-62: Update the quiz-creation flow around the Supabase calls in
the hook’s creation method and the corresponding question-upload operation so
each sets its loading flag back to false in a finally block. Preserve the
existing authentication and operation error handling, while ensuring rejected
calls or thrown transformations cannot leave isCreatingQuiz or
isUploadingQuestions enabled.

In `@src/views/CreateQuiz.tsx`:
- Around line 42-48: Update the form props in CreateQuiz so the disabled state
includes isCreatingQuiz as well as the existing quiz.id condition, preventing
title and description edits while createQuiz is in flight.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9937d443-334e-4d42-833d-c683ebc5a728

📥 Commits

Reviewing files that changed from the base of the PR and between 3c92c3c and 000906d.

📒 Files selected for processing (5)
  • src/components/CreateQuizForm.tsx
  • src/hooks/useCreateQuiz.ts
  • src/lib/types.ts
  • src/utils/transforms.ts
  • src/views/CreateQuiz.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant