Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: add tooltips to Caps dashboard

Richie McIlroye2f02fbaec18
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index f50e766b4..d89a1472f 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -3,7 +3,7 @@
"private": true,
"version": "0.2.7",
"scripts": {
- "dev": "tauri dev",
+ "dev": "RUST_BACKTRACE=1 tauri dev",
"build": "tsc && next build",
"tauri": "tauri"
},
diff --git a/apps/web/app/api/video/analytics/route.ts b/apps/web/app/api/video/analytics/route.ts
index ac861fe7b..125c7e184 100644
--- a/apps/web/app/api/video/analytics/route.ts
+++ b/apps/web/app/api/video/analytics/route.ts
@@ -2,7 +2,7 @@ import { dub } from "@/utils/dub";
import { ClicksCount } from "dub/models/components";
import { NextRequest } from "next/server";
-export const revalidate = 300;
+export const revalidate = 180;
export async function GET(request: NextRequest) {
const { searchParams } = request.nextUrl;
@@ -17,24 +17,54 @@ export async function GET(request: NextRequest) {
});
}
- const { clicks: analytics } = (await dub.analytics.retrieve({
- domain: "cap.link",
- key: videoId,
- })) as ClicksCount;
+ try {
+ const response = await dub.analytics.retrieve({
+ domain: "cap.link",
+ key: videoId,
+ });
+ console.log(response);
+ const { clicks: analytics } = response as ClicksCount;
+
+ if (typeof analytics !== "number" || analytics === null) {
+ console.log("analytics error");
+ return new Response(JSON.stringify({ error: true }), {
+ status: 401,
+ headers: {
+ "Content-Type": "application/json",
+ },
+ });
+ }
- if (typeof analytics !== "number") {
+ return new Response(JSON.stringify({ count: analytics }), {
+ status: 200,
+ headers: {
+ "Content-Type": "application/json",
+ },
+ });
+ } catch (error: any) {
+ // Handle specific 'not_found' error
+ if (error.code === "not_found") {
+ return new Response(
+ JSON.stringify({
+ error: true,
+ message: "Video link not found.",
+ docUrl: error.docUrl,
+ }),
+ {
+ status: 404,
+ headers: {
+ "Content-Type": "application/json",
+ },
+ }
+ );
+ }
+
+ // Handle other unexpected errors
return new Response(JSON.stringify({ error: true }), {
- status: 401,
+ status: 500,
headers: {
"Content-Type": "application/json",
},
});
}
-
- return new Response(JSON.stringify({ count: analytics }), {
- status: 200,
- headers: {
- "Content-Type": "application/json",
- },
- });
}
diff --git a/apps/web/app/dashboard/caps/Caps.tsx b/apps/web/app/dashboard/caps/Caps.tsx
index 9c4a68c76..4eea4e7d0 100644
--- a/apps/web/app/dashboard/caps/Caps.tsx
+++ b/apps/web/app/dashboard/caps/Caps.tsx
@@ -26,6 +26,7 @@ import {
} from "@cap/ui";
import { debounce } from "lodash";
import { playlistToMp4 } from "@/utils/video/ffmpeg/helpers";
+import { Tooltip } from "react-tooltip";
type videoData = {
id: string;
@@ -144,7 +145,7 @@ export const Caps = ({ data, count }: { data: videoData; count: number }) => {
}
)
.finally(() => {
- setIsDownloading(null); // Reset downloading state after completion or failure
+ setIsDownloading(null);
});
};
@@ -211,7 +212,7 @@ export const Caps = ({ data, count }: { data: videoData; count: number }) => {
return (
<div
key={index}
- className="rounded-xl border border-filler overflow-hidden relative"
+ className="rounded-xl border border-filler relative"
>
<div className="absolute top-2 right-2 space-y-2 z-20">
<button
@@ -232,8 +233,11 @@ export const Caps = ({ data, count }: { data: videoData; count: number }) => {
}
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"
@@ -245,6 +249,8 @@ export const Caps = ({ data, count }: { data: videoData; count: number }) => {
await downloadCap(cap.id);
}}
+ data-tooltip-id={cap.id + "_download"}
+ data-tooltip-content="Download your Cap recording"
>
{isDownloading === cap.id ? (
<svg
@@ -272,7 +278,10 @@ export const Caps = ({ data, count }: { data: videoData; count: number }) => {
/>
</svg>
) : (
- <DownloadIcon className="w-4 h-4" />
+ <>
+ <DownloadIcon className="w-4 h-4" />
+ <Tooltip id={cap.id + "_download"} />
+ </>
)}
</button>
<button
@@ -281,8 +290,11 @@ export const Caps = ({ data, count }: { data: videoData; count: number }) => {
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
@@ -335,27 +347,49 @@ export const Caps = ({ data, count }: { data: videoData; count: number }) => {
{titles[cap.id] || cap.name}
</p>
)}
- <p className="text-sm text-gray-400">
- {moment(cap.createdAt).fromNow()}
+ <p>
+ <span
+ className="text-sm 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-600">
- <div className="flex items-center">
+ <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={`${videoAnalytics} unique views via your shareable Cap.link. Refreshed every 5 minutes.`}
+ >
<EyeIcon className="w-4 h-4 mr-1" />
<span className="text-gray-600">
{videoAnalytics ?? "-"}
</span>
+ <Tooltip id={cap.id + "_analytics"} />
</div>
- <div className="flex items-center">
+ <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" />
<span className="text-gray-600">
{cap.totalComments}
</span>
+ <Tooltip id={cap.id + "_comments"} />
</div>
- <div className="flex items-center">
+ <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" />
<span className="text-gray-600">
{cap.totalReactions}
</span>
+ <Tooltip id={cap.id + "_reactions"} />
</div>
</div>
</div>
diff --git a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
index 267c24dca..d5361b03a 100644
--- a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
+++ b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
@@ -6,7 +6,6 @@ import { useRouter } from "next/navigation";
import { useState } from "react";
import { toast } from "react-hot-toast";
import { LinkIcon } from "lucide-react";
-import { Tooltip } from "react-tooltip";
export const ShareHeader = ({
data,
@@ -53,7 +52,6 @@ export const ShareHeader = ({
return (
<>
- <Tooltip data-tooltip-id="clipboard" />
<div>
<div className="md:flex md:items-center md:justify-between space-x-0 md:space-x-6">
<div className="flex items-center md:justify-between space-x-6">
diff --git a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx b/apps/web/app/s/[videoId]/_components/ShareVideo.tsx
index bfcf4e186..756b9486c 100644
--- a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx
+++ b/apps/web/app/s/[videoId]/_components/ShareVideo.tsx
@@ -11,7 +11,6 @@ import {
} from "lucide-react";
import { LogoSpinner } from "@cap/ui";
import { userSelectProps } from "@cap/database/auth/session";
-import { Tooltip } from "react-tooltip";
import { fromVtt, Subtitle } from "subtitles-parser-vtt";
import { is } from "drizzle-orm";
import toast from "react-hot-toast";
@@ -410,7 +409,6 @@ export const ShareVideo = ({
: "User"
}`}
>
- <Tooltip id={comment.id} />
<span>
{comment.type === "text" ? (
<MessageSquare
diff --git a/apps/web/utils/dub.ts b/apps/web/utils/dub.ts
index 7f3290359..59acf19b9 100644
--- a/apps/web/utils/dub.ts
+++ b/apps/web/utils/dub.ts
@@ -1,3 +1,5 @@
import { Dub } from "dub";
-export const dub = new Dub();
+export const dub = new Dub({
+ token: process.env.DUB_API_KEY,
+});