Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Separate Caps.tsx into components

Richie McIlroya234adfe78ef
diff --git a/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx b/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx
index 840af7fc0..fb093a2e0 100644
--- a/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx
+++ b/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx
@@ -8,6 +8,7 @@ import {
MoreVertical,
Settings,
MessageSquare,
+ Share2,
} from "lucide-react";
import Link from "next/link";
import { classNames } from "@cap/utils";
@@ -96,6 +97,12 @@ export const AdminNavItems = () => {
icon: Clapperboard,
subNav: [],
},
+ {
+ name: "Shared Caps",
+ href: `/dashboard/shared-caps`,
+ icon: Share2,
+ subNav: [],
+ },
{
name: "Download App",
href: `/download`,
diff --git a/apps/web/app/dashboard/caps/Caps.tsx b/apps/web/app/dashboard/caps/Caps.tsx
index d66161ac2..f7a66412f 100644
--- a/apps/web/app/dashboard/caps/Caps.tsx
+++ b/apps/web/app/dashboard/caps/Caps.tsx
@@ -1,34 +1,13 @@
"use client";
-import { Button } from "@cap/ui";
-import moment from "moment";
-import { VideoThumbnail } from "@/components/VideoThumbnail";
-import { redirect, useRouter, useSearchParams } from "next/navigation";
-import toast, { Toaster } from "react-hot-toast";
-import {
- EyeIcon,
- LinkIcon,
- MessageSquareIcon,
- SmileIcon,
- Video,
- Trash,
- DownloadIcon,
-} from "lucide-react";
+import { useRouter, useSearchParams } from "next/navigation";
+import toast from "react-hot-toast";
import { useEffect, useState } from "react";
import { useSharedContext } from "@/app/dashboard/_components/DynamicSharedLayout";
-import {
- Pagination,
- PaginationContent,
- PaginationEllipsis,
- PaginationItem,
- PaginationLink,
- PaginationNext,
- PaginationPrevious,
-} from "@cap/ui";
-import { debounce } from "lodash";
-import { playlistToMp4 } from "@/utils/video/ffmpeg/helpers";
-import { Tooltip } from "react-tooltip";
+import { CapCard } from "./components/CapCard";
+import { EmptyCapState } from "./components/EmptyCapState";
+import { CapPagination } from "./components/CapPagination";
-type videoData = {
+type VideoData = {
id: string;
ownerId: string;
name: string;
@@ -37,7 +16,7 @@ type videoData = {
totalReactions: number;
}[];
-export const Caps = ({ data, count }: { data: videoData; count: number }) => {
+export const Caps = ({ data, count }: { data: VideoData; count: number }) => {
const { refresh, replace } = useRouter();
const params = useSearchParams();
const page = Number(params.get("page")) || 1;
@@ -45,49 +24,11 @@ export const Caps = ({ data, count }: { data: videoData; count: number }) => {
const { user, activeSpace } = useSharedContext();
const limit = 15;
const totalPages = Math.ceil(count / limit);
- const [isEditing, setIsEditing] = useState<null | string>(null);
- const [isDownloading, setIsDownloading] = useState<null | string>(null);
- const [titles, setTitles] = useState<Record<string, string>>({});
if (!activeSpace && (user?.name === undefined || user?.name === "")) {
replace("/onboarding");
}
- const handleTitleBlur = async ({ id }: { id: string }) => {
- setIsEditing(id);
-
- if (!titles[id]) {
- setIsEditing(null);
- return;
- }
-
- const response = await fetch(
- `${process.env.NEXT_PUBLIC_URL}/api/video/title`,
- {
- method: "PUT",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ title: titles[id], videoId: id }),
- }
- );
- if (!response.ok) {
- toast.error("Failed to update title - please try again.");
- return;
- }
-
- toast.success("Video title updated");
-
- setIsEditing(null);
- };
-
- const handleTitleKeyDown = debounce(
- async ({ key, id }: { key: string; id: string }) => {
- if (key === "Enter") {
- handleTitleBlur({ id });
- }
- },
- 300
- );
-
useEffect(() => {
const fetchAnalytics = async () => {
const analyticsData: Record<string, number> = {};
@@ -101,11 +42,7 @@ export const Caps = ({ data, count }: { data: videoData; count: number }) => {
);
const data = await response.json();
- if (!data.count) {
- analyticsData[video.id] = 0;
- } else {
- analyticsData[video.id] = data.count;
- }
+ analyticsData[video.id] = data.count || 0;
}
setAnalytics(analyticsData);
};
@@ -113,46 +50,6 @@ export const Caps = ({ data, count }: { data: videoData; count: number }) => {
fetchAnalytics();
}, [data]);
- const downloadCap = async (videoId: string) => {
- if (isDownloading !== null) {
- toast.error(
- "You are already downloading a Cap. Please wait for it to finish downloading."
- );
- return;
- }
-
- setIsDownloading(videoId);
-
- toast
- .promise(
- (async () => {
- const video = data.find((cap) => cap.id === videoId);
- if (!video) {
- throw new Error("Video not found");
- }
-
- const videoName = video.name || "Cap Video";
- const mp4Blob = await playlistToMp4(user.id, video.id, video.name);
- const downloadUrl = window.URL.createObjectURL(mp4Blob);
- const a = document.createElement("a");
- a.style.display = "none";
- a.href = downloadUrl;
- a.download = `${videoName}.mp4`;
- document.body.appendChild(a);
- a.click();
- window.URL.revokeObjectURL(downloadUrl);
- })(),
- {
- loading: "Downloading Cap...",
- success: "Cap downloaded",
- error: "Failed to download Cap",
- }
- )
- .finally(() => {
- setIsDownloading(null);
- });
- };
-
const deleteCap = async (videoId: string) => {
if (
!window.confirm(
@@ -175,305 +72,34 @@ export const Caps = ({ data, count }: { data: videoData; count: number }) => {
};
return (
- <div>
- {data.length === 0 ? (
- <div className="inner min-h-full h-full flex flex-col items-center justify-center">
- <div className="w-full max-w-md mx-auto">
- <img
- className="w-full h-auto"
- src="/illustrations/person-microphone.svg"
- alt="Person using microphone"
- />
- </div>
- <div className="text-center pb-[30px]">
- <h1 className="text-2xl font-semibold mb-3">
- <span className="block text-gray-400 text-lg">
- Hey, {user?.name}!
- </span>
- <span className="block">Record your first Cap.</span>
- </h1>
- <p className="text-xl max-w-md">
- Craft your narrative with a Cap—get projects done quicker.
- </p>
- <Button
- href="/download"
- size="lg"
- className="mt-8 relative"
- variant="primary"
- >
- Download Cap
- </Button>
- </div>
- </div>
- ) : (
- <div>
- <div className="mb-3">
- <h1 className="text-3xl font-medium">My Caps</h1>
- </div>
- <div className="inner grid grid-cols-2 md:grid-cols-3 xl:grid-cols-4 gap-4">
- {data.map((cap, index) => {
- const videoAnalytics = analytics[cap.id];
- const displayCount =
- videoAnalytics === 0
- ? Math.max(cap.totalComments, cap.totalReactions)
- : videoAnalytics;
-
- return (
- <div
- key={index}
- className="rounded-xl border-[1px] border-gray-200 relative"
- style={{ boxShadow: "0px 8px 16px rgba(18, 22, 31, 0.04)" }}
- >
- <div className="absolute top-2 right-2 space-y-2 z-20">
- <button
- type="button"
- className="cursor-pointer border border-gray-300 relative bg-white hover:bg-gray-200 w-8 h-8 m-0 p-0 rounded-full flex items-center justify-center transition-all"
- onClick={() => {
- if (
- process.env.NEXT_PUBLIC_IS_CAP &&
- process.env.NEXT_ENV === "production"
- ) {
- navigator.clipboard.writeText(
- `https://cap.link/${cap.id}`
- );
- } else {
- navigator.clipboard.writeText(
- `${process.env.NEXT_PUBLIC_URL}/s/${cap.id}`
- );
- }
- toast.success("Link copied to clipboard!");
- }}
- data-tooltip-id={cap.id + "_copy"}
- data-tooltip-content="Copy shareable Cap link"
- >
- <LinkIcon className="w-4 h-4" />
- <Tooltip id={cap.id + "_copy"} />
- </button>
- {/* <button
- type="button"
- className="cursor-pointer border border-gray-300 relative bg-white hover:bg-gray-200 w-8 h-8 m-0 p-0 rounded-full flex items-center justify-center transition-all"
- onClick={async () => {
- if (isDownloading === cap.id) {
- return;
- }
-
- await downloadCap(cap.id);
- }}
- data-tooltip-id={cap.id + "_download"}
- data-tooltip-content="Download your Cap recording"
- >
- {isDownloading === cap.id ? (
- <svg
- xmlns="http://www.w3.org/2000/svg"
- className="w-6 h-6"
- viewBox="0 0 24 24"
- >
- <style>
- {
- "@keyframes spinner_AtaB{to{transform:rotate(360deg)}}"
- }
- </style>
- <path
- fill="#000"
- d="M12 1a11 11 0 1 0 11 11A11 11 0 0 0 12 1Zm0 19a8 8 0 1 1 8-8 8 8 0 0 1-8 8Z"
- opacity={0.25}
- />
- <path
- fill="#00"
- d="M10.14 1.16a11 11 0 0 0-9 8.92A1.59 1.59 0 0 0 2.46 12a1.52 1.52 0 0 0 1.65-1.3 8 8 0 0 1 6.66-6.61A1.42 1.42 0 0 0 12 2.69a1.57 1.57 0 0 0-1.86-1.53Z"
- style={{
- transformOrigin: "center",
- animation: "spinner_AtaB .75s infinite linear",
- }}
- />
- </svg>
- ) : (
- <>
- <DownloadIcon className="w-4 h-4" />
- <Tooltip id={cap.id + "_download"} />
- </>
- )}
- </button> */}
- <button
- type="button"
- className="cursor-pointer border border-gray-300 relative bg-white hover:bg-gray-200 w-8 h-8 m-0 p-0 rounded-full flex items-center justify-center transition-all"
- onClick={async () => {
- await deleteCap(cap.id);
- }}
- data-tooltip-id={cap.id + "_delete"}
- data-tooltip-content="Delete your Cap recording"
- >
- <Trash className="w-4 h-4" />
- <Tooltip id={cap.id + "_delete"} />
- </button>
- </div>
- <a
- className="group block"
- href={
- process.env.NEXT_PUBLIC_IS_CAP &&
- process.env.NEXT_ENV === "production"
- ? `https://cap.link/${cap.id}`
- : `${process.env.NEXT_PUBLIC_URL}/s/${cap.id}`
- }
- >
- <VideoThumbnail
- userId={cap.ownerId}
- videoId={cap.id}
- alt={`${cap.name} Thumbnail`}
- />
- </a>
- <div className="flex flex-col p-4">
- {isEditing !== null && isEditing === cap.id ? (
- <textarea
- rows={1}
- value={titles[cap.id] || cap.name}
- onChange={(e) =>
- setTitles({
- ...titles,
- [cap.id]: e.target.value,
- })
- }
- onBlur={() => {
- handleTitleBlur({ id: cap.id });
- }}
- onKeyDown={(e) => {
- handleTitleKeyDown({ key: e.key, id: cap.id });
- }}
- autoFocus
- className="text-[0.875rem] leading-[1.25rem] text-gray-500 font-medium box-border"
- />
- ) : (
- <p
- className="text-[0.875rem] leading-[1.25rem] text-gray-500 font-medium"
- onClick={() => {
- if (
- user !== null &&
- user.id.toString() === cap.ownerId
- ) {
- setIsEditing(cap.id);
- }
- }}
- >
- {titles[cap.id] || cap.name}
- </p>
- )}
- <p>
- <span
- className="text-[0.875rem] leading-[1.25rem] text-gray-400"
- data-tooltip-id={cap.id + "_createdAt"}
- data-tooltip-content={`Cap created at ${cap.createdAt}`}
- >
- {moment(cap.createdAt).fromNow()}
- </span>
- <Tooltip id={cap.id + "_createdAt"} />
- </p>
- <div className="flex items-center space-x-3 mt-2 text-sm text-gray-60">
- <div
- className="flex items-center"
- data-tooltip-id={cap.id + "_analytics"}
- data-tooltip-content={`${displayCount} unique views via your shareable Cap.link.`}
- >
- <EyeIcon className="w-4 h-4 mr-1 text-gray-400" />
- <span className="text-[0.875rem] leading-[1.25rem] text-gray-400">
- {displayCount ?? "-"}
- </span>
- <Tooltip id={cap.id + "_analytics"} />
- </div>
- <div
- className="flex items-center"
- data-tooltip-id={cap.id + "_comments"}
- data-tooltip-content={`${cap.totalComments} comments`}
- >
- <MessageSquareIcon className="w-4 h-4 mr-1 text-gray-400" />
- <span className="text-[0.875rem] leading-[1.25rem] text-gray-400">
- {cap.totalComments}
- </span>
- <Tooltip id={cap.id + "_comments"} />
- </div>
- <div
- className="flex items-center"
- data-tooltip-id={cap.id + "_reactions"}
- data-tooltip-content={`${cap.totalReactions} reactions`}
- >
- <SmileIcon className="w-4 h-4 mr-1 text-gray-400" />
- <span className="text-[0.875rem] leading-[1.25rem] text-gray-400">
- {cap.totalReactions}
- </span>
- <Tooltip id={cap.id + "_reactions"} />
- </div>
- </div>
- </div>
- </div>
- );
- })}
- </div>
- {(data.length > limit || data.length === limit || page !== 1) && (
- <div className="mt-4">
- <Pagination>
- <PaginationContent>
- {page > 1 && (
- <PaginationItem>
- <PaginationPrevious
- href={
- process.env.NEXT_PUBLIC_URL +
- `/dashboard/caps?page=${page === 1 ? page : page - 1}`
- }
- />
- </PaginationItem>
- )}
- <PaginationItem>
- <PaginationLink
- href={
- process.env.NEXT_PUBLIC_URL + `/dashboard/caps?page=1`
- }
- isActive={page === 1}
- >
- 1
- </PaginationLink>
- </PaginationItem>
- {page !== 1 && (
- <PaginationItem>
- <PaginationLink
- href={
- process.env.NEXT_PUBLIC_URL +
- `/dashboard/caps?page=${page}`
- }
- isActive={true}
- >
- {page}
- </PaginationLink>
- </PaginationItem>
- )}
- {totalPages > page + 1 && (
- <PaginationItem>
- <PaginationLink
- href={
- process.env.NEXT_PUBLIC_URL +
- `/dashboard/caps?page=${page + 1}`
- }
- isActive={page === page + 1}
- >
- {page + 1}
- </PaginationLink>
- </PaginationItem>
- )}
- {page > 2 && <PaginationEllipsis />}
- <PaginationItem>
- <PaginationNext
- href={
- process.env.NEXT_PUBLIC_URL +
- `/dashboard/caps?page=${
- page === totalPages ? page : page + 1
- }`
- }
- />
- </PaginationItem>
- </PaginationContent>
- </Pagination>
+ <>
+ <div className="mb-3">
+ <h1 className="text-3xl font-medium">My Caps</h1>
+ </div>
+ <div className="inner min-h-full h-full">
+ {data.length === 0 ? (
+ <EmptyCapState userName={user?.name || ""} />
+ ) : (
+ <div>
+ <div className="inner grid grid-cols-2 md:grid-cols-3 xl:grid-cols-4 gap-4">
+ {data.map((cap) => (
+ <CapCard
+ key={cap.id}
+ cap={cap}
+ analytics={analytics[cap.id] || 0}
+ onDelete={deleteCap}
+ userId={user?.id}
+ />
+ ))}
</div>
- )}
- </div>
- )}
- </div>
+ {(data.length > limit || data.length === limit || page !== 1) && (
+ <div className="mt-4">
+ <CapPagination currentPage={page} totalPages={totalPages} />
+ </div>
+ )}
+ </div>
+ )}
+ </div>
+ </>
);
};
diff --git a/apps/web/app/dashboard/caps/components/CapCard.tsx b/apps/web/app/dashboard/caps/components/CapCard.tsx
new file mode 100644
index 000000000..77a59747b
--- /dev/null
+++ b/apps/web/app/dashboard/caps/components/CapCard.tsx
@@ -0,0 +1,141 @@
+import { useState } from "react";
+import { VideoThumbnail } from "@/components/VideoThumbnail";
+import { CapCardActions } from "@/app/dashboard/caps/components/CapCardActions";
+import { CapCardAnalytics } from "@/app/dashboard/caps/components/CapCardAnalytics";
+import { toast } from "react-hot-toast";
+import moment from "moment";
+import { Tooltip } from "react-tooltip";
+import { ShareIcon } from "lucide-react";
+
+interface CapCardProps {
+ cap: {
+ id: string;
+ ownerId: string;
+ name: string;
+ createdAt: Date;
+ totalComments: number;
+ totalReactions: number;
+ sharedSpaces: { id: string; name: string }[];
+ };
+ analytics: number;
+ onDelete: (videoId: string) => Promise<void>;
+ userId: string;
+}
+
+export const CapCard: React.FC<CapCardProps> = ({
+ cap,
+ analytics,
+ onDelete,
+ userId,
+}) => {
+ const [isEditing, setIsEditing] = useState(false);
+ const [title, setTitle] = useState(cap.name);
+
+ const handleTitleBlur = async () => {
+ if (!title) {
+ setIsEditing(false);
+ return;
+ }
+
+ const response = await fetch(
+ `${process.env.NEXT_PUBLIC_URL}/api/video/title`,
+ {
+ method: "PUT",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ title, videoId: cap.id }),
+ }
+ );
+ if (!response.ok) {
+ toast.error("Failed to update title - please try again.");
+ return;
+ }
+
+ toast.success("Video title updated");
+ setIsEditing(false);
+ };
+
+ const handleTitleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
+ if (e.key === "Enter") {
+ e.preventDefault();
+ handleTitleBlur();
+ }
+ };
+
+ const displayCount =
+ analytics === 0
+ ? Math.max(cap.totalComments, cap.totalReactions)
+ : analytics;
+
+ return (
+ <div
+ className="rounded-xl border-[1px] border-gray-200 relative"
+ style={{ boxShadow: "0px 8px 16px rgba(18, 22, 31, 0.04)" }}
+ >
+ <CapCardActions capId={cap.id} onDelete={onDelete} />
+ <a
+ className="group block"
+ href={
+ process.env.NEXT_PUBLIC_IS_CAP &&
+ process.env.NEXT_ENV === "production"
+ ? `https://cap.link/${cap.id}`
+ : `${process.env.NEXT_PUBLIC_URL}/s/${cap.id}`
+ }
+ >
+ <VideoThumbnail
+ userId={cap.ownerId}
+ videoId={cap.id}
+ alt={`${cap.name} Thumbnail`}
+ />
+ </a>
+ <div className="flex flex-col p-4">
+ {isEditing ? (
+ <textarea
+ rows={1}
+ value={title}
+ onChange={(e) => setTitle(e.target.value)}
+ onBlur={handleTitleBlur}
+ onKeyDown={handleTitleKeyDown}
+ autoFocus
+ className="text-[0.875rem] leading-[1.25rem] text-gray-500 font-medium box-border"
+ />
+ ) : (
+ <p
+ className="text-[0.875rem] leading-[1.25rem] text-gray-500 font-medium"
+ onClick={() => {
+ if (userId === cap.ownerId) {
+ setIsEditing(true);
+ }
+ }}
+ >
+ {title}
+ </p>
+ )}
+ <p>
+ <span
+ className="text-[0.875rem] leading-[1.25rem] text-gray-400"
+ data-tooltip-id={cap.id + "_createdAt"}
+ data-tooltip-content={`Cap created at ${cap.createdAt}`}
+ >
+ {moment(cap.createdAt).fromNow()}
+ </span>
+ <Tooltip id={cap.id + "_createdAt"} />
+ </p>
+ <CapCardAnalytics
+ capId={cap.id}
+ displayCount={displayCount}
+ totalComments={cap.totalComments}
+ totalReactions={cap.totalReactions}
+ />
+ {cap.sharedSpaces.length > 0 && (
+ <div className="mt-2 flex items-center">
+ <ShareIcon className="w-4 h-4 mr-2 text-gray-400" />
+ <span className="text-[0.875rem] leading-[1.25rem] text-gray-400">
+ Shared to:{" "}
+ {cap.sharedSpaces.map((space) => space.name).join(", ")}
+ </span>
+ </div>
+ )}
+ </div>
+ </div>
+ );
+};
diff --git a/apps/web/app/dashboard/caps/components/CapCardActions.tsx b/apps/web/app/dashboard/caps/components/CapCardActions.tsx
new file mode 100644
index 000000000..52b825970
--- /dev/null
+++ b/apps/web/app/dashboard/caps/components/CapCardActions.tsx
@@ -0,0 +1,48 @@
+import { LinkIcon, Trash } from "lucide-react";
+import { toast } from "react-hot-toast";
+import { Tooltip } from "react-tooltip";
+
+interface CapCardActionsProps {
+ capId: string;
+ onDelete: (videoId: string) => Promise<void>;
+}
+
+export const CapCardActions: React.FC<CapCardActionsProps> = ({
+ capId,
+ onDelete,
+}) => {
+ const copyLink = () => {
+ const link =
+ process.env.NEXT_PUBLIC_IS_CAP && process.env.NEXT_ENV === "production"
+ ? `https://cap.link/${capId}`
+ : `${process.env.NEXT_PUBLIC_URL}/s/${capId}`;
+
+ navigator.clipboard.writeText(link);
+ toast.success("Link copied to clipboard!");
+ };
+
+ return (
+ <div className="absolute top-2 right-2 space-y-2 z-20">
+ <button
+ type="button"
+ className="cursor-pointer border border-gray-300 relative bg-white hover:bg-gray-200 w-8 h-8 m-0 p-0 rounded-full flex items-center justify-center transition-all"
+ onClick={copyLink}
+ data-tooltip-id={capId + "_copy"}
+ data-tooltip-content="Copy shareable Cap link"
+ >
+ <LinkIcon className="w-4 h-4" />
+ <Tooltip id={capId + "_copy"} />
+ </button>
+ <button
+ type="button"
+ className="cursor-pointer border border-gray-300 relative bg-white hover:bg-gray-200 w-8 h-8 m-0 p-0 rounded-full flex items-center justify-center transition-all"
+ onClick={() => onDelete(capId)}
+ data-tooltip-id={capId + "_delete"}
+ data-tooltip-content="Delete your Cap recording"
+ >
+ <Trash className="w-4 h-4" />
+ <Tooltip id={capId + "_delete"} />
+ </button>
+ </div>
+ );
+};
diff --git a/apps/web/app/dashboard/caps/components/CapCardAnalytics.tsx b/apps/web/app/dashboard/caps/components/CapCardAnalytics.tsx
new file mode 100644
index 000000000..178d0a775
--- /dev/null
+++ b/apps/web/app/dashboard/caps/components/CapCardAnalytics.tsx
@@ -0,0 +1,54 @@
+import { EyeIcon, MessageSquareIcon, SmileIcon } from "lucide-react";
+import { Tooltip } from "react-tooltip";
+
+interface CapCardAnalyticsProps {
+ capId: string;
+ displayCount: number;
+ totalComments: number;
+ totalReactions: number;
+}
+
+export const CapCardAnalytics: React.FC<CapCardAnalyticsProps> = ({
+ capId,
+ displayCount,
+ totalComments,
+ totalReactions,
+}) => {
+ return (
+ <div className="flex items-center space-x-3 mt-2 text-sm text-gray-60">
+ <div
+ className="flex items-center"
+ data-tooltip-id={capId + "_analytics"}
+ data-tooltip-content={`${displayCount} unique views via your shareable Cap.link.`}
+ >
+ <EyeIcon className="w-4 h-4 mr-1 text-gray-400" />
+ <span className="text-[0.875rem] leading-[1.25rem] text-gray-400">
+ {displayCount ?? "-"}
+ </span>
+ <Tooltip id={capId + "_analytics"} />
+ </div>
+ <div
+ className="flex items-center"
+ data-tooltip-id={capId + "_comments"}
+ data-tooltip-content={`${totalComments} comments`}
+ >
+ <MessageSquareIcon className="w-4 h-4 mr-1 text-gray-400" />
+ <span className="text-[0.875rem] leading-[1.25rem] text-gray-400">
+ {totalComments}
+ </span>
+ <Tooltip id={capId + "_comments"} />
+ </div>
+ <div
+ className="flex items-center"
+ data-tooltip-id={capId + "_reactions"}
+ data-tooltip-content={`${totalReactions} reactions`}
+ >
+ <SmileIcon className="w-4 h-4 mr-1 text-gray-400" />
+ <span className="text-[0.875rem] leading-[1.25rem] text-gray-400">
+ {totalReactions}
+ </span>
+ <Tooltip id={capId + "_reactions"} />
+ </div>
+ </div>
+ );
+};
diff --git a/apps/web/app/dashboard/caps/components/CapPagination.tsx b/apps/web/app/dashboard/caps/components/CapPagination.tsx
new file mode 100644
index 000000000..5fa272766
--- /dev/null
+++ b/apps/web/app/dashboard/caps/components/CapPagination.tsx
@@ -0,0 +1,73 @@
+import {
+ Pagination,
+ PaginationContent,
+ PaginationEllipsis,
+ PaginationItem,
+ PaginationLink,
+ PaginationNext,
+ PaginationPrevious,
+} from "@cap/ui";
+
+interface CapPaginationProps {
+ currentPage: number;
+ totalPages: number;
+}
+
+export const CapPagination: React.FC<CapPaginationProps> = ({
+ currentPage,
+ totalPages,
+}) => {
+ return (
+ <Pagination>
+ <PaginationContent>
+ {currentPage > 1 && (
+ <PaginationItem>
+ <PaginationPrevious
+ href={`${process.env.NEXT_PUBLIC_URL}/dashboard/caps?page=${
+ currentPage - 1
+ }`}
+ />
+ </PaginationItem>
+ )}
+ <PaginationItem>
+ <PaginationLink
+ href={`${process.env.NEXT_PUBLIC_URL}/dashboard/caps?page=1`}
+ isActive={currentPage === 1}
+ >
+ 1
+ </PaginationLink>
+ </PaginationItem>
+ {currentPage !== 1 && (
+ <PaginationItem>
+ <PaginationLink
+ href={`${process.env.NEXT_PUBLIC_URL}/dashboard/caps?page=${currentPage}`}
+ isActive={true}
+ >
+ {currentPage}
+ </PaginationLink>
+ </PaginationItem>
+ )}
+ {totalPages > currentPage + 1 && (
+ <PaginationItem>
+ <PaginationLink
+ href={`${process.env.NEXT_PUBLIC_URL}/dashboard/caps?page=${
+ currentPage + 1
+ }`}
+ isActive={false}
+ >
+ {currentPage + 1}
+ </PaginationLink>
+ </PaginationItem>
+ )}
+ {currentPage > 2 && <PaginationEllipsis />}
+ <PaginationItem>
+ <PaginationNext
+ href={`${process.env.NEXT_PUBLIC_URL}/dashboard/caps?page=${
+ currentPage === totalPages ? currentPage : currentPage + 1
+ }`}
+ />
+ </PaginationItem>
+ </PaginationContent>
+ </Pagination>
+ );
+};
diff --git a/apps/web/app/dashboard/caps/components/EmptyCapState.tsx b/apps/web/app/dashboard/caps/components/EmptyCapState.tsx
new file mode 100644
index 000000000..16f8ed139
--- /dev/null
+++ b/apps/web/app/dashboard/caps/components/EmptyCapState.tsx
@@ -0,0 +1,38 @@
+import { Button } from "@cap/ui";
+
+interface EmptyCapStateProps {
+ userName?: string;
+}
+
+export const EmptyCapState: React.FC<EmptyCapStateProps> = ({ userName }) => {
+ return (
+ <div className="flex flex-col items-center justify-center">
+ <div className="w-full max-w-md mx-auto">
+ <img
+ className="w-full h-auto"
+ src="/illustrations/person-microphone.svg"
+ alt="Person using microphone"
+ />
+ </div>
+ <div className="text-center pb-[30px]">
+ <h1 className="text-2xl font-semibold mb-3">
+ <span className="block">Hey{userName ? `, ${userName}` : ""}!</span>
+ <span className="block">Record your first Cap.</span>
+ </h1>
+ <p className="text-xl max-w-md">
+ Craft your narrative with a Cap—get projects done quicker.
+ </p>
+ <div className="flex justify-center mt-8">
+ <Button
+ href="/download"
+ size="lg"
+ className="relative"
+ variant="primary"
+ >
+ Download Cap
+ </Button>
+ </div>
+ </div>
+ </div>
+ );
+};
diff --git a/apps/web/app/dashboard/caps/page.tsx b/apps/web/app/dashboard/caps/page.tsx
index a7eb11a5b..a8bab661e 100644
--- a/apps/web/app/dashboard/caps/page.tsx
+++ b/apps/web/app/dashboard/caps/page.tsx
@@ -1,6 +1,6 @@
import { Caps } from "./Caps";
import { db } from "@cap/database";
-import { comments, videos } from "@cap/database/schema";
+import { comments, videos, sharedVideos, spaces } from "@cap/database/schema";
import { desc, eq, sql, count } from "drizzle-orm";
import { getCurrentUser } from "@cap/database/auth/session";
import { Metadata } from "next";
@@ -35,16 +35,34 @@ export default async function CapsPage({
ownerId: videos.ownerId,
name: videos.name,
createdAt: videos.createdAt,
- totalComments: sql<number>`COUNT(CASE WHEN ${comments.type} = 'text' THEN 1 END)`,
- totalReactions: sql<number>`COUNT(CASE WHEN ${comments.type} = 'emoji' THEN 1 END)`,
+ totalComments: sql<number>`COUNT(DISTINCT CASE WHEN ${comments.type} = 'text' THEN ${comments.id} END)`,
+ totalReactions: sql<number>`COUNT(DISTINCT CASE WHEN ${comments.type} = 'emoji' THEN ${comments.id} END)`,
+ sharedSpaces: sql<{ id: string; name: string }[]>`
+ JSON_ARRAYAGG(
+ JSON_OBJECT(
+ 'id', ${spaces.id},
+ 'name', ${spaces.name}
+ )
+ )
+ `,
})
.from(videos)
.leftJoin(comments, eq(videos.id, comments.videoId))
+ .leftJoin(sharedVideos, eq(videos.id, sharedVideos.videoId))
+ .leftJoin(spaces, eq(sharedVideos.spaceId, spaces.id))
.where(eq(videos.ownerId, userId))
.groupBy(videos.id, videos.ownerId, videos.name, videos.createdAt)
.orderBy(desc(videos.createdAt))
.limit(limit)
.offset(offset);
- return <Caps data={videoData} count={totalCount} />;
+ const processedVideoData = videoData.map((video) => ({
+ ...video,
+ sharedSpaces: video.sharedSpaces.filter((space) => space.id !== null),
+ }));
+
+ console.log("processedVideoData:");
+ console.log(processedVideoData);
+
+ return <Caps data={processedVideoData} count={totalCount} />;
}