Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: count shared videos in nested folders

Richie McIlroyc49f73cc42bb
diff --git a/apps/web/lib/folder.ts b/apps/web/lib/folder.ts
index 7a802a8c7..1932622f8 100644
--- a/apps/web/lib/folder.ts
+++ b/apps/web/lib/folder.ts
@@ -365,6 +365,23 @@ export const getChildFolders = Effect.fn(function* (
const user = yield* CurrentUser;
if (!user.activeOrganizationId) throw new Error("No active organization");
+ const videoCount =
+ root.variant === "space"
+ ? sql<number>`(
+ SELECT COUNT(*) FROM ${spaceVideos}
+ WHERE ${spaceVideos.folderId} = ${folders.id}
+ AND ${spaceVideos.spaceId} = ${root.spaceId}
+ )`
+ : root.variant === "org"
+ ? sql<number>`(
+ SELECT COUNT(*) FROM ${sharedVideos}
+ WHERE ${sharedVideos.folderId} = ${folders.id}
+ AND ${sharedVideos.organizationId} = ${root.organizationId}
+ )`
+ : sql<number>`(
+ SELECT COUNT(*) FROM ${videos}
+ WHERE ${videos.folderId} = ${folders.id}
+ )`;
const childFolders = yield* db.use((db) =>
db
@@ -375,9 +392,7 @@ export const getChildFolders = Effect.fn(function* (
public: folders.public,
parentId: folders.parentId,
organizationId: folders.organizationId,
- videoCount: sql<number>`(
- SELECT COUNT(*) FROM videos WHERE videos.folderId = folders.id
- )`,
+ videoCount,
})
.from(folders)
.where(
@@ -385,7 +400,9 @@ export const getChildFolders = Effect.fn(function* (
eq(folders.parentId, folderId),
root.variant === "space"
? eq(folders.spaceId, root.spaceId)
- : undefined,
+ : root.variant === "org"
+ ? eq(folders.spaceId, root.organizationId)
+ : isNull(folders.spaceId),
),
),
);