Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): add move support to CapCard and Folder

Richie McIlroyad89ffcd8aba
diff --git a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
index 3b433b091..64b8a22a6 100644
--- a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
+++ b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
@@ -11,7 +11,7 @@ import {
} from "@cap/ui";
import { calculateStrokeDashoffset, getProgressCircleConfig } from "@cap/utils";
import type { SpaceRuleSource, ViewerSettingKey } from "@cap/web-backend";
-import type { ImageUpload, Video } from "@cap/web-domain";
+import type { Folder, ImageUpload, Video } from "@cap/web-domain";
import { HttpClient } from "@effect/platform";
import {
faChartSimple,
@@ -33,6 +33,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import clsx from "clsx";
import { Effect, Option } from "effect";
+import { FolderInput } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { type PropsWithChildren, useEffect, useRef, useState } from "react";
@@ -46,13 +47,14 @@ import {
VideoThumbnail,
} from "@/components/VideoThumbnail";
import { useEffectMutation, useRpcClient } from "@/lib/EffectRuntime";
+import type { MoveLocation } from "@/lib/move-items";
import { ThumbnailRequest } from "@/lib/Requests/ThumbnailRequest";
import {
copyRichVideoLink,
videoPreviewImageUrl,
} from "@/lib/video-share-clipboard";
import { usePublicEnv } from "@/utils/public-env";
-
+import { MoveItemsDialog } from "../MoveItemsDialog";
import { PasswordDialog } from "../PasswordDialog";
import { SettingsDialog } from "../SettingsDialog";
import { SharingDialog } from "../SharingDialog";
@@ -131,6 +133,10 @@ export interface CapCardProps extends PropsWithChildren {
isDeleting?: boolean;
onDragStart?: () => void;
onDragEnd?: () => void;
+ canMove?: boolean;
+ moveLocation?: MoveLocation;
+ moveRootLabel?: string;
+ currentFolderId?: Folder.FolderId | null;
}
export const CapCard = ({
@@ -146,6 +152,10 @@ export const CapCard = ({
onSelectToggle,
anyCapSelected = false,
isDeleting = false,
+ canMove = false,
+ moveLocation,
+ moveRootLabel,
+ currentFolderId = null,
}: CapCardProps) => {
const { activeOrganization } = useDashboardContext();
const customDomain = activeOrganization?.organization.customDomain;
@@ -164,6 +174,7 @@ export const CapCard = ({
const [copyPressed, setCopyPressed] = useState(false);
const [isDragging, setIsDragging] = useState(false);
const [isSettingsDialogOpen, setIsSettingsDialogOpen] = useState(false);
+ const [isMoveDialogOpen, setIsMoveDialogOpen] = useState(false);
const { user, setUpgradeModalOpen } = useDashboardContext();
const [editUpgradeModalOpen, setEditUpgradeModalOpen] = useState(false);
@@ -229,6 +240,7 @@ export const CapCard = ({
};
const isOwner = userId === cap.ownerId;
+ const moveEnabled = Boolean(canMove && moveLocation && moveRootLabel);
const queryClient = useQueryClient();
const uploadProgress = useUploadProgress(
@@ -284,7 +296,7 @@ export const CapCard = ({
};
const handleDragStart = (e: React.DragEvent<HTMLElement>) => {
- if (anyCapSelected || !isOwner) return;
+ if (anyCapSelected || !moveEnabled) return;
// Set the data transfer
e.dataTransfer.setData(
@@ -411,9 +423,22 @@ export const CapCard = ({
hasPassword={passwordProtected}
onPasswordUpdated={handlePasswordUpdated}
/>
+ {moveEnabled && moveLocation && moveRootLabel && (
+ <MoveItemsDialog
+ open={isMoveDialogOpen}
+ onOpenChange={setIsMoveDialogOpen}
+ location={moveLocation}
+ rootLabel={moveRootLabel}
+ item={{
+ type: "videos",
+ videoIds: [cap.id],
+ currentFolderId,
+ }}
+ />
+ )}
<fieldset
aria-label={cap.name}
- draggable={isOwner && !anyCapSelected}
+ draggable={moveEnabled && !anyCapSelected}
onDragStart={handleDragStart}
onDragEnd={handleDragEnd}
className={clsx(
@@ -424,7 +449,9 @@ export const CapCard = ({
? "border-blue-10 hover:border-blue-10"
: "hover:border-blue-10",
isDragging && "opacity-50",
- isOwner && !anyCapSelected && "cursor-grab active:cursor-grabbing",
+ moveEnabled &&
+ !anyCapSelected &&
+ "cursor-grab active:cursor-grabbing",
)}
>
{anyCapSelected && !sharedCapCard && (
@@ -552,6 +579,18 @@ export const CapCard = ({
<FontAwesomeIcon className="size-3" icon={faLink} />
<p className="text-sm text-gray-12">Copy link</p>
</DropdownMenuItem>
+ {moveEnabled && (
+ <DropdownMenuItem
+ onClick={(event) => {
+ event.stopPropagation();
+ setIsMoveDialogOpen(true);
+ }}
+ className="flex gap-2 items-center rounded-lg"
+ >
+ <FolderInput className="size-3" />
+ <p className="text-sm text-gray-12">Move</p>
+ </DropdownMenuItem>
+ )}
{isOwner && (
<>
<DropdownMenuItem
diff --git a/apps/web/app/(org)/dashboard/caps/components/Folder.tsx b/apps/web/app/(org)/dashboard/caps/components/Folder.tsx
index 38b9e3124..74953741c 100644
--- a/apps/web/app/(org)/dashboard/caps/components/Folder.tsx
+++ b/apps/web/app/(org)/dashboard/caps/components/Folder.tsx
@@ -9,12 +9,14 @@ import { useEffect, useRef, useState } from "react";
import { toast } from "sonner";
import { moveVideoToFolder } from "@/actions/folders/moveVideoToFolder";
import { useEffectMutation, useRpcClient } from "@/lib/EffectRuntime";
+import { resolveMoveLocation } from "@/lib/move-items";
import { useCopyCollectionLink } from "@/lib/public-collection-client";
import { Fit, Layout, useRive } from "@/lib/rive";
import { ConfirmationDialog } from "../../_components/ConfirmationDialog";
import { useDashboardContext, useTheme } from "../../Contexts";
import { registerDropTarget } from "../../folder/[id]/components/ClientCapCard";
import { FoldersDropdown } from "./FoldersDropdown";
+import { MoveItemsDialog } from "./MoveItemsDialog";
export type FolderDataType = {
name: string;
@@ -24,6 +26,8 @@ export type FolderDataType = {
videoCount: number;
spaceId?: Space.SpaceIdOrOrganisationId | null;
parentId: Folder.FolderId | null;
+ canMove?: boolean;
+ moveRootLabel?: string;
};
const FolderCard = ({
@@ -34,6 +38,8 @@ const FolderCard = ({
parentId,
videoCount,
spaceId,
+ canMove,
+ moveRootLabel,
}: FolderDataType) => {
const router = useRouter();
const { theme } = useTheme();
@@ -45,11 +51,20 @@ const FolderCard = ({
const folderRef = useRef<HTMLFieldSetElement>(null);
const [isDragOver, setIsDragOver] = useState(false);
const [isMovingVideo, setIsMovingVideo] = useState(false);
+ const [isMoveDialogOpen, setIsMoveDialogOpen] = useState(false);
const { activeOrganization, setUpgradeModalOpen } = useDashboardContext();
const ownerIsPro = Boolean(activeOrganization?.ownerIsPro);
const folderHref = spaceId
? `/dashboard/spaces/${spaceId}/folder/${id}`
: `/dashboard/folder/${id}`;
+ const moveEnabled = canMove ?? !spaceId;
+ const effectiveMoveRootLabel =
+ moveRootLabel ??
+ (!spaceId ? "My Caps" : (activeOrganization?.organization.name ?? "Space"));
+ const moveLocation = resolveMoveLocation(
+ spaceId,
+ activeOrganization?.organization.id,
+ );
const dragStateRef = useRef({
isDragging: false,
@@ -115,7 +130,7 @@ const FolderCard = ({
}, [isPublic]);
useEffect(() => {
- if (!folderRef.current) return;
+ if (!folderRef.current || !moveEnabled) return;
const unregister = registerDropTarget(
folderRef.current,
@@ -127,9 +142,10 @@ const FolderCard = ({
await moveVideoToFolder({
videoId: data.id,
folderId: id,
- spaceId: spaceId ?? activeOrganization?.organization.id,
+ spaceId,
});
toast.success(`"${data.name}" moved to "${name}" folder`);
+ router.refresh();
} catch (error) {
console.error("Error moving video to folder:", error);
toast.error("Failed to move video to folder");
@@ -196,16 +212,10 @@ const FolderCard = ({
unregister();
document.removeEventListener("dragend", handleDragEnd);
};
- }, [
- id,
- name,
- rive,
- isDragOver,
- activeOrganization?.organization.id,
- spaceId,
- ]);
+ }, [id, name, rive, isDragOver, spaceId, moveEnabled, router]);
const handleDragOver = (e: React.DragEvent<HTMLFieldSetElement>) => {
+ if (!moveEnabled) return;
e.preventDefault();
e.stopPropagation();
@@ -253,6 +263,7 @@ const FolderCard = ({
};
const handleDrop = async (e: React.DragEvent<HTMLFieldSetElement>) => {
+ if (!moveEnabled) return;
e.preventDefault();
e.stopPropagation();
setIsDragOver(false);
@@ -280,6 +291,7 @@ const FolderCard = ({
setIsMovingVideo(true);
await moveVideoToFolder({ videoId: capData.id, folderId: id, spaceId });
toast.success(`"${capData.name}" moved to "${name}" folder`);
+ router.refresh();
} catch (error) {
console.error("Error moving video to folder:", error);
toast.error("Failed to move video to folder");
@@ -328,6 +340,19 @@ const FolderCard = ({
isMovingVideo && "opacity-70",
)}
>
+ {moveEnabled && (
+ <MoveItemsDialog
+ open={isMoveDialogOpen}
+ onOpenChange={setIsMoveDialogOpen}
+ location={moveLocation}
+ rootLabel={effectiveMoveRootLabel}
+ item={{
+ type: "folder",
+ folderId: id,
+ currentParentId: parentId,
+ }}
+ />
+ )}
<div className="flex flex-1 gap-3 items-center">
<Link href={folderHref} prefetch={false} className="shrink-0">
<FolderRive
@@ -423,6 +448,8 @@ const FolderCard = ({
onCopyPublicLink={async () => {
await copyPublicLink();
}}
+ canMove={moveEnabled}
+ onMove={() => setIsMoveDialogOpen(true)}
/>
</fieldset>
);
diff --git a/apps/web/app/(org)/dashboard/caps/components/FoldersDropdown.tsx b/apps/web/app/(org)/dashboard/caps/components/FoldersDropdown.tsx
index 3917c94f1..52b0fe7b8 100644
--- a/apps/web/app/(org)/dashboard/caps/components/FoldersDropdown.tsx
+++ b/apps/web/app/(org)/dashboard/caps/components/FoldersDropdown.tsx
@@ -7,6 +7,7 @@ import {
import {
faCopy,
faEllipsis,
+ faFolderTree,
faGlobe,
faPencil,
faTrash,
@@ -23,6 +24,8 @@ interface FoldersDropdownProps {
public: boolean;
onPublicToggle: () => void;
onCopyPublicLink: () => void;
+ canMove: boolean;
+ onMove: () => void;
}
export const FoldersDropdown = ({
@@ -32,6 +35,8 @@ export const FoldersDropdown = ({
public: isPublic,
onPublicToggle,
onCopyPublicLink,
+ canMove,
+ onMove,
}: FoldersDropdownProps) => {
return (
<DropdownMenu>
@@ -83,6 +88,15 @@ export const FoldersDropdown = ({
},
]
: []),
+ ...(canMove
+ ? [
+ {
+ label: "Move",
+ icon: faFolderTree,
+ onClick: onMove,
+ },
+ ]
+ : []),
{
label: "Delete",
icon: faTrash,