Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

4.1 KB
Raw Blame
"use client";

import { Button } from "@cap/ui";
import type { Folder, Video } from "@cap/web-domain";
import { faFilm, faTrash } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import NumberFlow from "@number-flow/react";
import { AnimatePresence, motion } from "framer-motion";
import { FolderInput } from "lucide-react";
import { useState } from "react";
import { ConfirmationDialog } from "@/app/(org)/dashboard/_components/ConfirmationDialog";
import type { MoveLocation } from "@/lib/move-items";
import { MoveItemsDialog } from "./MoveItemsDialog";

interface SelectedCapsBarProps {
	selectedCaps: Video.VideoId[];
	setSelectedCaps: (caps: Video.VideoId[]) => void;
	deleteSelectedCaps?: () => void;
	isDeleting?: boolean;
	moveLocation?: MoveLocation;
	moveRootLabel?: string;
	currentFolderId?: Folder.FolderId | null;
}

export const SelectedCapsBar = ({
	selectedCaps,
	setSelectedCaps,
	deleteSelectedCaps,
	isDeleting = false,
	moveLocation,
	moveRootLabel,
	currentFolderId = null,
}: SelectedCapsBarProps) => {
	const [confirmOpen, setConfirmOpen] = useState(false);
	const [moveOpen, setMoveOpen] = useState(false);

	const handleConfirmDelete = () => {
		deleteSelectedCaps?.();
		setConfirmOpen(false);
	};

	return (
		<AnimatePresence>
			{selectedCaps.length > 0 && (
				<>
					<motion.div
						className="flex fixed right-0 left-0 bottom-12 z-50 justify-between items-center p-3 mx-auto w-full max-w-xl rounded-xl border shadow-lg border-gray-2 bg-gray-1"
						initial={{ opacity: 0, y: 10, scale: 0.9 }}
						animate={{ opacity: 1, y: 0, scale: 1 }}
						exit={{
							opacity: 0,
							y: 10,
							scale: 0.9,
							transition: { duration: 0.2 },
						}}
						transition={{
							opacity: { duration: 0.2, ease: "easeOut" },
							y: { type: "spring", damping: 15, stiffness: 300 },
							scale: { type: "spring", damping: 15, stiffness: 300 },
						}}
					>
						<div className="flex gap-1 text-sm font-medium text-gray-10">
							<NumberFlow
								value={selectedCaps.length}
								className="tabular-nums text-md text-gray-12"
							/>
							cap{selectedCaps.length !== 1 ? "s" : ""} selected
						</div>
						<div className="flex gap-2 ml-4">
							{moveLocation && moveRootLabel && (
								<Button
									variant="gray"
									onClick={() => setMoveOpen(true)}
									className="flex gap-2 items-center text-sm"
									size="sm"
								>
									<FolderInput className="size-4" />
									Move
								</Button>
							)}
							<Button
								variant="dark"
								onClick={() => setSelectedCaps([])}
								className="text-sm"
								size="sm"
							>
								Cancel
							</Button>
							{deleteSelectedCaps && (
								<>
									<Button
										variant="destructive"
										onClick={() => setConfirmOpen(true)}
										disabled={isDeleting}
										className="size-[40px] min-w-[unset] p-0"
										size="sm"
									>
										<FontAwesomeIcon
											className="w-3.5 text-white"
											icon={faTrash}
										/>
									</Button>
									<ConfirmationDialog
										open={confirmOpen}
										icon={<FontAwesomeIcon icon={faFilm} />}
										title="Delete selected Caps"
										description={`Are you sure you want to delete ${
											selectedCaps.length
										} cap${
											selectedCaps.length === 1 ? "" : "s"
										}? This action cannot be undone.`}
										confirmLabel={isDeleting ? "Deleting..." : "Delete"}
										cancelLabel="Cancel"
										confirmVariant="dark"
										loading={isDeleting}
										onConfirm={handleConfirmDelete}
										onCancel={() => setConfirmOpen(false)}
									/>
								</>
							)}
						</div>
					</motion.div>
					{moveLocation && moveRootLabel && (
						<MoveItemsDialog
							open={moveOpen}
							onOpenChange={setMoveOpen}
							location={moveLocation}
							rootLabel={moveRootLabel}
							item={{
								type: "videos",
								videoIds: selectedCaps,
								currentFolderId,
							}}
							onMoved={() => setSelectedCaps([])}
						/>
					)}
				</>
			)}
		</AnimatePresence>
	);
};