Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(dashboard): support public folders in caps views
Richie McIlroyecad59c59b62
diff --git a/apps/web/app/(org)/dashboard/caps/components/CapPagination.tsx b/apps/web/app/(org)/dashboard/caps/components/CapPagination.tsxindex 183f594f5..10ccca102 100644--- a/apps/web/app/(org)/dashboard/caps/components/CapPagination.tsx+++ b/apps/web/app/(org)/dashboard/caps/components/CapPagination.tsx@@ -11,11 +11,13 @@ import {interface CapPaginationProps {currentPage: number;totalPages: number;+ hrefForPage?: (page: number) => string;}export const CapPagination: React.FC<CapPaginationProps> = ({currentPage,totalPages,+ hrefForPage = (page) => `/dashboard/caps?page=${page}`,}) => {return (<Pagination>@@ -24,14 +26,14 @@ export const CapPagination: React.FC<CapPaginationProps> = ({<PaginationItem><PaginationPreviousclassName="h-10 bg-transparent hover:bg-gray-4"- href={`/dashboard/caps?page=${currentPage - 1}`}+ href={hrefForPage(currentPage - 1)}/></PaginationItem>)}<PaginationItem><PaginationLinkclassName="h-10 min-w-10"- href={`/dashboard/caps?page=1`}+ href={hrefForPage(1)}isActive={currentPage === 1}>1@@ -41,7 +43,7 @@ export const CapPagination: React.FC<CapPaginationProps> = ({<PaginationItem><PaginationLinkclassName="h-10 min-w-10"- href={`/dashboard/caps?page=${currentPage}`}+ href={hrefForPage(currentPage)}isActive={true}>{currentPage}@@ -52,7 +54,7 @@ export const CapPagination: React.FC<CapPaginationProps> = ({<PaginationItem><PaginationLinkclassName="h-10 min-w-10 hover:bg-gray-3"- href={`/dashboard/caps?page=${currentPage + 1}`}+ href={hrefForPage(currentPage + 1)}isActive={false}>{currentPage + 1}@@ -63,9 +65,9 @@ export const CapPagination: React.FC<CapPaginationProps> = ({<PaginationItem><PaginationNextclassName="h-10 bg-transparent hover:bg-gray-4"- href={`/dashboard/caps?page=${- currentPage === totalPages ? currentPage : currentPage + 1- }`}+ href={hrefForPage(+ currentPage === totalPages ? currentPage : currentPage + 1,+ )}/></PaginationItem></PaginationContent>diff --git a/apps/web/app/(org)/dashboard/caps/components/Folder.tsx b/apps/web/app/(org)/dashboard/caps/components/Folder.tsxindex 6bc22a260..03037800f 100644--- a/apps/web/app/(org)/dashboard/caps/components/Folder.tsx+++ b/apps/web/app/(org)/dashboard/caps/components/Folder.tsx@@ -1,6 +1,6 @@"use client";import type { Folder, Space } from "@cap/web-domain";-import { faTrash } from "@fortawesome/free-solid-svg-icons";+import { faGlobe, faTrash } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { Fit, Layout, useRive } from "@rive-app/react-canvas";import clsx from "clsx";@@ -10,6 +10,7 @@ import { useEffect, useRef, useState } from "react";import { toast } from "sonner";import { moveVideoToFolder } from "@/actions/folders/moveVideoToFolder";import { useEffectMutation, useRpcClient } from "@/lib/EffectRuntime";+import { useCopyCollectionLink } from "@/lib/public-collection-client";import { ConfirmationDialog } from "../../_components/ConfirmationDialog";import { useDashboardContext, useTheme } from "../../Contexts";import { registerDropTarget } from "../../folder/[id]/components/ClientCapCard";@@ -19,6 +20,7 @@ export type FolderDataType = {name: string;id: Folder.FolderId;color: "normal" | "blue" | "red" | "yellow";+ public: boolean;videoCount: number;spaceId?: Space.SpaceIdOrOrganisationId | null;parentId: Folder.FolderId | null;@@ -27,6 +29,7 @@ export type FolderDataType = {const FolderCard = ({name,color,+ public: isPublic,id,parentId,videoCount,@@ -37,19 +40,22 @@ const FolderCard = ({const [confirmDeleteFolderOpen, setConfirmDeleteFolderOpen] = useState(false);const [isRenaming, setIsRenaming] = useState(false);const [updateName, setUpdateName] = useState(name);+ const [publicEnabled, setPublicEnabled] = useState(isPublic);const nameRef = useRef<HTMLTextAreaElement>(null);- const folderRef = useRef<HTMLDivElement>(null);+ const folderRef = useRef<HTMLFieldSetElement>(null);const [isDragOver, setIsDragOver] = useState(false);const [isMovingVideo, setIsMovingVideo] = useState(false);- const { activeOrganization } = useDashboardContext();+ const { activeOrganization, setUpgradeModalOpen } = useDashboardContext();+ const ownerIsPro = Boolean(activeOrganization?.ownerIsPro);+ const folderHref = spaceId+ ? `/dashboard/spaces/${spaceId}/folder/${id}`+ : `/dashboard/folder/${id}`;- // Use a ref to track drag state to avoid re-renders during animationconst dragStateRef = useRef({isDragging: false,isAnimating: false,});- // Add a debounce timer ref to prevent animation stutteringconst animationTimerRef = useRef<NodeJS.Timeout | null>(null);const artboard =@@ -70,6 +76,7 @@ const FolderCard = ({});const rpc = useRpcClient();+ const { copy: copyPublicLink } = useCopyCollectionLink(id);const deleteFolder = useEffectMutation({mutationFn: (id: Folder.FolderId) => rpc.FolderDelete(id),@@ -86,10 +93,13 @@ const FolderCard = ({const updateFolder = useEffectMutation({mutationFn: (data: Folder.FolderUpdate) => rpc.FolderUpdate(data),onSuccess: () => {- toast.success("Folder name updated successfully");+ toast.success("Folder updated successfully");router.refresh();},- onError: () => toast.error("Failed to update folder name"),+ onError: () => {+ setPublicEnabled(isPublic);+ toast.error("Failed to update folder");+ },onSettled: () => setIsRenaming(false),});@@ -100,13 +110,15 @@ const FolderCard = ({}}, [isRenaming]);- // Register this folder as a drop target for mobile drag and drop+ useEffect(() => {+ setPublicEnabled(isPublic);+ }, [isPublic]);+useEffect(() => {if (!folderRef.current) return;const unregister = registerDropTarget(folderRef.current,- // onDrop handlerasync (data) => {if (!data || !data.id) return;@@ -193,7 +205,7 @@ const FolderCard = ({spaceId,]);- const handleDragOver = (e: React.DragEvent<HTMLDivElement>) => {+ const handleDragOver = (e: React.DragEvent<HTMLFieldSetElement>) => {e.preventDefault();e.stopPropagation();@@ -218,7 +230,7 @@ const FolderCard = ({}};- const handleDragLeave = (e: React.DragEvent<HTMLDivElement>) => {+ const handleDragLeave = (e: React.DragEvent<HTMLFieldSetElement>) => {e.preventDefault();e.stopPropagation();@@ -240,7 +252,7 @@ const FolderCard = ({}};- const handleDrop = async (e: React.DragEvent<HTMLDivElement>) => {+ const handleDrop = async (e: React.DragEvent<HTMLFieldSetElement>) => {e.preventDefault();e.stopPropagation();setIsDragOver(false);@@ -277,135 +289,142 @@ const FolderCard = ({};return (- <Link- prefetch={false}- href={- spaceId- ? `/dashboard/spaces/${spaceId}/folder/${id}`- : `/dashboard/folder/${id}`- }- >- <div- ref={folderRef}- onMouseEnter={() => {- // Don't play mouse animations during drag operations- if (dragStateRef.current.isDragging) return;- if (!rive) return;-- // Clear any pending animation timer- if (animationTimerRef.current) {- clearTimeout(animationTimerRef.current);- animationTimerRef.current = null;- }+ <fieldset+ ref={folderRef}+ onMouseEnter={() => {+ if (dragStateRef.current.isDragging) return;+ if (!rive) return;- // Use a small delay to prevent stuttering when moving the mouse quickly- animationTimerRef.current = setTimeout(() => {- rive.stop();- rive.play("folder-open");- }, 50);- }}- onMouseLeave={() => {- // Don't play mouse animations during drag operations- if (dragStateRef.current.isDragging) return;- if (!rive) return;-- // Clear any pending animation timer- if (animationTimerRef.current) {- clearTimeout(animationTimerRef.current);- animationTimerRef.current = null;- }+ if (animationTimerRef.current) {+ clearTimeout(animationTimerRef.current);+ animationTimerRef.current = null;+ }- // Use a small delay to prevent stuttering when moving the mouse quickly- animationTimerRef.current = setTimeout(() => {- rive.stop();- rive.play("folder-close");- }, 50);- }}- onDragOver={handleDragOver}- onDragLeave={handleDragLeave}- onDrop={handleDrop}- className={clsx(- "flex justify-between items-center px-4 py-4 w-full h-auto rounded-lg border transition-all duration-200 cursor-pointer bg-gray-3 hover:bg-gray-4 hover:border-gray-6",- isDragOver ? "border-blue-10 bg-gray-4" : "border-gray-5",- isMovingVideo && "opacity-70",- )}- >- <div className="flex flex-1 gap-3 items-center">+ animationTimerRef.current = setTimeout(() => {+ rive.stop();+ rive.play("folder-open");+ }, 50);+ }}+ onMouseLeave={() => {+ if (dragStateRef.current.isDragging) return;+ if (!rive) return;++ if (animationTimerRef.current) {+ clearTimeout(animationTimerRef.current);+ animationTimerRef.current = null;+ }++ animationTimerRef.current = setTimeout(() => {+ rive.stop();+ rive.play("folder-close");+ }, 50);+ }}+ onDragOver={handleDragOver}+ onDragLeave={handleDragLeave}+ onDrop={handleDrop}+ className={clsx(+ "flex justify-between items-center px-4 py-4 w-full h-auto min-w-0 rounded-lg border transition-all duration-200 bg-gray-3 hover:bg-gray-4 hover:border-gray-6",+ isDragOver ? "border-blue-10 bg-gray-4" : "border-gray-5",+ isMovingVideo && "opacity-70",+ )}+ >+ <div className="flex flex-1 gap-3 items-center">+ <Link href={folderHref} prefetch={false} className="shrink-0"><FolderRivekey={`${theme}folder${id}`}className="w-[50px] h-[50px]"/>- <div- onClick={(e) => {- e.preventDefault();- e.stopPropagation();- }}- className="flex flex-col justify-center h-10"- >- {isRenaming ? (- <textarea- ref={nameRef}- rows={1}- value={updateName}- onChange={(e) => setUpdateName(e.target.value)}- onBlur={() => {+ </Link>+ <div className="flex flex-col justify-center h-10">+ {isRenaming ? (+ <textarea+ ref={nameRef}+ rows={1}+ value={updateName}+ onClick={(e) => {+ e.preventDefault();+ e.stopPropagation();+ }}+ onChange={(e) => setUpdateName(e.target.value)}+ onBlur={() => {+ setIsRenaming(false);+ if (updateName.trim() !== name)+ updateFolder.mutate({+ id,+ name: updateName.trim(),+ });+ }}+ onKeyDown={(e) => {+ if (e.key === "Enter") {setIsRenaming(false);if (updateName.trim() !== name)updateFolder.mutate({id,name: updateName.trim(),});- }}- onKeyDown={(e) => {- if (e.key === "Enter") {- setIsRenaming(false);- if (updateName.trim() !== name)- updateFolder.mutate({- id,- name: updateName.trim(),- });- }- }}- className="w-full resize-none bg-transparent border-none focus:outline-none+ }+ }}+ className="w-full resize-none bg-transparent border-none focus:outline-nonefocus:ring-0 focus:border-none text-gray-12 text-[15px] max-w-[116px] truncate p-0 m-0 h-[22px] leading-[22px] overflow-hidden font-normal tracking-normal"- />- ) : (- <div- onClick={(e) => {- e.preventDefault();- e.stopPropagation();- setIsRenaming(true);- }}- >- <p className="text-[15px] truncate text-gray-12 w-full max-w-[116px] m-0 p-0 h-[22px] leading-[22px] font-normal tracking-normal">- {updateName}- </p>- </div>- )}+ />+ ) : (+ <Link+ href={folderHref}+ prefetch={false}+ className="block text-left"+ >+ <span className="block text-[15px] truncate text-gray-12 w-full max-w-[116px] m-0 p-0 h-[22px] leading-[22px] font-normal tracking-normal">+ {updateName}+ </span>+ </Link>+ )}+ <div className="flex gap-2 items-center"><p className="text-sm truncate text-gray-10 w-fit">{`${videoCount} ${videoCount === 1 ? "video" : "videos"}`}</p>+ {publicEnabled && (+ <span className="inline-flex gap-1 items-center text-[11px] font-medium text-blue-9">+ <FontAwesomeIcon icon={faGlobe} className="size-2.5" />+ Public+ </span>+ )}</div></div>- <ConfirmationDialog- loading={deleteFolder.isPending}- open={confirmDeleteFolderOpen}- icon={<FontAwesomeIcon icon={faTrash} />}- onConfirm={() => deleteFolder.mutate(id)}- onCancel={() => setConfirmDeleteFolderOpen(false)}- confirmLabel={deleteFolder.isPending ? "Deleting..." : "Delete"}- title="Delete Folder"- description={`Are you sure you want to delete the folder "${name}"? This action cannot be undone.`}- />- <FoldersDropdown- id={id}- parentId={parentId}- setIsRenaming={setIsRenaming}- setConfirmDeleteFolderOpen={setConfirmDeleteFolderOpen}- nameRef={nameRef}- /></div>- </Link>+ <ConfirmationDialog+ loading={deleteFolder.isPending}+ open={confirmDeleteFolderOpen}+ icon={<FontAwesomeIcon icon={faTrash} />}+ onConfirm={() => deleteFolder.mutate(id)}+ onCancel={() => setConfirmDeleteFolderOpen(false)}+ confirmLabel={deleteFolder.isPending ? "Deleting..." : "Delete"}+ title="Delete Folder"+ description={`Are you sure you want to delete the folder "${name}"? This action cannot be undone.`}+ />+ <FoldersDropdown+ id={id}+ parentId={parentId}+ public={publicEnabled}+ setIsRenaming={setIsRenaming}+ setConfirmDeleteFolderOpen={setConfirmDeleteFolderOpen}+ nameRef={nameRef}+ onPublicToggle={() => {+ const nextPublic = !publicEnabled;+ if (nextPublic && !ownerIsPro) {+ setUpgradeModalOpen(true);+ return;+ }+ setPublicEnabled(nextPublic);+ updateFolder.mutate({+ id,+ public: nextPublic,+ });+ }}+ onCopyPublicLink={async () => {+ await copyPublicLink();+ }}+ />+ </fieldset>);};diff --git a/apps/web/app/(org)/dashboard/caps/components/FoldersDropdown.tsx b/apps/web/app/(org)/dashboard/caps/components/FoldersDropdown.tsxindex d224034b0..3917c94f1 100644--- a/apps/web/app/(org)/dashboard/caps/components/FoldersDropdown.tsx+++ b/apps/web/app/(org)/dashboard/caps/components/FoldersDropdown.tsx@@ -5,7 +5,9 @@ import {DropdownMenuTrigger,} from "@cap/ui";import {+ faCopy,faEllipsis,+ faGlobe,faPencil,faTrash,} from "@fortawesome/free-solid-svg-icons";@@ -18,89 +20,90 @@ interface FoldersDropdownProps {setConfirmDeleteFolderOpen: (open: boolean) => void;nameRef: RefObject<HTMLTextAreaElement | null>;parentId?: string | null;+ public: boolean;+ onPublicToggle: () => void;+ onCopyPublicLink: () => void;}export const FoldersDropdown = ({setIsRenaming,setConfirmDeleteFolderOpen,nameRef,+ public: isPublic,+ onPublicToggle,+ onCopyPublicLink,}: FoldersDropdownProps) => {return (- <div- onClick={(e) => e.stopPropagation()}- onMouseEnter={(e) => e.stopPropagation()}- onMouseLeave={(e) => e.stopPropagation()}- >- <DropdownMenu>- <DropdownMenuTrigger asChild>- <div- className="flex justify-center items-center rounded-full border transition-colors duration-200+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <button+ type="button"+ onClick={(e) => {+ e.preventDefault();+ e.stopPropagation();+ }}+ onMouseEnter={(e) => e.stopPropagation()}+ onMouseLeave={(e) => e.stopPropagation()}+ className="flex justify-center items-center rounded-full border transition-colors duration-200size-8 bg-gray-5 border-gray-7 hover:bg-gray-7 hover:border-gray-9 data-[state=open]:bg-gray-7 data-[state=open]:border-gray-9"- >- <FontAwesomeIcon- className="text-gray-12 size-4"- icon={faEllipsis}- />- </div>- </DropdownMenuTrigger>- <DropdownMenuContent>- {(() => {- type FolderDropdownItem = {- label: string;- icon: any;- onClick: () => void | Promise<void>;- };- const items: FolderDropdownItem[] = [- {- label: "Rename",- icon: faPencil,- onClick: () => {- setIsRenaming(true);- setTimeout(() => {- nameRef.current?.focus();- nameRef.current?.select();- }, 0);- },+ >+ <FontAwesomeIcon className="text-gray-12 size-4" icon={faEllipsis} />+ </button>+ </DropdownMenuTrigger>+ <DropdownMenuContent>+ {(() => {+ type FolderDropdownItem = {+ label: string;+ icon: typeof faPencil;+ onClick: () => void | Promise<void>;+ };+ const items: FolderDropdownItem[] = [+ {+ label: "Rename",+ icon: faPencil,+ onClick: () => {+ setIsRenaming(true);+ setTimeout(() => {+ nameRef.current?.focus();+ nameRef.current?.select();+ }, 0);},- // Only show Duplicate if there is NO active space- // ...(!activeSpace- // ? [- // {- // label: "Duplicate",- // icon: faCopy,- // onClick: async () => {- // try {- // await duplicateFolder(id, parentId);- // toast.success("Folder duplicated successfully");- // } catch (error) {- // toast.error("Failed to duplicate folder");- // }- // },- // },- // ]- // : []),- {- label: "Delete",- icon: faTrash,- onClick: () => setConfirmDeleteFolderOpen(true),- },- ];- return items.map((item) => (- <DropdownMenuItem- key={item.label}- onClick={item.onClick}- className="rounded-lg"- >- <FontAwesomeIcon- className="mr-1.5 text-gray-10 size-3"- icon={item.icon}- />- {item.label}- </DropdownMenuItem>- ));- })()}- </DropdownMenuContent>- </DropdownMenu>- </div>+ },+ {+ label: isPublic ? "Make private" : "Make public",+ icon: faGlobe,+ onClick: onPublicToggle,+ },+ ...(isPublic+ ? [+ {+ label: "Copy public link",+ icon: faCopy,+ onClick: onCopyPublicLink,+ },+ ]+ : []),+ {+ label: "Delete",+ icon: faTrash,+ onClick: () => setConfirmDeleteFolderOpen(true),+ },+ ];+ return items.map((item) => (+ <DropdownMenuItem+ key={item.label}+ onClick={item.onClick}+ className="rounded-lg"+ >+ <FontAwesomeIcon+ className="mr-1.5 text-gray-10 size-3"+ icon={item.icon}+ />+ {item.label}+ </DropdownMenuItem>+ ));+ })()}+ </DropdownMenuContent>+ </DropdownMenu>);};diff --git a/apps/web/app/(org)/dashboard/caps/components/NewFolderDialog.tsx b/apps/web/app/(org)/dashboard/caps/components/NewFolderDialog.tsxindex 065f2e4ea..5ecf9387c 100644--- a/apps/web/app/(org)/dashboard/caps/components/NewFolderDialog.tsx+++ b/apps/web/app/(org)/dashboard/caps/components/NewFolderDialog.tsx@@ -19,6 +19,8 @@ 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,type FolderHandle,@@ -77,6 +79,8 @@ export const NewFolderDialog: React.FC<Props> = ({(typeof FolderOptions)[number]["value"] | null>(null);const [folderName, setFolderName] = useState<string>("");+ const [publicEnabled, setPublicEnabled] = useState(false);+ const { activeOrganization, setUpgradeModalOpen } = useDashboardContext();const router = useRouter();const { riveFile } = useRiveFile({@@ -84,7 +88,10 @@ export const NewFolderDialog: React.FC<Props> = ({});useEffect(() => {- if (!open) setSelectedColor(null);+ if (!open) {+ setSelectedColor(null);+ setPublicEnabled(false);+ }}, [open]);const folderRefs = useRef(@@ -103,10 +110,15 @@ export const NewFolderDialog: React.FC<Props> = ({const rpc = useRpcClient();const createFolder = 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(spaceId),parentId: Option.none(),}),@@ -140,7 +152,8 @@ export const NewFolderDialog: 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@@ -172,11 +185,20 @@ export const NewFolderDialog: 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)}>@@ -185,7 +207,11 @@ export const NewFolderDialog: React.FC<Props> = ({<ButtononClick={() => {if (selectedColor === null) return;- createFolder.mutate({ name: folderName, color: selectedColor });+ createFolder.mutate({+ name: folderName,+ color: selectedColor,+ public: publicEnabled,+ });}}size="sm"spinner={createFolder.isPending}diff --git a/apps/web/app/(org)/dashboard/caps/page.tsx b/apps/web/app/(org)/dashboard/caps/page.tsxindex c49ee5be3..6c2ed332e 100644--- a/apps/web/app/(org)/dashboard/caps/page.tsx+++ b/apps/web/app/(org)/dashboard/caps/page.tsx@@ -226,6 +226,7 @@ export default async function CapsPage(props: PageProps<"/dashboard/caps">) {id: folders.id,name: folders.name,color: folders.color,+ public: folders.public,parentId: folders.parentId,videoCount: sql<number>`(SELECT COUNT(*) FROM videos WHERE videos.folderId = folders.id