Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(dashboard): add public collection support to folder pages

Richie McIlroy6600d0440a9e
diff --git a/apps/web/app/(org)/dashboard/folder/[id]/components/SubfolderDialog.tsx b/apps/web/app/(org)/dashboard/folder/[id]/components/SubfolderDialog.tsx
index 62f0046e2..b2b18202e 100644
--- a/apps/web/app/(org)/dashboard/folder/[id]/components/SubfolderDialog.tsx
+++ b/apps/web/app/(org)/dashboard/folder/[id]/components/SubfolderDialog.tsx
@@ -20,6 +20,7 @@ import { useRouter } from "next/navigation";
import React, { useEffect, useRef, useState } from "react";
import { toast } from "sonner";
import { useEffectMutation, useRpcClient } from "@/lib/EffectRuntime";
+import { PublicCollectionField } from "../../../_components/PublicCollectionField";
import { useDashboardContext } from "../../../Contexts";
import {
BlueFolder,
@@ -79,7 +80,9 @@ export const SubfolderDialog: React.FC<Props> = ({
(typeof FolderOptions)[number]["value"] | null
>(null);
const [folderName, setFolderName] = useState<string>("");
- const { activeSpace } = useDashboardContext();
+ const [publicEnabled, setPublicEnabled] = useState(false);
+ const { activeSpace, activeOrganization, setUpgradeModalOpen } =
+ useDashboardContext();
const router = useRouter();
const { riveFile } = useRiveFile({
@@ -90,6 +93,7 @@ export const SubfolderDialog: React.FC<Props> = ({
if (!open) {
setSelectedColor(null);
setFolderName("");
+ setPublicEnabled(false);
}
}, [open]);
@@ -109,10 +113,15 @@ export const SubfolderDialog: React.FC<Props> = ({
const rpc = useRpcClient();
const createSubfolder = useEffectMutation({
- mutationFn: (data: { name: string; color: Folder.FolderColor }) =>
+ mutationFn: (data: {
+ name: string;
+ color: Folder.FolderColor;
+ public: boolean;
+ }) =>
rpc.FolderCreate({
name: data.name,
color: data.color,
+ public: data.public,
spaceId: Option.fromNullable(activeSpace?.id),
parentId: Option.some(parentFolderId),
}),
@@ -146,7 +155,8 @@ export const SubfolderDialog: React.FC<Props> = ({
<div className="flex flex-wrap gap-2 mt-3">
{FolderOptions.map((option) => {
return (
- <div
+ <button
+ type="button"
className={clsx(
"flex flex-col flex-1 gap-1 items-center p-2 rounded-xl border transition-colors duration-200 cursor-pointer",
selectedColor === option.value
@@ -178,11 +188,20 @@ export const SubfolderDialog: React.FC<Props> = ({
riveFile as RiveFile,
folderRefs.current[option.value],
)}
- <p className="text-xs text-gray-10">{option.label}</p>
- </div>
+ <span className="text-xs text-gray-10">{option.label}</span>
+ </button>
);
})}
</div>
+ <div className="mt-4">
+ <PublicCollectionField
+ kind="folder"
+ enabled={publicEnabled}
+ onChange={setPublicEnabled}
+ isPro={Boolean(activeOrganization?.ownerIsPro)}
+ onUpgrade={() => setUpgradeModalOpen(true)}
+ />
+ </div>
</div>
<DialogFooter>
<Button size="sm" variant="gray" onClick={() => onOpenChange(false)}>
@@ -194,6 +213,7 @@ export const SubfolderDialog: React.FC<Props> = ({
createSubfolder.mutate({
name: folderName,
color: selectedColor,
+ public: publicEnabled,
});
}}
size="sm"
diff --git a/apps/web/app/(org)/dashboard/folder/[id]/page.tsx b/apps/web/app/(org)/dashboard/folder/[id]/page.tsx
index f16cf43ff..249507304 100644
--- a/apps/web/app/(org)/dashboard/folder/[id]/page.tsx
+++ b/apps/web/app/(org)/dashboard/folder/[id]/page.tsx
@@ -7,10 +7,13 @@ import { notFound } from "next/navigation";
import {
getChildFolders,
getFolderBreadcrumb,
+ getFolderById,
getVideosByFolderId,
} from "@/lib/folder";
+import { isOrganizationOwnerPro } from "@/lib/org-pro";
import { runPromise } from "@/lib/server";
+import { CollectionShareControl } from "../../_components/CollectionShareControl";
import { UploadCapButton } from "../../caps/components";
import FolderCard from "../../caps/components/Folder";
import { WebRecorderDialog } from "../../caps/components/web-recorder-dialog/web-recorder-dialog";
@@ -29,13 +32,30 @@ const FolderPage = async (props: PageProps<"/dashboard/folder/[id]">) => {
if (!user || !user.activeOrganizationId) return notFound();
return Effect.gen(function* () {
- const [childFolders, breadcrumb, videosData] = yield* Effect.all([
- getChildFolders(folderId, { variant: "user" }),
- getFolderBreadcrumb(folderId),
- getVideosByFolderId(folderId, {
- variant: "user",
- }),
- ]);
+ const [childFolders, breadcrumb, videosData, share] = yield* Effect.all(
+ [
+ getChildFolders(folderId, { variant: "user" }),
+ getFolderBreadcrumb(folderId),
+ getVideosByFolderId(folderId, {
+ variant: "user",
+ }),
+ Effect.gen(function* () {
+ const folder = yield* getFolderById(folderId);
+ // Mirrors FoldersPolicy.canEdit for personal folders: only the
+ // creator may manage sharing; the Pro gate uses the folder's own
+ // organization, which is what the server enforces on writes.
+ const canManage =
+ folder.spaceId === null && folder.createdById === user.id;
+ const ownerIsPro = canManage
+ ? yield* Effect.promise(() =>
+ isOrganizationOwnerPro(folder.organizationId),
+ )
+ : false;
+ return { folder, canManage, ownerIsPro };
+ }),
+ ],
+ { concurrency: "unbounded" },
+ );
return (
<div>
@@ -43,8 +63,20 @@ const FolderPage = async (props: PageProps<"/dashboard/folder/[id]">) => {
<NewSubfolderButton parentFolderId={folderId} />
<UploadCapButton size="sm" />
<WebRecorderDialog />
+ <CollectionShareControl
+ kind="folder"
+ collectionId={folderId}
+ isPublic={share.folder.public}
+ canManage={share.canManage}
+ isPro={share.ownerIsPro}
+ settings={
+ share.canManage
+ ? (share.folder.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 />
@@ -74,6 +106,7 @@ const FolderPage = async (props: PageProps<"/dashboard/folder/[id]">) => {
key={folder.id}
name={folder.name}
color={folder.color}
+ public={folder.public}
id={folder.id}
parentId={folder.parentId}
videoCount={folder.videoCount}