Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Add cap share link to dashboard

Richie McIlroye43a500e26ec
diff --git a/apps/web/app/dashboard/caps/Caps.tsx b/apps/web/app/dashboard/caps/Caps.tsx
index 9b5d3c8a7..2782d28ef 100644
--- a/apps/web/app/dashboard/caps/Caps.tsx
+++ b/apps/web/app/dashboard/caps/Caps.tsx
@@ -4,6 +4,7 @@ import { videos } from "@cap/database/schema";
import moment from "moment";
import { VideoThumbnail } from "@/components/VideoThumbnail";
import { useRouter } from "next/navigation";
+import toast from "react-hot-toast";
export const Caps = ({ data }: { data: (typeof videos.$inferSelect)[] }) => {
const { push } = useRouter();
@@ -49,9 +50,9 @@ export const Caps = ({ data }: { data: (typeof videos.$inferSelect)[] }) => {
return (
<div
key={index}
- className="rounded-xl border border-filler overflow-hidden group"
+ className="rounded-xl border border-filler overflow-hidden"
>
- <a href={`/share/${cap.id}`}>
+ <a className="group" href={`/share/${cap.id}`}>
<div>
<VideoThumbnail
userId={cap.ownerId}
@@ -59,13 +60,35 @@ export const Caps = ({ data }: { data: (typeof videos.$inferSelect)[] }) => {
alt={`${cap.name} Thumbnail`}
/>
</div>
- <div className="p-4">
- <p className="font-medium">{cap.name}</p>
- <p className="text-sm text-gray-400">
- {moment(cap.createdAt).fromNow()}
- </p>
- </div>
</a>
+ <div className="p-4">
+ <p className="font-medium">{cap.name}</p>
+ <p className="text-sm text-gray-400">
+ {moment(cap.createdAt).fromNow()}
+ </p>
+ <div className="mt-3">
+ <input
+ className="text-sm cursor-pointer bg-white p-2 w-full rounded-lg flex items-center justify-center border hover:border-primary-3 transition-all"
+ onClick={(event) => {
+ if (process.env.NEXT_PUBLIC_IS_CAP) {
+ navigator.clipboard.writeText(
+ `https://cap.link/${cap.id}`
+ );
+ } else {
+ navigator.clipboard.writeText(
+ `${process.env.NEXT_PUBLIC_URL}/share/${cap.id}`
+ );
+ }
+ toast.success("Link copied to clipboard!");
+ }}
+ value={
+ process.env.NEXT_PUBLIC_IS_CAP
+ ? `https://cap.link/${cap.id}`
+ : `${process.env.NEXT_PUBLIC_URL}/share/${cap.id}`
+ }
+ ></input>
+ </div>
+ </div>
</div>
);
})}
diff --git a/apps/web/app/share/[videoId]/_components/ShareHeader.tsx b/apps/web/app/share/[videoId]/_components/ShareHeader.tsx
index 118a8ac94..b4b65f4a9 100644
--- a/apps/web/app/share/[videoId]/_components/ShareHeader.tsx
+++ b/apps/web/app/share/[videoId]/_components/ShareHeader.tsx
@@ -6,6 +6,7 @@ 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,
@@ -42,76 +43,83 @@ export const ShareHeader = ({
};
return (
- <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">
- <div>
- <a
- href={`${process.env.NEXT_PUBLIC_URL}?referrer=${data.id}`}
- target="_blank"
- >
- <LogoBadge className="w-8 h-auto" />
- </a>
- </div>
- <div>
- {isEditing ? (
- <input
- value={title}
- onChange={(e) => setTitle(e.target.value)}
- onBlur={handleBlur}
- onKeyDown={handleKeyDown}
- autoFocus
- className="text-2xl font-semibold"
- />
- ) : (
- <h1
- className="text-2xl"
+ <>
+ <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">
+ <div>
+ <a
+ href={`${process.env.NEXT_PUBLIC_URL}?referrer=${data.id}`}
+ target="_blank"
+ >
+ <LogoBadge className="w-8 h-auto" />
+ </a>
+ </div>
+ <div>
+ {isEditing ? (
+ <input
+ value={title}
+ onChange={(e) => setTitle(e.target.value)}
+ onBlur={handleBlur}
+ onKeyDown={handleKeyDown}
+ autoFocus
+ className="text-2xl font-semibold"
+ />
+ ) : (
+ <h1
+ className="text-2xl"
+ onClick={() => {
+ if (
+ user !== null &&
+ user.userId.toString() === data.ownerId
+ ) {
+ setIsEditing(true);
+ }
+ }}
+ >
+ {title}
+ </h1>
+ )}
+ <p className="text-gray-400 text-sm">
+ {moment(data.createdAt).fromNow()}
+ </p>
+ </div>
+ <div>
+ <button
+ data-tooltip-id="clipboard"
+ data-tooltip-content="Copy link to clipboard"
+ className="bg-white p-2 w-8 h-8 rounded-lg flex items-center justify-center border hover:border-primary-3 transition-all"
onClick={() => {
- if (
- user !== null &&
- user.userId.toString() === data.ownerId
- ) {
- setIsEditing(true);
+ if (process.env.NEXT_PUBLIC_IS_CAP) {
+ navigator.clipboard.writeText(
+ `https://cap.link/${data.id}`
+ );
+ } else {
+ navigator.clipboard.writeText(
+ `${process.env.NEXT_PUBLIC_URL}/share/${data.id}`
+ );
}
+ toast.success("Link copied to clipboard!");
}}
>
- {title}
- </h1>
- )}
- <p className="text-gray-400 text-sm">
- {moment(data.createdAt).fromNow()}
- </p>
- </div>
- <div>
- <button
- className="bg-white p-2 w-8 h-8 rounded-lg flex items-center justify-center border hover:border-primary-3 transition-all"
- onClick={() => {
- if (process.env.NEXT_PUBLIC_IS_CAP) {
- navigator.clipboard.writeText(`https://cap.link/${data.id}`);
- } else {
- navigator.clipboard.writeText(
- `${process.env.NEXT_PUBLIC_URL}/share/${data.id}`
- );
- }
- toast.success("Link copied to clipboard!");
- }}
- >
- <LinkIcon className="w-5 h-5" />
- </button>
+ <LinkIcon className="w-5 h-5" />
+ </button>
+ </div>
</div>
+ {user !== null && (
+ <div className="hidden md:flex">
+ <Button
+ onClick={() => {
+ push(`${process.env.NEXT_PUBLIC_URL}/dashboard`);
+ }}
+ >
+ Go to Dashboard
+ </Button>
+ </div>
+ )}
</div>
- {user !== null && (
- <div className="hidden md:flex">
- <Button
- onClick={() => {
- push(`${process.env.NEXT_PUBLIC_URL}/dashboard`);
- }}
- >
- Go to Dashboard
- </Button>
- </div>
- )}
</div>
- </div>
+ </>
);
};
diff --git a/apps/web/app/share/[videoId]/_components/ShareVideo.tsx b/apps/web/app/share/[videoId]/_components/ShareVideo.tsx
index 1b537c6ba..dfb55fcba 100644
--- a/apps/web/app/share/[videoId]/_components/ShareVideo.tsx
+++ b/apps/web/app/share/[videoId]/_components/ShareVideo.tsx
@@ -285,7 +285,7 @@ export const ShareVideo = ({
onMouseLeave={() => setSeeking(false)}
onTouchEnd={handleSeekMouseUp}
>
- {comments !== null && (
+ {!isLoading && comments !== null && (
<div className="w-full -mt-5">
{comments.map((comment) => {
if (comment.timestamp === null) return null;