Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(dashboard): surface public collections in spaces views

Richie McIlroy7507079df50e
diff --git a/apps/web/app/(org)/dashboard/spaces/[spaceId]/SharedCaps.tsx b/apps/web/app/(org)/dashboard/spaces/[spaceId]/SharedCaps.tsx
index 33569dd2f..967bfed80 100644
--- a/apps/web/app/(org)/dashboard/spaces/[spaceId]/SharedCaps.tsx
+++ b/apps/web/app/(org)/dashboard/spaces/[spaceId]/SharedCaps.tsx
@@ -6,6 +6,7 @@ import type { SpaceRuleSource, ViewerSettingKey } from "@cap/web-backend";
import type {
ImageUpload,
Organisation,
+ PublicCollection,
Space,
User,
Video,
@@ -16,7 +17,7 @@ import {
faInfoCircle,
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-import { useRouter, useSearchParams } from "next/navigation";
+import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { useState } from "react";
import {
canManageOrganizationMembers,
@@ -25,6 +26,7 @@ import {
getEffectiveSpaceRole,
} from "@/lib/permissions/roles";
import { useVideosAnalyticsQuery } from "@/lib/Queries/Analytics";
+import { CollectionShareControl } from "../../_components/CollectionShareControl";
import SpaceDialog from "../../_components/Navbar/SpaceDialog";
import { useDashboardContext } from "../../Contexts";
import { CapPagination } from "../../caps/components/CapPagination";
@@ -74,8 +76,13 @@ type SpaceData = {
organizationId: Organisation.OrganisationId;
createdById: User.UserId;
iconUrl?: ImageUpload.ImageUrl | null;
- settings?: Partial<Record<ViewerSettingKey, boolean>> | null;
+ settings?:
+ | (Partial<Record<ViewerSettingKey, boolean>> & {
+ publicPage?: PublicCollection.PublicPageSettings;
+ })
+ | null;
hasPassword?: boolean;
+ public?: boolean;
};
export const SharedCaps = ({
@@ -107,6 +114,7 @@ export const SharedCaps = ({
};
}) => {
const params = useSearchParams();
+ const pathname = usePathname();
const router = useRouter();
const page = Number(params.get("page")) || 1;
const { activeOrganization } = useDashboardContext();
@@ -183,10 +191,24 @@ export const SharedCaps = ({
iconUrl: spaceData.iconUrl ?? undefined,
settings: spaceData.settings ?? null,
hasPassword: spaceData.hasPassword,
+ public: spaceData.public,
}}
/>
) : null;
+ const collectionShareControl = spaceData ? (
+ <CollectionShareControl
+ kind="space"
+ collectionId={spaceData.id}
+ isPublic={Boolean(spaceData.public)}
+ canManage={canManageCurrentSpace}
+ isPro={Boolean(activeOrganization?.ownerIsPro)}
+ settings={
+ canManageCurrentSpace ? (spaceData.settings?.publicPage ?? null) : null
+ }
+ />
+ ) : null;
+
if (data.length === 0 && folders?.length === 0) {
return (
<div className="flex relative flex-col w-full h-full">
@@ -211,6 +233,7 @@ export const SharedCaps = ({
Space settings
</Button>
)}
+ {collectionShareControl}
<MembersIndicator
memberCount={spaceMemberCount}
members={spaceMembers}
@@ -325,6 +348,7 @@ export const SharedCaps = ({
Space settings
</Button>
)}
+ {collectionShareControl}
<MembersIndicator
memberCount={spaceMemberCount}
members={spaceMembers}
@@ -422,7 +446,13 @@ export const SharedCaps = ({
</div>
{(data.length > limit || data.length === limit || page !== 1) && (
<div className="mt-4">
- <CapPagination currentPage={page} totalPages={totalPages} />
+ <CapPagination
+ currentPage={page}
+ totalPages={totalPages}
+ hrefForPage={(targetPage) =>
+ targetPage <= 1 ? pathname : `${pathname}?page=${targetPage}`
+ }
+ />
</div>
)}
</>
diff --git a/apps/web/app/(org)/dashboard/spaces/[spaceId]/folder/[folderId]/page.tsx b/apps/web/app/(org)/dashboard/spaces/[spaceId]/folder/[folderId]/page.tsx
index cfa50bcec..0cbf2b245 100644
--- a/apps/web/app/(org)/dashboard/spaces/[spaceId]/folder/[folderId]/page.tsx
+++ b/apps/web/app/(org)/dashboard/spaces/[spaceId]/folder/[folderId]/page.tsx
@@ -1,15 +1,21 @@
import { getCurrentUser } from "@cap/database/auth/session";
import { serverEnv } from "@cap/env";
import { makeCurrentUserLayer, Spaces } from "@cap/web-backend";
-import { type Folder, Space } from "@cap/web-domain";
+import { type Folder, type Organisation, Space } from "@cap/web-domain";
import { Effect } from "effect";
import { notFound } from "next/navigation";
+import { getOrganizationAccess } from "@/actions/organization/authorization";
+import { getSpaceAccess } from "@/actions/organization/space-authorization";
+import { CollectionShareControl } from "@/app/(org)/dashboard/_components/CollectionShareControl";
import FolderCard from "@/app/(org)/dashboard/caps/components/Folder";
import {
getChildFolders,
getFolderBreadcrumb,
+ getFolderById,
getVideosByFolderId,
} from "@/lib/folder";
+import { isOrganizationOwnerPro } from "@/lib/org-pro";
+import { canManageSpace } from "@/lib/permissions/roles";
import { runPromise } from "@/lib/server";
import {
BreadcrumbItem,
@@ -36,21 +42,66 @@ const FolderPage = async (props: {
);
if (!spaceOrOrg) notFound();
- const [childFolders, breadcrumb, videosData] = yield* Effect.all([
- getChildFolders(
- params.folderId,
- spaceOrOrg.variant === "space"
- ? { variant: "space", spaceId: spaceOrOrg.space.id }
- : { variant: "org", organizationId: spaceOrOrg.organization.id },
- ),
- getFolderBreadcrumb(params.folderId),
- getVideosByFolderId(
- params.folderId,
- spaceOrOrg.variant === "space"
- ? { variant: "space", spaceId: spaceOrOrg.space.id }
- : { variant: "org", organizationId: spaceOrOrg.organization.id },
- ),
- ]);
+ const orgId: Organisation.OrganisationId =
+ spaceOrOrg.variant === "space"
+ ? spaceOrOrg.space.organizationId
+ : spaceOrOrg.organization.id;
+
+ const spaceManagementAccess =
+ spaceOrOrg.variant === "space"
+ ? Effect.promise(() => getSpaceAccess(user.id, spaceOrOrg.space.id))
+ : Effect.succeed(null);
+ const orgManagementAccess =
+ spaceOrOrg.variant === "space"
+ ? Effect.succeed(null)
+ : Effect.promise(() => getOrganizationAccess(user.id, orgId));
+
+ const [
+ childFolders,
+ breadcrumb,
+ videosData,
+ currentFolder,
+ ownerIsPro,
+ managementAccess,
+ orgAccess,
+ ] = yield* Effect.all(
+ [
+ getChildFolders(
+ params.folderId,
+ spaceOrOrg.variant === "space"
+ ? { variant: "space", spaceId: spaceOrOrg.space.id }
+ : { variant: "org", organizationId: spaceOrOrg.organization.id },
+ ),
+ getFolderBreadcrumb(params.folderId),
+ getVideosByFolderId(
+ params.folderId,
+ spaceOrOrg.variant === "space"
+ ? { variant: "space", spaceId: spaceOrOrg.space.id }
+ : { variant: "org", organizationId: spaceOrOrg.organization.id },
+ ),
+ getFolderById(params.folderId),
+ Effect.promise(() => isOrganizationOwnerPro(orgId)),
+ spaceManagementAccess,
+ orgManagementAccess,
+ ],
+ // Independent reads — without this, Effect.all runs them sequentially
+ // and every page view pays the roundtrips back to back.
+ { concurrency: "unbounded" },
+ );
+ // Mirrors FoldersPolicy.canEdit so the share control is only shown to
+ // users the server would actually allow: space folders need space/org
+ // management; org-wide folders need org management. The folder must also
+ // actually belong to the routed space/org — getFolderById is unscoped,
+ // so a foreign folderId must not surface another collection's settings.
+ const folderBelongsToContext = currentFolder.spaceId === params.spaceId;
+ const canManageCollection =
+ folderBelongsToContext &&
+ (spaceOrOrg.variant === "space"
+ ? Boolean(managementAccess?.canManage)
+ : canManageSpace({
+ organizationRole: orgAccess?.role,
+ spaceRole: null,
+ }));
return (
<div>
@@ -61,8 +112,20 @@ const FolderPage = async (props: {
spaceId={params.spaceId}
folderName={breadcrumb[breadcrumb.length - 1]?.name ?? "Folder"}
/>
+ <CollectionShareControl
+ kind="folder"
+ collectionId={params.folderId}
+ isPublic={currentFolder.public}
+ canManage={canManageCollection}
+ isPro={ownerIsPro}
+ settings={
+ canManageCollection
+ ? (currentFolder.settings?.publicPage ?? null)
+ : null
+ }
+ />
</div>
- <div className="flex justify-between items-center mb-6 w-full">
+ <div className="flex flex-wrap gap-3 items-center mb-6 w-full">
<div className="flex overflow-x-auto items-center font-medium">
<ClientMyCapsLink spaceId={params.spaceId} />
{breadcrumb.map((folder, index) => (
@@ -79,7 +142,6 @@ const FolderPage = async (props: {
))}
</div>
</div>
- {/* Display Child Folders */}
{childFolders.length > 0 && (
<>
<h1 className="mb-6 text-xl font-medium text-gray-12">
@@ -91,6 +153,7 @@ const FolderPage = async (props: {
key={folder.id}
name={folder.name}
color={folder.color}
+ public={folder.public}
spaceId={params.spaceId}
id={folder.id}
parentId={folder.parentId}
@@ -100,7 +163,6 @@ const FolderPage = async (props: {
</div>
</>
)}
- {/* Display Videos */}
<FolderVideosSection
initialVideos={videosData}
analyticsEnabled={Boolean(
diff --git a/apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx b/apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx
index be6b5b0f4..a556110f0 100644
--- a/apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx
+++ b/apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx
@@ -58,6 +58,7 @@ async function fetchFolders(
id: folders.id,
name: folders.name,
color: folders.color,
+ public: folders.public,
parentId: folders.parentId,
spaceId: folders.spaceId,
videoCount: sql<number>`(
diff --git a/apps/web/app/(org)/dashboard/spaces/browse/page.tsx b/apps/web/app/(org)/dashboard/spaces/browse/page.tsx
index 43fff2c25..2493f4386 100644
--- a/apps/web/app/(org)/dashboard/spaces/browse/page.tsx
+++ b/apps/web/app/(org)/dashboard/spaces/browse/page.tsx
@@ -183,6 +183,9 @@ export default function BrowseSpacesPage() {
(m: { user: { id: string } }) => m.user.id,
),
iconUrl: space.iconUrl ?? undefined,
+ settings: space.settings,
+ hasPassword: space.hasPassword,
+ public: space.public,
});
setShowSpaceDialog(true);
}}