Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

web: re-arrange cap card buttons, share page show owner, and more... (#1156)

Ameer Al Ashhab696a695a68c1
diff --git a/apps/web/app/(org)/dashboard/caps/Caps.tsx b/apps/web/app/(org)/dashboard/caps/Caps.tsx
index 10869c80a..7c98c8b43 100644
--- a/apps/web/app/(org)/dashboard/caps/Caps.tsx
+++ b/apps/web/app/(org)/dashboard/caps/Caps.tsx
@@ -266,7 +266,7 @@ export const Caps = ({
[data, isUploading, uploadingCapId],
);
- if (count === 0) return <EmptyCapState />;
+ if (count === 0 && folders.length === 0) return <EmptyCapState />;
return (
<div className="flex relative flex-col w-full h-full">
diff --git a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
index 6fc8db838..a90727280 100644
--- a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
+++ b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
@@ -18,6 +18,7 @@ import {
faGear,
faLink,
faLock,
+ faShare,
faTrash,
faUnlock,
faVideo,
@@ -42,6 +43,7 @@ import {
} from "@/components/VideoThumbnail";
import { useEffectMutation } from "@/lib/EffectRuntime";
import { withRpc } from "@/lib/Rpcs";
+import { usePublicEnv } from "@/utils/public-env";
import { PasswordDialog } from "../PasswordDialog";
import { SettingsDialog } from "../SettingsDialog";
import { SharingDialog } from "../SharingDialog";
@@ -121,6 +123,8 @@ export const CapCard = ({
const [passwordProtected, setPasswordProtected] = useState(
cap.hasPassword || false,
);
+ const { webUrl } = usePublicEnv();
+
const [copyPressed, setCopyPressed] = useState(false);
const [isDragging, setIsDragging] = useState(false);
const [isSettingsDialogOpen, setIsSettingsDialogOpen] = useState(false);
@@ -345,72 +349,74 @@ export const CapCard = ({
"top-2 right-2 flex-col gap-2 z-[51]",
)}
>
- {isOwner ? (
- <CapCardButton
- tooltipContent="Settings"
- onClick={(e) => {
- e.stopPropagation();
- setIsSettingsDialogOpen(true);
- }}
- className="delay-0"
- icon={() => {
- return <FontAwesomeIcon className="size-4" icon={faGear} />;
- }}
- />
- ) : (
- <CapCardButton
- tooltipContent="Download Cap"
- onClick={(e) => {
- e.stopPropagation();
- handleDownload();
- }}
- className="delay-0"
- icon={() => (
- <FontAwesomeIcon className="size-4" icon={faDownload} />
- )}
- />
- )}
<CapCardButton
- tooltipContent="Copy link"
+ tooltipContent="Share"
onClick={(e) => {
e.stopPropagation();
- handleCopy(
- buildEnv.NEXT_PUBLIC_IS_CAP &&
- NODE_ENV === "production" &&
- customDomain &&
- domainVerified
- ? `https://${customDomain}/s/${cap.id}`
- : buildEnv.NEXT_PUBLIC_IS_CAP && NODE_ENV === "production"
- ? `https://cap.link/${cap.id}`
- : `${location.origin}/s/${cap.id}`,
- );
+ setIsSharingDialogOpen(true);
}}
className="delay-0"
- icon={() => {
- return !copyPressed ? (
- <FontAwesomeIcon
- className="text-gray-12 size-4"
- icon={faLink}
- />
- ) : (
- <svg
- xmlns="http://www.w3.org/2000/svg"
- width="24"
- height="24"
- viewBox="0 0 24 24"
- fill="none"
- stroke="currentColor"
- strokeWidth="2"
- strokeLinecap="round"
- strokeLinejoin="round"
- className="text-gray-12 size-5 svgpathanimation"
- >
- <path d="M20 6 9 17l-5-5" />
- </svg>
- );
+ icon={<FontAwesomeIcon icon={faShare} />}
+ />
+
+ <CapCardButton
+ tooltipContent="Download Cap"
+ onClick={(e) => {
+ e.stopPropagation();
+ handleDownload();
}}
+ className="delay-0"
+ icon={<FontAwesomeIcon icon={faDownload} />}
/>
+ {!isOwner && (
+ <CapCardButton
+ tooltipContent="Copy link"
+ onClick={(e) => {
+ e.stopPropagation();
+ handleCopy(
+ NODE_ENV === "development"
+ ? `${webUrl}/s/${cap.id}`
+ : buildEnv.NEXT_PUBLIC_IS_CAP &&
+ customDomain &&
+ domainVerified
+ ? `https://${customDomain}/s/${cap.id}`
+ : buildEnv.NEXT_PUBLIC_IS_CAP &&
+ !customDomain &&
+ !domainVerified
+ ? `https://cap.link/${cap.id}`
+ : `${webUrl}/s/${cap.id}`,
+ );
+ }}
+ className="delay-0"
+ icon={
+ <>
+ {!copyPressed ? (
+ <FontAwesomeIcon
+ className="text-gray-12 size-4"
+ icon={faLink}
+ />
+ ) : (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ className="text-gray-12 size-5 svgpathanimation"
+ >
+ <path d="M20 6 9 17l-5-5" />
+ </svg>
+ )}
+ </>
+ }
+ />
+ )}
+
{isOwner && (
<DropdownMenu modal={false} onOpenChange={setIsDropdownOpen}>
<DropdownMenuTrigger asChild suppressHydrationWarning>
@@ -418,9 +424,7 @@ export const CapCard = ({
<CapCardButton
tooltipContent="More options"
className="delay-75"
- icon={() => (
- <FontAwesomeIcon className="size-4" icon={faEllipsis} />
- )}
+ icon={<FontAwesomeIcon icon={faEllipsis} />}
/>
</div>
</DropdownMenuTrigger>
@@ -432,12 +436,33 @@ export const CapCard = ({
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation();
- handleDownload();
+ setIsSettingsDialogOpen(true);
+ }}
+ className="flex gap-2 items-center rounded-lg"
+ >
+ <FontAwesomeIcon className="size-3" icon={faGear} />
+ <p className="text-sm text-gray-12">Settings</p>
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ onClick={(e) => {
+ e.stopPropagation();
+ handleCopy(
+ buildEnv.NEXT_PUBLIC_IS_CAP &&
+ NODE_ENV === "production" &&
+ customDomain &&
+ domainVerified
+ ? `https://${customDomain}/s/${cap.id}`
+ : buildEnv.NEXT_PUBLIC_IS_CAP &&
+ NODE_ENV === "production"
+ ? `https://cap.link/${cap.id}`
+ : `${location.origin}/s/${cap.id}`,
+ );
+ toast.success("Link copied to clipboard");
}}
className="flex gap-2 items-center rounded-lg"
>
- <FontAwesomeIcon className="size-3" icon={faDownload} />
- <p className="text-sm text-gray-12">Download</p>
+ <FontAwesomeIcon className="size-3" icon={faLink} />
+ <p className="text-sm text-gray-12">Copy link</p>
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => {
diff --git a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCardButton.tsx b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCardButton.tsx
index 61868a1f9..cf0724ed9 100644
--- a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCardButton.tsx
+++ b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCardButton.tsx
@@ -2,7 +2,8 @@
import { Button } from "@cap/ui";
import clsx from "clsx";
-import type { MouseEvent, ReactNode } from "react";
+import type { MouseEvent } from "react";
+import React from "react";
import { Tooltip } from "@/components/Tooltip";
interface CapCardButtonProps {
@@ -10,7 +11,7 @@ interface CapCardButtonProps {
onClick?: (e: MouseEvent) => void;
disabled?: boolean;
className: string;
- icon: () => ReactNode;
+ icon: React.JSX.Element;
asChild?: boolean;
}
@@ -36,7 +37,9 @@ export const CapCardButton = ({
size="sm"
aria-label={tooltipContent}
>
- {icon()}
+ {React.cloneElement(icon, {
+ className: clsx(icon.props.className, "size-3.5"),
+ })}
</Button>
</Tooltip>
);
diff --git a/apps/web/app/(org)/dashboard/caps/page.tsx b/apps/web/app/(org)/dashboard/caps/page.tsx
index b71d6ce16..754d9665d 100644
--- a/apps/web/app/(org)/dashboard/caps/page.tsx
+++ b/apps/web/app/(org)/dashboard/caps/page.tsx
@@ -227,6 +227,7 @@ export default async function CapsPage(props: PageProps<"/dashboard/caps">) {
.where(
and(
eq(folders.organizationId, user.activeOrganizationId),
+ eq(folders.createdById, user.id),
isNull(folders.parentId),
isNull(folders.spaceId),
),
diff --git a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
index 1401f11b8..50989fb70 100644
--- a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
+++ b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
@@ -3,13 +3,13 @@
import type { userSelectProps } from "@cap/database/auth/session";
import type { videos } from "@cap/database/schema";
import { buildEnv, NODE_ENV } from "@cap/env";
-import { Button } from "@cap/ui";
+import { Avatar, Button } from "@cap/ui";
import { userIsPro } from "@cap/utils";
import { faChevronDown, faLock } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-import clsx from "clsx";
import { Check, Copy, Globe2 } from "lucide-react";
import moment from "moment";
+import Image from "next/image";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { toast } from "sonner";
@@ -29,7 +29,10 @@ export const ShareHeader = ({
sharedSpaces = [],
spacesData = null,
}: {
- data: typeof videos.$inferSelect;
+ data: typeof videos.$inferSelect & {
+ ownerName?: string | null;
+ ownerImage?: string | null;
+ };
user: typeof userSelectProps | null;
customDomain?: string | null;
domainVerified?: boolean;
@@ -70,7 +73,8 @@ export const ShareHeader = ({
const handleBlur = async () => {
setIsEditing(false);
-
+ const next = title.trim();
+ if (next === "" || next === data.name) return;
try {
await editTitle(data.id, title);
toast.success("Video title updated");
@@ -135,9 +139,6 @@ export const ShareHeader = ({
};
const renderSharedStatus = () => {
- const baseClassName =
- "text-sm text-gray-10 transition-colors duration-200 flex items-center";
-
if (isOwner) {
const hasSpaceSharing =
sharedOrganizations?.length > 0 || effectiveSharedSpaces?.length > 0;
@@ -145,27 +146,39 @@ export const ShareHeader = ({
if (!hasSpaceSharing && !isPublic) {
return (
- <p
- className={clsx(baseClassName, "cursor-pointer hover:text-gray-12")}
+ <Button
+ className="px-3 w-fit"
+ size="xs"
+ variant="outline"
onClick={() => setIsSharingDialogOpen(true)}
>
Not shared{" "}
<FontAwesomeIcon className="ml-2 size-2.5" icon={faChevronDown} />
- </p>
+ </Button>
);
} else {
return (
- <p
- className={clsx(baseClassName, "cursor-pointer hover:text-gray-12")}
+ <Button
+ className="px-3 w-fit"
+ size="xs"
+ variant="outline"
onClick={() => setIsSharingDialogOpen(true)}
>
Shared{" "}
<FontAwesomeIcon className="ml-1 size-2.5" icon={faChevronDown} />
- </p>
+ </Button>
);
}
} else {
- return <p className={baseClassName}>Shared with you</p>;
+ return (
+ <Button
+ className="px-3 pointer-events-none w-fit"
+ size="xs"
+ variant="outline"
+ >
+ Shared with you
+ </Button>
+ );
}
};
@@ -199,8 +212,8 @@ export const ShareHeader = ({
<div className="mt-8">
<div className="flex flex-col gap-6 lg:flex-row lg:items-center lg:justify-between lg:gap-0">
<div className="items-center md:flex md:justify-between md:space-x-6">
- <div className="mb-3 md:mb-0">
- <div className="flex items-center space-x-3 lg:min-w-[400px]">
+ <div className="space-y-3">
+ <div className="flex flex-col lg:min-w-[400px]">
{isEditing ? (
<input
value={title}
@@ -208,7 +221,7 @@ export const ShareHeader = ({
onBlur={handleBlur}
onKeyDown={handleKeyDown}
autoFocus
- className="w-full text-xl font-semibold sm:text-2xl"
+ className="w-full text-xl sm:text-2xl"
/>
) : (
<h1
@@ -223,10 +236,29 @@ export const ShareHeader = ({
</h1>
)}
</div>
- {user && renderSharedStatus()}
- <p className="mt-1 text-sm text-gray-10">
- {moment(data.createdAt).fromNow()}
- </p>
+ <div className="flex gap-7 items-center">
+ <div className="flex gap-2 items-center">
+ {data.ownerImage ? (
+ <Image
+ src={data.ownerImage}
+ alt={data.ownerName || ""}
+ width={32}
+ unoptimized
+ height={32}
+ className="rounded-full"
+ />
+ ) : (
+ <Avatar name={data.ownerName} className="size-8" />
+ )}
+ <div className="flex flex-col text-left">
+ <p className="text-sm text-gray-12">{data.ownerName}</p>
+ <p className="text-xs text-gray-10">
+ {moment(data.createdAt).fromNow()}
+ </p>
+ </div>
+ </div>
+ {user && renderSharedStatus()}
+ </div>
</div>
</div>
{user !== null && (
diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsx
index 94a44f097..3a6a50987 100644
--- a/apps/web/app/s/[videoId]/page.tsx
+++ b/apps/web/app/s/[videoId]/page.tsx
@@ -270,6 +270,8 @@ export default async function ShareVideoPage(props: PageProps<"/s/[videoId]">) {
id: videos.id,
name: videos.name,
ownerId: videos.ownerId,
+ ownerName: users.name,
+ ownerImage: users.image,
orgId: videos.orgId,
createdAt: videos.createdAt,
updatedAt: videos.updatedAt,
@@ -363,6 +365,8 @@ async function AuthorizedContent({
sharedOrganization: { organizationId: Organisation.OrganisationId } | null;
hasPassword: boolean;
ownerIsPro?: boolean;
+ ownerName?: string | null;
+ ownerImage?: string | null;
orgSettings?: OrganizationSettings | null;
videoSettings?: OrganizationSettings | null;
};
@@ -466,6 +470,8 @@ async function AuthorizedContent({
id: videos.id,
name: videos.name,
ownerId: videos.ownerId,
+ ownerName: users.name,
+ ownerImage: users.image,
ownerIsPro:
sql`${users.stripeSubscriptionStatus} IN ('active','trialing','complete','paid') OR ${users.thirdPartyStripeSubscriptionId} IS NOT NULL`.mapWith(
Boolean,