Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(web): move share branding into header with owner row layout
Richie McIlroy9bdcb9857057
diff --git a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx b/apps/web/app/s/[videoId]/_components/ShareHeader.tsxindex e997dac86..049cfbc2a 100644--- a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx+++ b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx@@ -1,7 +1,7 @@"use client";import { buildEnv, NODE_ENV } from "@cap/env";-import { Button } from "@cap/ui";+import { Button, Logo } from "@cap/ui";import type { ViewerSettingKey } from "@cap/web-backend";import {faChartSimple,@@ -9,22 +9,26 @@ import {faLock,} from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";-import { Check, Clock, Copy, Globe2, Scissors } from "lucide-react";+import { Check, Clock, Copy, Globe2, Pencil, Scissors, X } from "lucide-react";import moment from "moment";+import Image from "next/image";import { useRouter } from "next/navigation";import { useEffect, useRef, useState } from "react";import { toast } from "sonner";+import {+ hideShareableLinkCapLogo,+ selectShareableLinkBrandingOrganization,+} from "@/actions/organization/shareable-link-icon";import { editTitle } from "@/actions/videos/edit-title";import { useDashboardContext } from "@/app/(org)/dashboard/Contexts";import { SharingDialog } from "@/app/(org)/dashboard/caps/components/SharingDialog";import type { Spaces } from "@/app/(org)/dashboard/dashboard-data";import { useCurrentUser } from "@/app/Layout/AuthContext";import { SignedImageUrl } from "@/components/SignedImageUrl";-import { Tooltip } from "@/components/Tooltip";import { UpgradeModal } from "@/components/UpgradeModal";import { usePublicEnv } from "@/utils/public-env";import { navigateWithTransition } from "@/utils/view-transition";-import type { VideoData } from "../types";+import type { SharePageBranding, VideoData } from "../types";export const ShareHeader = ({data,@@ -33,6 +37,8 @@ export const ShareHeader = ({sharedOrganizations = [],sharedSpaces = [],spacesData = null,+ branding,+ canManageSharePageBranding = false,}: {data: VideoData;customDomain?: string | null;@@ -56,6 +62,8 @@ export const ShareHeader = ({hasPassword?: boolean;}[];spacesData?: Spaces[] | null;+ branding?: SharePageBranding | null;+ canManageSharePageBranding?: boolean;}) => {const user = useCurrentUser();const { push, refresh } = useRouter();@@ -66,6 +74,9 @@ export const ShareHeader = ({const [linkCopied, setLinkCopied] = useState(false);const [showCopyOptions, setShowCopyOptions] = useState(false);const [capturedTime, setCapturedTime] = useState(0);+ const [isHidingBranding, setIsHidingBranding] = useState(false);+ const [isOpeningBrandingSettings, setIsOpeningBrandingSettings] =+ useState(false);const copyOptionsRef = useRef<HTMLDivElement>(null);useEffect(() => {@@ -249,6 +260,106 @@ export const ShareHeader = ({navigateWithTransition("edit-enter", () => push(`/s/${data.id}/edit`));};+ const handleHideBranding = async () => {+ if (!user?.isPro) {+ setUpgradeModalOpen(true);+ return;+ }++ setIsHidingBranding(true);++ try {+ await hideShareableLinkCapLogo(data.orgId);+ toast.success("Cap logo hidden");+ refresh();+ } catch (error) {+ toast.error(+ error instanceof Error ? error.message : "Failed to hide Cap logo",+ );+ } finally {+ setIsHidingBranding(false);+ }+ };++ const handleEditBranding = async () => {+ if (!user?.isPro) {+ setUpgradeModalOpen(true);+ return;+ }++ setIsOpeningBrandingSettings(true);++ try {+ await selectShareableLinkBrandingOrganization(data.orgId);+ push("/dashboard/settings/organization");+ } catch (error) {+ toast.error(+ error instanceof Error+ ? error.message+ : "Failed to open organization settings",+ );+ setIsOpeningBrandingSettings(false);+ }+ };++ const renderBranding = () => {+ if (!branding) return null;++ return (+ <div className="group relative inline-flex shrink-0 items-center">+ {canManageSharePageBranding && (+ <div className="pointer-events-none absolute left-0 top-full z-10 mt-1 flex items-center gap-1 rounded-full border border-gray-5 bg-white p-1 opacity-0 shadow-sm transition-opacity group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100">+ <Button+ variant="gray"+ size="xs"+ aria-label="Edit shareable link branding"+ className="h-7 gap-1 whitespace-nowrap rounded-full px-2 text-[11px]"+ disabled={isOpeningBrandingSettings}+ onClick={handleEditBranding}+ >+ <Pencil className="size-3.5 text-gray-12" />+ Change logo+ </Button>+ {branding.type === "cap" && (+ <Button+ variant="gray"+ size="xs"+ aria-label="Hide Cap logo"+ className="h-7 gap-1 whitespace-nowrap rounded-full px-2 text-[11px]"+ disabled={isHidingBranding}+ onClick={handleHideBranding}+ >+ <X className="size-3.5 text-gray-12" />+ Remove+ </Button>+ )}+ </div>+ )}+ {branding.type === "custom" ? (+ <div className="inline-flex h-11 max-w-56 items-center justify-center">+ <Image+ src={branding.imageUrl}+ alt={`${branding.name} logo`}+ width={176}+ height={32}+ unoptimized+ className="max-h-8 w-auto max-w-44 object-contain"+ />+ </div>+ ) : (+ <a+ target="_blank"+ rel="noreferrer"+ href={`/?ref=video_${data.id}`}+ className="inline-flex h-11 items-center"+ >+ <Logo className="h-7 w-auto" />+ </a>+ )}+ </div>+ );+ };+return (<>{userIsOwnerAndNotPro && (@@ -282,23 +393,25 @@ export const ShareHeader = ({onUpgradeRequest={setUpgradeModalOpen}/><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="space-y-3">- <div className="flex flex-col lg:min-w-[400px]">+ <div className="flex flex-col gap-4">+ <div className="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">+ <div className="flex min-w-0 items-center gap-3 lg:min-w-[400px]">+ {renderBranding()}+ {branding && <div className="h-7 w-px shrink-0 bg-gray-6" />}+ <div className="min-w-0 flex-1">{isEditing ? (<inputvalue={title}onChange={(e) => setTitle(e.target.value)}onBlur={handleBlur}onKeyDown={handleKeyDown}- className="w-full text-xl sm:text-2xl"+ className="w-full min-w-0 text-xl sm:text-2xl"/>) : (<h1role={isOwner ? "button" : undefined}tabIndex={isOwner ? 0 : undefined}- className="text-xl sm:text-2xl"+ className="truncate text-xl sm:text-2xl"onClick={() => {if (isOwner) {setIsEditing(true);@@ -318,29 +431,8 @@ export const ShareHeader = ({</h1>)}</div>- <div className="flex gap-7 items-center">- <div className="flex gap-2 items-center">- {data.name && (- <SignedImageUrl- name={data.name}- image={data.owner.image}- className="size-8"- letterClass="text-base"- />- )}- <div className="flex flex-col text-left">- <p className="text-sm text-gray-12">{data.owner.name}</p>- <p className="text-xs text-gray-10">- {moment(data.createdAt).fromNow()}- </p>- </div>- </div>- {user && renderSharedStatus()}- </div></div>- </div>- {user !== null && (- <div className="flex space-x-2">+ {user !== null && (<div><div className="flex gap-2 items-center">{(data.hasPassword || data.hasInheritedPassword) && (@@ -350,8 +442,14 @@ export const ShareHeader = ({/>)}<div className="relative" ref={copyOptionsRef}>- <Button variant="white" onClick={handleCopyClick}>- {getDisplayLink()}+ <Button+ variant="white"+ className="max-w-full px-3"+ onClick={handleCopyClick}+ >+ <span className="max-w-[70vw] truncate sm:max-w-96">+ {getDisplayLink()}+ </span>{linkCopied ? (<Check className="ml-2 w-4 h-4 svgpathanimation" />) : (@@ -391,69 +489,71 @@ export const ShareHeader = ({</button>)}</div>- {user !== null && canEditVideo && (+ )}+ </div>+ <div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">+ <div className="flex flex-wrap gap-x-7 gap-y-2 items-center">+ <div className="flex gap-2 items-center">+ {data.name && (+ <SignedImageUrl+ name={data.name}+ image={data.owner.image}+ className="size-8"+ letterClass="text-base"+ />+ )}+ <div className="flex flex-col text-left">+ <p className="text-sm text-gray-12">{data.owner.name}</p>+ <p className="text-xs text-gray-10">+ {moment(data.createdAt).fromNow()}+ </p>+ </div>+ </div>+ {user && renderSharedStatus()}+ </div>+ {user !== null && (+ <div className="flex flex-wrap items-center gap-2 sm:justify-end">+ {isOwner && (+ <>+ {canEditVideo && (+ <Button+ variant="gray"+ size="xs"+ className="h-8 gap-1.5 rounded-full px-2.5 text-xs"+ onClick={handleEditVideo}+ >+ <Scissors className="size-3.5 text-gray-12" />+ Edit video+ </Button>+ )}+ <Button+ variant="gray"+ size="xs"+ className="h-8 gap-1.5 rounded-full px-2.5 text-xs"+ onClick={() => {+ push(`/dashboard/analytics?capId=${data.id}`);+ }}+ >+ <FontAwesomeIcon+ className="size-3.5 text-gray-12"+ icon={faChartSimple}+ />+ View analytics+ </Button>+ </>+ )}<Button- variant="gray"- aria-label="Edit video"- className="rounded-full flex items-center justify-center md:hidden"- onClick={handleEditVideo}+ size="xs"+ className="h-8 rounded-full px-2.5 text-xs"+ onClick={() => {+ push("/dashboard/caps?page=1");+ }}>- <Scissors className="size-4 text-gray-12" />+ Go to dashboard</Button>- )}- {user !== null && (- <div className="hidden md:flex gap-2">- {isOwner && (- <>- {canEditVideo && (- <Tooltip- content="Edit video"- className="bg-gray-12 text-gray-1 border-gray-11 shadow-lg"- delayDuration={100}- >- <Button- variant="gray"- className="rounded-full flex items-center justify-center"- onClick={handleEditVideo}- >- <Scissors className="size-4 text-gray-12" />- </Button>- </Tooltip>- )}- <Tooltip- content="View analytics"- className="bg-gray-12 text-gray-1 border-gray-11 shadow-lg"- delayDuration={100}- >- <Button- variant="gray"- className="rounded-full flex items-center justify-center"- onClick={() => {- push(`/dashboard/analytics?capId=${data.id}`);- }}- >- <FontAwesomeIcon- className="size-4 text-gray-12"- icon={faChartSimple}- />- </Button>- </Tooltip>- </>- )}- <Button- onClick={() => {- push("/dashboard/caps?page=1");- }}- >- <span className="hidden text-sm text-white lg:block">- Go to- </span>{" "}- Dashboard- </Button>- </div>- )}- </div>- )}+ </div>+ )}+ </div></div></div><UpgradeModaldiff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsxindex e8d322b06..dcf898332 100644--- a/apps/web/app/s/[videoId]/page.tsx+++ b/apps/web/app/s/[videoId]/page.tsx@@ -34,7 +34,6 @@ import { and, eq, type InferSelectModel, isNull, sql } from "drizzle-orm";import { Effect, Option } from "effect";import type { Metadata } from "next";import { headers } from "next/headers";-import Image from "next/image";import Link from "next/link";import { notFound } from "next/navigation";import { getVideoAnalytics } from "@/actions/videos/get-analytics";@@ -43,6 +42,10 @@ import {type OrganizationSettings,} from "@/app/(org)/dashboard/dashboard-data";import { createNotification } from "@/lib/Notification";+import {+ canManageOrganizationSettings,+ getEffectiveOrganizationRole,+} from "@/lib/permissions/roles";import * as EffectRuntime from "@/lib/server";import { runPromise } from "@/lib/server";import {@@ -59,6 +62,7 @@ import { isAiGenerationEnabled } from "@/utils/flags";import { PasswordOverlay } from "./_components/PasswordOverlay";import { ShareHeader } from "./_components/ShareHeader";import { Share } from "./Share";+import type { SharePageBranding } from "./types";// Helper function to fetch shared spaces data for a videoasync function getSharedSpacesForVideo(videoId: Video.VideoId) {@@ -163,16 +167,6 @@ const renderPolicyDenied = (videoId: Video.VideoId, reason?: string) =>const renderNoSuchElement = () => Effect.sync(() => notFound());-type SharePageBranding =- | {- type: "custom";- imageUrl: ImageUpload.ImageUrl;- name: string;- }- | {- type: "cap";- };-function getSharePageBranding(data: {owner: { isPro: boolean };orgSettings?: OrganizationSettings | null;@@ -203,42 +197,6 @@ function getSharePageBranding(data: {return { type: "cap" };}-function SharePageBranding({- branding,- videoId,-}: {- branding: SharePageBranding | null;- videoId: Video.VideoId;-}) {- if (!branding) return null;-- return (- <div className="flex justify-center pt-8">- {branding.type === "custom" ? (- <div className="inline-flex h-12 max-w-64 items-center justify-center rounded-xl border border-gray-5 bg-white px-4">- <Image- src={branding.imageUrl}- alt={`${branding.name} logo`}- width={208}- height={32}- unoptimized- className="max-h-8 w-auto max-w-52 object-contain"- />- </div>- ) : (- <a- target="_blank"- rel="noreferrer"- href={`/?ref=video_${videoId}`}- className="inline-flex items-center rounded-full border border-gray-5 bg-white px-4 py-2"- >- <Logo className="h-7 w-auto" />- </a>- )}- </div>- );-}-const getShareVideoPageCatchers = (videoId: Video.VideoId) => ({PolicyDenied: (e: Policy.PolicyDeniedError) =>renderPolicyDenied(videoId, e.reason),@@ -755,6 +713,41 @@ async function AuthorizedContent({customDomainPromise,]);+ const canManageSharePageBranding = await (async () => {+ if (!userId) return false;++ const [organizationAccess] = await db()+ .select({+ ownerId: organizations.ownerId,+ memberRole: organizationMembers.role,+ })+ .from(organizations)+ .leftJoin(+ organizationMembers,+ and(+ eq(organizationMembers.organizationId, organizations.id),+ eq(organizationMembers.userId, userId),+ ),+ )+ .where(+ and(+ eq(organizations.id, video.orgId),+ isNull(organizations.tombstoneAt),+ ),+ )+ .limit(1);++ if (!organizationAccess) return false;++ return canManageOrganizationSettings(+ getEffectiveOrganizationRole({+ userId,+ ownerId: organizationAccess.ownerId,+ memberRole: organizationAccess.memberRole,+ }),+ );+ })();+const videoWithOrganizationInfo = await Effect.gen(function* () {const imageUploads = yield* ImageUploads;@@ -797,10 +790,6 @@ async function AuthorizedContent({return (<div className="container flex-1 px-4 mx-auto">- <SharePageBranding- branding={getSharePageBranding(videoWithOrganizationInfo)}- videoId={video.id}- /><ShareHeaderdata={{...videoWithOrganizationInfo,@@ -816,6 +805,8 @@ async function AuthorizedContent({sharedSpaces={sharedSpaces}userOrganizations={userOrganizations}spacesData={spacesData}+ branding={getSharePageBranding(videoWithOrganizationInfo)}+ canManageSharePageBranding={canManageSharePageBranding}/><Share