Skip to content

Conversation

jon-bell
Copy link
Contributor

@jon-bell jon-bell commented Oct 3, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Prevented read-status checks from running without a signed-in user, reducing erroneous requests and potential errors.
    • Corrected user filtering for discussion read status to reliably reflect the current user’s unread items.
    • Added a stricter rendering guard to show course content only when both course data and user context are ready, improving stability and avoiding transient UI issues.

Copy link
Contributor

coderabbitai bot commented Oct 3, 2025

Walkthrough

Introduces early return in setUnread when no user ID, updates user_id filter to use user.id, and adds a rendering guard in CourseControllerProvider requiring both courseController and userId before rendering.

Changes

Cohort / File(s) Summary
Discussion read-status & provider guards
hooks/useCourseController.tsx
- setUnread: Return early if no user ID; query filter uses user.id explicitly.
- CourseControllerProvider: Rendering now gated by presence of both courseController and userId.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor UI
  participant Hook as useDiscussionThreadReadStatus
  participant API as ReadStatusAPI

  UI->>Hook: setUnread(threadId)
  alt userId present
    Hook->>API: fetch readStatus where user_id = user.id
    API-->>Hook: status result
    Hook->>Hook: update local state/unread flag
  else userId missing
    Note right of Hook: Early return<br/>(no fetch performed)
  end
Loading
sequenceDiagram
  autonumber
  actor App
  participant Provider as CourseControllerProvider
  participant Children as Descendants

  App->>Provider: Render attempt
  alt courseController && userId available
    Provider->>Children: Render children
  else missing dependency
    Provider-->>App: Do not render children (guard)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A gate now guards the render path,
A user key unlocks the aftermath.
Threads wait quietly, fetches refrain,
No ID in hand—no network train.
With filters precise and logic lean,
The flow clicks true, composed and clean.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed Although the title notes that the pull request addresses an invalid column error in Postgres related to the user_id filter, it directly relates to the code change updating the filter to use a valid user id and prevent empty queries. The mention of “spam errors” may be confusing since the changes focus on filter logic rather than message spam. Overall, the title references the core fix but could be more concise to clearly convey the primary update.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-userid-errors

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92b0275 and 08ceb57.

📒 Files selected for processing (1)
  • hooks/useCourseController.tsx (3 hunks)
🔇 Additional comments (2)
hooks/useCourseController.tsx (2)

217-219: LGTM! Proper guard prevents invalid Postgres queries.

The early return correctly prevents the getOneByFilters call when user?.id is undefined, which would have caused Postgres errors. The subsequent use of user.id (non-optional) at line 229 is now safe due to this guard.

Also applies to: 229-229


1210-1210: LGTM! Defensive guard prevents edge case.

The updated condition correctly ensures both courseController and userId are present before rendering. This prevents potential issues if userId becomes undefined while courseController is still cleaning up.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@jon-bell jon-bell merged commit 0954525 into staging Oct 3, 2025
9 of 10 checks passed
@jon-bell jon-bell deleted the fix-userid-errors branch October 3, 2025 16:37
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