From 680a7b1a409483d93df1c565b73893fe98cb2935 Mon Sep 17 00:00:00 2001 From: ameer2468 <33054370+ameer2468@users.noreply.github.com> Date: Tue, 7 Oct 2025 15:09:36 +0300 Subject: [PATCH 1/3] fix caps count --- apps/web/app/(org)/dashboard/caps/page.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/web/app/(org)/dashboard/caps/page.tsx b/apps/web/app/(org)/dashboard/caps/page.tsx index d381db2b3b..b71d6ce162 100644 --- a/apps/web/app/(org)/dashboard/caps/page.tsx +++ b/apps/web/app/(org)/dashboard/caps/page.tsx @@ -113,7 +113,13 @@ export default async function CapsPage(props: PageProps<"/dashboard/caps">) { const totalCountResult = await db() .select({ count: count() }) .from(videos) - .where(eq(videos.ownerId, userId)); + .leftJoin(organizations, eq(videos.orgId, organizations.id)) + .where( + and( + eq(videos.ownerId, userId), + eq(organizations.id, user.activeOrganizationId), + ), + ); const totalCount = totalCountResult[0]?.count || 0; From 1d1619d04185178af26aea4b86ffef53994fbee8 Mon Sep 17 00:00:00 2001 From: ameer2468 <33054370+ameer2468@users.noreply.github.com> Date: Tue, 7 Oct 2025 15:27:59 +0300 Subject: [PATCH 2/3] display caps count in sidebar --- apps/web/app/(org)/dashboard/Contexts.tsx | 4 ++++ .../dashboard/_components/Navbar/Items.tsx | 11 ++++++++++- .../dashboard/_components/Navbar/Top.tsx | 3 +-- .../web/app/(org)/dashboard/dashboard-data.ts | 19 ++++++++++++++++++- apps/web/app/(org)/dashboard/layout.tsx | 4 ++++ 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/apps/web/app/(org)/dashboard/Contexts.tsx b/apps/web/app/(org)/dashboard/Contexts.tsx index a8799701e9..ae9459ea42 100644 --- a/apps/web/app/(org)/dashboard/Contexts.tsx +++ b/apps/web/app/(org)/dashboard/Contexts.tsx @@ -22,6 +22,7 @@ type SharedContext = { sharedSpaces: Spaces[] | null; activeSpace: Spaces | null; user: typeof users.$inferSelect; + userCapsCount: number | null; isSubscribed: boolean; toggleSidebarCollapsed: () => void; anyNewNotifications: boolean; @@ -54,6 +55,7 @@ export function DashboardContexts({ organizationData, activeOrganization, spacesData, + userCapsCount, user, isSubscribed, organizationSettings, @@ -67,6 +69,7 @@ export function DashboardContexts({ organizationData: SharedContext["organizationData"]; activeOrganization: SharedContext["activeOrganization"]; spacesData: SharedContext["spacesData"]; + userCapsCount: SharedContext["userCapsCount"]; user: SharedContext["user"]; isSubscribed: SharedContext["isSubscribed"]; organizationSettings: SharedContext["organizationSettings"]; @@ -160,6 +163,7 @@ export function DashboardContexts({ organizationData, activeOrganization, spacesData, + userCapsCount, anyNewNotifications, userPreferences, organizationSettings, diff --git a/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx b/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx index 560205301e..d6d100b273 100644 --- a/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx +++ b/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx @@ -50,12 +50,13 @@ const AdminNavItems = ({ toggleMobileNav }: Props) => { const pathname = usePathname(); const [open, setOpen] = useState(false); const [hoveredItem, setHoveredItem] = useState(null); - const { user, sidebarCollapsed } = useDashboardContext(); + const { user, sidebarCollapsed, userCapsCount } = useDashboardContext(); const manageNavigation = [ { name: "My Caps", href: `/dashboard/caps`, + extraText: userCapsCount, icon: , subNav: [], }, @@ -346,6 +347,7 @@ const AdminNavItems = ({ toggleMobileNav }: Props) => { sidebarCollapsed={sidebarCollapsed} toggleMobileNav={toggleMobileNav} isPathActive={isPathActive} + extraText={item.extraText} /> ))} @@ -435,6 +437,7 @@ const NavItem = ({ sidebarCollapsed, toggleMobileNav, isPathActive, + extraText, }: { name: string; href: string; @@ -446,6 +449,7 @@ const NavItem = ({ sidebarCollapsed: boolean; toggleMobileNav?: () => void; isPathActive: (path: string) => boolean; + extraText: number | null | undefined; }) => { const iconRef = useRef(null); return ( @@ -487,6 +491,11 @@ const NavItem = ({ > {name}

+ {extraText && ( +

+ {extraText} +

+ )} ); diff --git a/apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx b/apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx index c09a8eba59..96393b26fa 100644 --- a/apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx +++ b/apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx @@ -47,8 +47,7 @@ import type { DownloadIconHandle } from "../AnimatedIcons/Download"; import type { ReferIconHandle } from "../AnimatedIcons/Refer"; const Top = () => { - const { activeSpace, anyNewNotifications, activeOrganization } = - useDashboardContext(); + const { activeSpace, anyNewNotifications } = useDashboardContext(); const [toggleNotifications, setToggleNotifications] = useState(false); const bellRef = useRef(null); const { theme, setThemeHandler } = useTheme(); diff --git a/apps/web/app/(org)/dashboard/dashboard-data.ts b/apps/web/app/(org)/dashboard/dashboard-data.ts index b41b75741c..0f7655c6d9 100644 --- a/apps/web/app/(org)/dashboard/dashboard-data.ts +++ b/apps/web/app/(org)/dashboard/dashboard-data.ts @@ -9,6 +9,7 @@ import { spaceMembers, spaces, users, + videos, } from "@cap/database/schema"; import { and, count, eq, inArray, isNull, or, sql } from "drizzle-orm"; @@ -85,7 +86,7 @@ export async function getDashboardData(user: typeof userSelectProps) { let anyNewNotifications = false; let spacesData: Spaces[] = []; let organizationSettings: OrganizationSettings | null = null; - + let userCapsCount = 0; // Find active organization ID let activeOrganizationId = organizationIds.find( @@ -181,6 +182,20 @@ export async function getDashboardData(user: typeof userSelectProps) { ); const orgVideoCount = orgVideoCountResult[0]?.value || 0; + const userCapsCountResult = await db() + .select({ + value: sql`COUNT(DISTINCT ${videos.id})`, + }) + .from(videos) + .where( + and( + eq(videos.orgId, activeOrgInfo.organization.id), + eq(videos.ownerId, user.id), + ), + ); + + userCapsCount = userCapsCountResult[0]?.value || 0; + const allSpacesEntry = { id: activeOrgInfo.organization.id, primary: true, @@ -279,12 +294,14 @@ export async function getDashboardData(user: typeof userSelectProps) { spacesData, anyNewNotifications, userPreferences, + userCapsCount, }; } catch (error) { console.error("Failed to fetch dashboard data", error); return { organizationSelect: [], spacesData: [], + userCapsCount: null, anyNewNotifications: false, userPreferences: null, organizationSettings: null, diff --git a/apps/web/app/(org)/dashboard/layout.tsx b/apps/web/app/(org)/dashboard/layout.tsx index 99d71fdbe6..1afbba49e9 100644 --- a/apps/web/app/(org)/dashboard/layout.tsx +++ b/apps/web/app/(org)/dashboard/layout.tsx @@ -33,6 +33,7 @@ export default async function DashboardLayout({ } let organizationSelect: Organization[] = []; + let userCapsCount: number | null = null; let organizationSettings: OrganizationSettings | null = null; let spacesData: Spaces[] = []; let anyNewNotifications = false; @@ -40,6 +41,7 @@ export default async function DashboardLayout({ try { const dashboardData = await getDashboardData(user); organizationSelect = dashboardData.organizationSelect; + userCapsCount = dashboardData.userCapsCount; organizationSettings = dashboardData.organizationSettings; userPreferences = dashboardData.userPreferences?.preferences || null; spacesData = dashboardData.spacesData; @@ -47,6 +49,7 @@ export default async function DashboardLayout({ } catch (error) { console.error("Failed to load dashboard data", error); organizationSelect = []; + userCapsCount = null; organizationSettings = null; spacesData = []; anyNewNotifications = false; @@ -75,6 +78,7 @@ export default async function DashboardLayout({ Date: Tue, 7 Oct 2025 15:30:14 +0300 Subject: [PATCH 3/3] Update Items.tsx --- apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx b/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx index d6d100b273..3a9580287e 100644 --- a/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx +++ b/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx @@ -491,7 +491,7 @@ const NavItem = ({ > {name}

- {extraText && ( + {extraText && !sidebarCollapsed && (

{extraText}