Skip to content

Conversation

@ameer2468
Copy link
Contributor

@ameer2468 ameer2468 commented Oct 7, 2025

Summary by CodeRabbit

  • New Features
    • “My Caps” in the dashboard navigation now displays your cap count.
  • Improvements
    • Dashboard data now includes your personal cap count and surfaces it across the UI where relevant.
    • If data can’t be loaded, the cap count is hidden to avoid misleading information.
  • Bug Fixes
    • Cap totals are now correctly scoped to your active organization, ensuring counts reflect only caps within the organization you’re currently viewing.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 7, 2025

Walkthrough

Adds userCapsCount to dashboard data flow: computed in dashboard-data.ts, passed through layout to DashboardContexts, exposed via useDashboardContext, and rendered as extraText on the "My Caps" navbar item. Adjusts caps/page.tsx to count user videos within the active organization. Minor context usage tweak in Top.tsx.

Changes

Cohort / File(s) Summary of changes
Dashboard context augmentation
apps/web/app/(org)/dashboard/Contexts.tsx, apps/web/app/(org)/dashboard/layout.tsx
Introduces userCapsCount in SharedContext and DashboardContexts props; layout fetches, stores, and passes userCapsCount to the context provider, including error-path handling.
Data fetching and counting
apps/web/app/(org)/dashboard/dashboard-data.ts, apps/web/app/(org)/dashboard/caps/page.tsx
Adds query to count distinct user videos within the active org; exposes userCapsCount in return payload; updates caps page count from simple owner filter to joined owner+org filter.
Navbar integration
apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx
Reads userCapsCount from context; passes as extraText to "My Caps"; updates NavItem prop signature to accept and render extraText when expanded; ensures manageNavigation items carry extraText.
Top bar context usage
apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx
Removes activeOrganization from destructuring; continues using activeSpace and anyNewNotifications.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant L as dashboard/layout.tsx
  participant D as getDashboardData()
  participant C as DashboardContexts (Provider)
  participant N as Navbar Items (NavItem)

  U->>L: Load dashboard
  L->>D: Fetch dashboard data
  D-->>L: { userCapsCount, ... } or error
  alt success
    L->>C: Provide context { userCapsCount, ... }
    N->>C: useDashboardContext()
    C-->>N: { userCapsCount, ... }
    N->>N: Render "My Caps" with extraText = userCapsCount
  else error
    L->>C: Provide context { userCapsCount: null, ... }
    N->>N: Render without count (null)
  end
Loading
sequenceDiagram
  autonumber
  participant P as caps/page.tsx
  participant DB as DB (videos ←→ organizations)
  P->>DB: Count distinct videos WHERE ownerId = user AND orgId = activeOrg
  DB-->>P: totalUserVideosInActiveOrg
  P->>P: Use count in page rendering
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • Brendonovich

Poem

A hop, a count, a carrot of lore,
My Caps now gleam with numbers galore. 🥕
Through context fields the totals flow,
From data burrows to navbar glow.
If nulls appear, I’ll twitch an ear—
Still proud of every cap this year! 🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 The title clearly and concisely summarizes the primary changes—correcting the caps count for empty states and displaying that count in the sidebar—which directly reflects the modifications introduced in the pull request.
✨ 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-caps-count

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/web/app/(org)/dashboard/caps/page.tsx (1)

116-122: Consider using an inner join instead of left join.

Since the where clause filters on organizations.id, and videos.orgId is a required field (schema shows nanoIdRequired), an inner join would be more semantically appropriate and explicit about the relationship requirement.

Apply this diff:

 const totalCountResult = await db()
   .select({ count: count() })
   .from(videos)
-  .leftJoin(organizations, eq(videos.orgId, organizations.id))
+  .innerJoin(organizations, eq(videos.orgId, organizations.id))
   .where(
     and(
       eq(videos.ownerId, userId),
       eq(organizations.id, user.activeOrganizationId),
     ),
   );
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 00a7d88 and 51ee04e.

📒 Files selected for processing (6)
  • apps/web/app/(org)/dashboard/Contexts.tsx (4 hunks)
  • apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx (5 hunks)
  • apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx (1 hunks)
  • apps/web/app/(org)/dashboard/caps/page.tsx (1 hunks)
  • apps/web/app/(org)/dashboard/dashboard-data.ts (4 hunks)
  • apps/web/app/(org)/dashboard/layout.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
apps/web/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

apps/web/**/*.{ts,tsx}: Use TanStack Query v5 for all client-side server state and data fetching in the web app
Web mutations should call Server Actions directly and perform targeted cache updates with setQueryData/setQueriesData rather than broad invalidations
Client code should use useEffectQuery/useEffectMutation and useRpcClient from apps/web/lib/EffectRuntime.ts; do not create ManagedRuntime inside components

Files:

  • apps/web/app/(org)/dashboard/caps/page.tsx
  • apps/web/app/(org)/dashboard/layout.tsx
  • apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx
  • apps/web/app/(org)/dashboard/Contexts.tsx
  • apps/web/app/(org)/dashboard/dashboard-data.ts
  • apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx
apps/web/app/**/*.{tsx,ts}

📄 CodeRabbit inference engine (CLAUDE.md)

Prefer Server Components for initial data in the Next.js App Router and pass initialData to client components

Files:

  • apps/web/app/(org)/dashboard/caps/page.tsx
  • apps/web/app/(org)/dashboard/layout.tsx
  • apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx
  • apps/web/app/(org)/dashboard/Contexts.tsx
  • apps/web/app/(org)/dashboard/dashboard-data.ts
  • apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx
**/*.{ts,tsx,js,jsx,rs}

📄 CodeRabbit inference engine (CLAUDE.md)

Do not add inline, block, or docstring comments in any language; code must be self-explanatory

Files:

  • apps/web/app/(org)/dashboard/caps/page.tsx
  • apps/web/app/(org)/dashboard/layout.tsx
  • apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx
  • apps/web/app/(org)/dashboard/Contexts.tsx
  • apps/web/app/(org)/dashboard/dashboard-data.ts
  • apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use strict TypeScript and avoid any; leverage shared types from packages

**/*.{ts,tsx}: Use a 2-space indent for TypeScript code.
Use Biome for formatting and linting TypeScript/JavaScript files by running pnpm format.

Files:

  • apps/web/app/(org)/dashboard/caps/page.tsx
  • apps/web/app/(org)/dashboard/layout.tsx
  • apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx
  • apps/web/app/(org)/dashboard/Contexts.tsx
  • apps/web/app/(org)/dashboard/dashboard-data.ts
  • apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx,js,jsx}: Use kebab-case for filenames for TypeScript/JavaScript modules (e.g., user-menu.tsx).
Use PascalCase for React/Solid components.

Files:

  • apps/web/app/(org)/dashboard/caps/page.tsx
  • apps/web/app/(org)/dashboard/layout.tsx
  • apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx
  • apps/web/app/(org)/dashboard/Contexts.tsx
  • apps/web/app/(org)/dashboard/dashboard-data.ts
  • apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx
apps/web/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

On the client, always use useEffectQuery or useEffectMutation from @/lib/EffectRuntime; never call EffectRuntime.run* directly in components.

Files:

  • apps/web/app/(org)/dashboard/caps/page.tsx
  • apps/web/app/(org)/dashboard/layout.tsx
  • apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx
  • apps/web/app/(org)/dashboard/Contexts.tsx
  • apps/web/app/(org)/dashboard/dashboard-data.ts
  • apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx
🧬 Code graph analysis (5)
apps/web/app/(org)/dashboard/caps/page.tsx (1)
packages/database/schema.ts (2)
  • organizations (152-180)
  • videos (256-311)
apps/web/app/(org)/dashboard/layout.tsx (1)
apps/web/app/(org)/dashboard/dashboard-data.ts (3)
  • OrganizationSettings (29-31)
  • Spaces (33-39)
  • getDashboardData (43-310)
apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx (1)
apps/web/app/(org)/dashboard/Contexts.tsx (1)
  • useDashboardContext (51-51)
apps/web/app/(org)/dashboard/dashboard-data.ts (2)
packages/database/index.ts (1)
  • db (29-34)
packages/database/schema.ts (1)
  • videos (256-311)
apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx (1)
apps/web/app/(org)/dashboard/Contexts.tsx (1)
  • useDashboardContext (51-51)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build Desktop (aarch64-apple-darwin, macos-latest)
  • GitHub Check: Build Desktop (x86_64-pc-windows-msvc, windows-latest)
  • GitHub Check: Analyze (rust)
🔇 Additional comments (9)
apps/web/app/(org)/dashboard/dashboard-data.ts (4)

12-12: LGTM!

The import is correctly added and used in the SQL query below.


89-89: LGTM!

Correct initialization for the count variable.


185-197: LGTM!

The SQL query correctly counts the user's videos within the active organization. The query structure is consistent with other queries in the file and properly handles the result with a fallback to 0.


297-297: LGTM!

The return values are correctly typed and consistent with error handling patterns throughout the function.

Also applies to: 304-304

apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx (1)

50-50: LGTM!

Valid cleanup removing the unused activeOrganization from the destructured context.

apps/web/app/(org)/dashboard/layout.tsx (1)

36-36: LGTM!

The state management for userCapsCount is implemented correctly with proper initialization, success handling, error handling, and propagation to the context provider.

Also applies to: 44-44, 52-52, 81-81

apps/web/app/(org)/dashboard/Contexts.tsx (1)

25-25: LGTM!

The type definitions and context propagation for userCapsCount are correctly implemented. The type number | null appropriately handles both success and error states.

Also applies to: 58-58, 72-72, 166-166

apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx (2)

53-53: LGTM!

The userCapsCount is correctly read from the dashboard context and assigned to the navigation item's extraText property.

Also applies to: 59-59


440-440: LGTM!

The extraText parameter is properly typed and conditionally rendered. The display logic correctly shows the count only when the value exists and the sidebar is not collapsed, which provides a good user experience.

Also applies to: 452-452, 494-498

@ameer2468 ameer2468 merged commit 889cafb into main Oct 7, 2025
15 checks passed
@ameer2468 ameer2468 deleted the fix-caps-count branch October 7, 2025 12:38
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.

2 participants