Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Add 'Record a Cap' page to dashboard

Richie McIlroy268e19beee7e
diff --git a/apps/web/app/(org)/dashboard/_components/AnimatedIcons/Record.tsx b/apps/web/app/(org)/dashboard/_components/AnimatedIcons/Record.tsx
new file mode 100644
index 000000000..a2244b2ef
--- /dev/null
+++ b/apps/web/app/(org)/dashboard/_components/AnimatedIcons/Record.tsx
@@ -0,0 +1,98 @@
+"use client";
+
+import { motion, useAnimation } from "motion/react";
+import type { HTMLAttributes } from "react";
+import { forwardRef, useCallback, useImperativeHandle, useRef } from "react";
+import { cn } from "@/lib/utils";
+
+export interface RecordIconHandle {
+ startAnimation: () => void;
+ stopAnimation: () => void;
+}
+
+interface RecordIconProps extends HTMLAttributes<HTMLDivElement> {
+ size?: number;
+}
+
+const RecordIcon = forwardRef<RecordIconHandle, RecordIconProps>(
+ ({ onMouseEnter, onMouseLeave, className, size = 28, ...props }, ref) => {
+ const controls = useAnimation();
+ const isControlledRef = useRef(false);
+
+ useImperativeHandle(ref, () => {
+ isControlledRef.current = true;
+
+ return {
+ startAnimation: () => controls.start("animate"),
+ stopAnimation: () => controls.start("normal"),
+ };
+ });
+
+ const handleMouseEnter = useCallback(
+ (e: React.MouseEvent<HTMLDivElement>) => {
+ if (!isControlledRef.current) {
+ controls.start("animate");
+ } else {
+ onMouseEnter?.(e);
+ }
+ },
+ [controls, onMouseEnter],
+ );
+
+ const handleMouseLeave = useCallback(
+ (e: React.MouseEvent<HTMLDivElement>) => {
+ if (!isControlledRef.current) {
+ controls.start("normal");
+ } else {
+ onMouseLeave?.(e);
+ }
+ },
+ [controls, onMouseLeave],
+ );
+
+ return (
+ <div
+ className={cn(className)}
+ onMouseEnter={handleMouseEnter}
+ onMouseLeave={handleMouseLeave}
+ {...props}
+ >
+ <motion.svg
+ xmlns="http://www.w3.org/2000/svg"
+ width={size}
+ height={size}
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ transition={{ type: "spring", stiffness: 50, damping: 10 }}
+ >
+ <rect x="2" y="3" width="20" height="14" rx="2" />
+ <line x1="8" y1="21" x2="16" y2="21" />
+ <line x1="12" y1="17" x2="12" y2="21" />
+ <motion.circle
+ cx="12"
+ cy="10"
+ r="2"
+ variants={{
+ normal: { scale: 1, opacity: 0, fill: "currentColor" },
+ animate: {
+ scale: [1, 1.25, 1],
+ opacity: [0, 1, 0.8, 1],
+ fill: "currentColor",
+ },
+ }}
+ animate={controls}
+ transition={{ duration: 0.9, ease: "easeInOut" }}
+ />
+ </motion.svg>
+ </div>
+ );
+ },
+);
+
+RecordIcon.displayName = "RecordIcon";
+
+export default RecordIcon;
diff --git a/apps/web/app/(org)/dashboard/_components/AnimatedIcons/index.ts b/apps/web/app/(org)/dashboard/_components/AnimatedIcons/index.ts
index 17c438c79..d7b2c4307 100644
--- a/apps/web/app/(org)/dashboard/_components/AnimatedIcons/index.ts
+++ b/apps/web/app/(org)/dashboard/_components/AnimatedIcons/index.ts
@@ -6,6 +6,7 @@ import DownloadIcon from "./Download";
import HomeIcon from "./Home";
import LayersIcon from "./Layers";
import LogoutIcon from "./Logout";
+import RecordIcon from "./Record";
import ReferIcon from "./Refer";
import SettingsGearIcon from "./Settings";
@@ -20,4 +21,5 @@ export {
LogoutIcon,
SettingsGearIcon,
ReferIcon,
+ RecordIcon,
};
diff --git a/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx b/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx
index fadb2c328..5198484ee 100644
--- a/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx
+++ b/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx
@@ -36,7 +36,7 @@ import { SignedImageUrl } from "@/components/SignedImageUrl";
import { Tooltip } from "@/components/Tooltip";
import { UsageButton } from "@/components/UsageButton";
import { useDashboardContext } from "../../Contexts";
-import { CapIcon, CogIcon } from "../AnimatedIcons";
+import { CapIcon, CogIcon, RecordIcon } from "../AnimatedIcons";
import type { CogIconHandle } from "../AnimatedIcons/Cog";
import CapAIBox from "./CapAIBox";
import SpacesList from "./SpacesList";
@@ -59,6 +59,12 @@ const AdminNavItems = ({ toggleMobileNav }: Props) => {
icon: <CapIcon />,
subNav: [],
},
+ {
+ name: "Record a Cap",
+ href: `/dashboard/caps/record`,
+ icon: <RecordIcon />,
+ subNav: [],
+ },
{
name: "Organization Settings",
href: `/dashboard/settings/organization`,
@@ -78,7 +84,12 @@ const AdminNavItems = ({ toggleMobileNav }: Props) => {
const [openAIDialog, setOpenAIDialog] = useState(false);
const router = useRouter();
- const isPathActive = (path: string) => pathname.includes(path);
+ const isPathActive = (path: string) => {
+ if (path === "/dashboard/caps") {
+ return pathname === "/dashboard/caps";
+ }
+ return pathname === path || pathname.startsWith(`${path}/`);
+ };
const isDomainSetupVerified =
activeOrg?.organization.customDomain &&
activeOrg?.organization.domainVerified;
diff --git a/apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx b/apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx
index 3884e96c2..5af3fe662 100644
--- a/apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx
+++ b/apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx
@@ -59,6 +59,7 @@ const Top = () => {
"/dashboard/caps": "Caps",
"/dashboard/folder": "Caps",
"/dashboard/shared-caps": "Shared Caps",
+ "/dashboard/caps/record": "Record a Cap",
"/dashboard/settings/organization": "Organization Settings",
"/dashboard/settings/account": "Account Settings",
"/dashboard/spaces": "Spaces",
diff --git a/apps/web/app/(org)/dashboard/caps/record/RecordVideoPage.tsx b/apps/web/app/(org)/dashboard/caps/record/RecordVideoPage.tsx
new file mode 100644
index 000000000..33507f422
--- /dev/null
+++ b/apps/web/app/(org)/dashboard/caps/record/RecordVideoPage.tsx
@@ -0,0 +1,168 @@
+"use client";
+
+import { Button } from "@cap/ui";
+import { faDownload } from "@fortawesome/free-solid-svg-icons";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { ChevronDown } from "lucide-react";
+import { AnimatePresence, motion } from "motion/react";
+import { useCallback, useId, useRef, useState } from "react";
+import { FREE_PLAN_MAX_RECORDING_MS } from "../components/web-recorder-dialog/web-recorder-constants";
+import { WebRecorderDialog } from "../components/web-recorder-dialog/web-recorder-dialog";
+
+export const RecordVideoPage = () => {
+ const checkingRef = useRef<ReturnType<typeof setTimeout> | null>(null);
+
+ const openDesktop = useCallback(() => {
+ let handled = false;
+ const onChange = () => {
+ handled = true;
+ document.removeEventListener("visibilitychange", onChange);
+ window.removeEventListener("pagehide", onChange);
+ window.removeEventListener("blur", onChange);
+ };
+ document.addEventListener("visibilitychange", onChange, { once: true });
+ window.addEventListener("pagehide", onChange, { once: true });
+ window.addEventListener("blur", onChange, { once: true });
+
+ window.location.href = "cap-desktop://";
+
+ if (checkingRef.current) clearTimeout(checkingRef.current);
+ checkingRef.current = setTimeout(() => {
+ if (!handled && document.visibilityState === "visible") {
+ document.removeEventListener("visibilitychange", onChange);
+ window.removeEventListener("pagehide", onChange);
+ window.removeEventListener("blur", onChange);
+ window.location.assign("/download");
+ }
+ }, 1500);
+ }, []);
+
+ return (
+ <div
+ className="flex flex-col flex-1 justify-center items-center w-full h-full"
+ style={{ scrollbarGutter: "stable" }}
+ >
+ <div className="flex flex-col gap-3 justify-center items-center h-full text-center">
+ <div className="w-full px-5">
+ <div className="mx-auto w-full max-w-[560px]">
+ <div className="flex flex-col items-center">
+ <p className="max-w-md text-gray-10 text-md">
+ Choose how you'd like to record your Cap
+ </p>
+ </div>
+ <div className="flex flex-wrap gap-3 justify-center items-center mt-4">
+ <Button
+ onClick={openDesktop}
+ className="flex relative gap-2 justify-center items-center"
+ variant="primary"
+ >
+ <FontAwesomeIcon className="size-3.5" icon={faDownload} />
+ Open Cap Desktop
+ </Button>
+ <p className="text-sm text-gray-10">or</p>
+ <WebRecorderDialog />
+ </div>
+ <FaqAccordion />
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+};
+
+const FaqAccordion = () => {
+ const freeMinutes = Math.floor(FREE_PLAN_MAX_RECORDING_MS / 60000);
+ const items = [
+ {
+ id: "what-is-cap",
+ q: "What is a Cap?",
+ a: "A Cap is a quick video recording of your screen, camera, or both that you can share instantly with a link.",
+ },
+ {
+ id: "how-it-works",
+ q: "How does it work?",
+ a: "On compatible browsers, your capture uploads in the background while you record. Otherwise it records first and uploads immediately after you stop, so your link is ready right away.",
+ },
+ {
+ id: "browsers",
+ q: "Which browsers are recommended?",
+ a: "We recommend Google Chrome or other Chromium‑based browsers for the most reliable recording and upload behavior. Most modern browsers are supported, but capabilities can vary.",
+ },
+ {
+ id: "pip",
+ q: "How do I keep my webcam visible?",
+ a: "On compatible browsers, selecting a camera opens a picture‑in‑picture window that’s captured when you record fullscreen. We recommend recording fullscreen to keep it on top. If PiP capture isn’t supported, your camera stays within the Cap recorder tab.",
+ },
+ {
+ id: "what-can-i-record",
+ q: "What can I record?",
+ a: "You can record your entire screen, a specific window, a browser tab, or just your camera.",
+ },
+ {
+ id: "system-audio",
+ q: "Can I record system audio?",
+ a: "Browsers limit system‑wide audio capture. Chrome can capture tab audio, but full system audio is best with Cap Desktop.",
+ },
+ {
+ id: "install",
+ q: "Do I need to install the app?",
+ a: `No. You can record in your browser. For longer recordings, system audio, and advanced editing, use Cap Desktop. The Free plan supports up to ${freeMinutes} minutes per recording in the browser.`,
+ },
+ ];
+
+ return (
+ <div className="mt-8 w-full max-w-[560px] px-5 text-left">
+ <div className="divide-y divide-gray-4 rounded-lg border border-gray-4 bg-gray-2 w-full">
+ {items.map((it) => (
+ <AccordionItem key={it.id} title={it.q} content={it.a} />
+ ))}
+ </div>
+ </div>
+ );
+};
+
+const AccordionItem = ({
+ title,
+ content,
+}: {
+ title: string;
+ content: string;
+}) => {
+ const [open, setOpen] = useState(false);
+ const contentId = useId();
+ const headerId = useId();
+
+ return (
+ <div className="p-3">
+ <button
+ id={headerId}
+ aria-controls={contentId}
+ aria-expanded={open}
+ onClick={() => setOpen((v) => !v)}
+ type="button"
+ className="flex w-full items-center justify-between gap-3 text-left"
+ >
+ <span className="text-sm font-medium text-gray-12">{title}</span>
+ <ChevronDown
+ className="size-4 shrink-0 text-gray-10 transition-transform duration-200"
+ style={{ transform: open ? "rotate(180deg)" : "rotate(0deg)" }}
+ />
+ </button>
+ <AnimatePresence initial={false}>
+ {open && (
+ <motion.section
+ id={contentId}
+ aria-labelledby={headerId}
+ initial={{ opacity: 0, height: 0 }}
+ animate={{ opacity: 1, height: "auto" }}
+ exit={{ opacity: 0, height: 0 }}
+ transition={{ duration: 0.18 }}
+ className="overflow-hidden"
+ >
+ <div className="pt-2 text-sm text-gray-10">{content}</div>
+ </motion.section>
+ )}
+ </AnimatePresence>
+ </div>
+ );
+};
diff --git a/apps/web/app/(org)/dashboard/caps/record/page.tsx b/apps/web/app/(org)/dashboard/caps/record/page.tsx
new file mode 100644
index 000000000..d69028846
--- /dev/null
+++ b/apps/web/app/(org)/dashboard/caps/record/page.tsx
@@ -0,0 +1,10 @@
+import type { Metadata } from "next";
+import { RecordVideoPage } from "./RecordVideoPage";
+
+export const metadata: Metadata = {
+ title: "Record a Cap",
+};
+
+export default function RecordVideoRoute() {
+ return <RecordVideoPage />;
+}