Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Add video name + animated title reveal

Richie McIlroy5608985a0b65
diff --git a/apps/web/actions/videos/get-status.ts b/apps/web/actions/videos/get-status.ts
index 4d3bc5c4f..95dda29d2 100644
--- a/apps/web/actions/videos/get-status.ts
+++ b/apps/web/actions/videos/get-status.ts
@@ -34,6 +34,7 @@ type AiGenerationStatus =
export interface VideoStatusResult {
transcriptionStatus: TranscriptionStatus | null;
aiGenerationStatus: AiGenerationStatus | null;
+ name: string | null;
aiTitle: string | null;
summary: string | null;
chapters: { title: string; start: number }[] | null;
@@ -93,6 +94,7 @@ export async function getVideoStatus(
transcriptionStatus: null,
aiGenerationStatus:
(metadata.aiGenerationStatus as AiGenerationStatus) || null,
+ name: video.name,
aiTitle: metadata.aiTitle || null,
summary: metadata.summary || null,
chapters: metadata.chapters || null,
@@ -114,6 +116,7 @@ export async function getVideoStatus(
transcriptionStatus: "PROCESSING",
aiGenerationStatus:
(metadata.aiGenerationStatus as AiGenerationStatus) || null,
+ name: video.name,
aiTitle: metadata.aiTitle || null,
summary: metadata.summary || null,
chapters: metadata.chapters || null,
@@ -127,6 +130,7 @@ export async function getVideoStatus(
transcriptionStatus: "ERROR",
aiGenerationStatus:
(metadata.aiGenerationStatus as AiGenerationStatus) || null,
+ name: video.name,
aiTitle: metadata.aiTitle || null,
summary: metadata.summary || null,
chapters: metadata.chapters || null,
@@ -140,6 +144,7 @@ export async function getVideoStatus(
transcriptionStatus: "ERROR",
aiGenerationStatus:
(metadata.aiGenerationStatus as AiGenerationStatus) || null,
+ name: video.name,
aiTitle: metadata.aiTitle || null,
summary: metadata.summary || null,
chapters: metadata.chapters || null,
@@ -181,6 +186,7 @@ export async function getVideoStatus(
transcriptionStatus:
(video.transcriptionStatus as TranscriptionStatus) || null,
aiGenerationStatus: "QUEUED" as AiGenerationStatus,
+ name: video.name,
aiTitle: metadata.aiTitle || null,
summary: metadata.summary || null,
chapters: metadata.chapters || null,
@@ -199,6 +205,7 @@ export async function getVideoStatus(
(video.transcriptionStatus as TranscriptionStatus) || null,
aiGenerationStatus:
(metadata.aiGenerationStatus as AiGenerationStatus) || null,
+ name: video.name,
aiTitle: metadata.aiTitle || null,
summary: metadata.summary || null,
chapters: metadata.chapters || null,
diff --git a/apps/web/app/(org)/dashboard/Contexts.tsx b/apps/web/app/(org)/dashboard/Contexts.tsx
index 44c86c4c0..f130e0310 100644
--- a/apps/web/app/(org)/dashboard/Contexts.tsx
+++ b/apps/web/app/(org)/dashboard/Contexts.tsx
@@ -3,7 +3,13 @@
import { buildEnv } from "@cap/env";
import Cookies from "js-cookie";
import { redirect, usePathname } from "next/navigation";
-import { createContext, useContext, useEffect, useState } from "react";
+import {
+ createContext,
+ useCallback,
+ useContext,
+ useEffect,
+ useState,
+} from "react";
import { InviteDialog } from "@/app/(org)/dashboard/settings/organization/components/InviteDialog";
import { type CurrentUser, useCurrentUser } from "@/app/Layout/AuthContext";
import { UpgradeModal } from "@/components/UpgradeModal";
@@ -41,12 +47,15 @@ type SharedContext = {
};
type ITheme = "light" | "dark";
+type SetThemeOptions = {
+ persist?: boolean;
+};
const DashboardContext = createContext<SharedContext>({} as SharedContext);
const ThemeContext = createContext<{
theme: ITheme;
- setThemeHandler: (newTheme: ITheme) => void;
+ setThemeHandler: (newTheme: ITheme, options?: SetThemeOptions) => void;
}>({
theme: "light",
setThemeHandler: () => {},
@@ -134,13 +143,18 @@ export function DashboardContexts({
}
}, [spacesData, pathname]);
- const setThemeHandler = (newTheme: ITheme) => {
- setTheme(newTheme);
- document.body.className = newTheme;
- Cookies.set("theme", newTheme, {
- expires: 365,
- });
- };
+ const setThemeHandler = useCallback(
+ (newTheme: ITheme, options?: SetThemeOptions) => {
+ setTheme(newTheme);
+ document.body.className = newTheme;
+ if (options?.persist !== false) {
+ Cookies.set("theme", newTheme, {
+ expires: 365,
+ });
+ }
+ },
+ [],
+ );
useEffect(() => {
if (Cookies.get("theme")) {
document.body.className = Cookies.get("theme") as ITheme;
diff --git a/apps/web/app/globals.css b/apps/web/app/globals.css
index 59d5e8f8a..8f0b2defe 100644
--- a/apps/web/app/globals.css
+++ b/apps/web/app/globals.css
@@ -812,6 +812,68 @@ footer a {
animation: slideUp 0.3s ease-out forwards;
}
+@keyframes ai-title-shimmer {
+ 0% {
+ transform: translateX(-100%);
+ }
+ 100% {
+ transform: translateX(100%);
+ }
+}
+
+@keyframes ai-title-skeleton-in {
+ from {
+ opacity: 0;
+ }
+ to {
+ opacity: 1;
+ }
+}
+
+@keyframes ai-title-skeleton-out {
+ 0%,
+ 55% {
+ clip-path: inset(0 0 0 0);
+ }
+ 100% {
+ clip-path: inset(0 0 0 100%);
+ }
+}
+
+.ai-title-skeleton {
+ position: absolute;
+ inset: 0;
+ overflow: hidden;
+ border-radius: 0.5rem;
+ background: var(--gray-3);
+ opacity: 1;
+ pointer-events: none;
+ animation:
+ ai-title-skeleton-in 0.16s ease-out both,
+ ai-title-skeleton-out 1s cubic-bezier(0.22, 1, 0.36, 1) both;
+}
+
+.ai-title-skeleton::after {
+ content: "";
+ position: absolute;
+ inset: 0;
+ background: linear-gradient(
+ 100deg,
+ transparent 20%,
+ var(--gray-5) 45%,
+ var(--gray-6) 50%,
+ var(--gray-5) 55%,
+ transparent 80%
+ );
+ animation: ai-title-shimmer 1s ease-in-out infinite;
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .ai-title-skeleton {
+ display: none;
+ }
+}
+
.media-player video::-webkit-media-text-track-display {
@apply !bottom-12 !top-auto !mb-0;
}
diff --git a/apps/web/app/s/[videoId]/Share.tsx b/apps/web/app/s/[videoId]/Share.tsx
index 4e99bc2c5..3285097a2 100644
--- a/apps/web/app/s/[videoId]/Share.tsx
+++ b/apps/web/app/s/[videoId]/Share.tsx
@@ -166,6 +166,7 @@ const useVideoStatus = (
aiGenerationEnabled: boolean,
initialData?: {
transcriptionStatus?: string | null;
+ name?: string | null;
aiData?: {
title?: string | null;
summary?: string | null;
@@ -194,6 +195,7 @@ const useVideoStatus = (
aiGenerationStatus:
(initialData.aiData?.aiGenerationStatus as AiGenerationStatus) ||
null,
+ name: initialData.name ?? null,
aiTitle: initialData.aiData?.title || null,
summary: initialData.aiData?.summary || null,
chapters: initialData.aiData?.chapters || null,
@@ -286,6 +288,7 @@ export const Share = ({
const { data: videoStatus } = useVideoStatus(data.id, aiGenerationEnabled, {
transcriptionStatus: data.transcriptionStatus,
+ name: data.name,
aiData: initialAiData,
});
diff --git a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
index 049cfbc2a..0ebedd592 100644
--- a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
+++ b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
@@ -9,6 +9,7 @@ import {
faLock,
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { skipToken, useQuery, useQueryClient } from "@tanstack/react-query";
import { Check, Clock, Copy, Globe2, Pencil, Scissors, X } from "lucide-react";
import moment from "moment";
import Image from "next/image";
@@ -20,6 +21,7 @@ import {
selectShareableLinkBrandingOrganization,
} from "@/actions/organization/shareable-link-icon";
import { editTitle } from "@/actions/videos/edit-title";
+import type { VideoStatusResult } from "@/actions/videos/get-status";
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";
@@ -67,8 +69,15 @@ export const ShareHeader = ({
}) => {
const user = useCurrentUser();
const { push, refresh } = useRouter();
+ const queryClient = useQueryClient();
+ const { data: videoStatus } = useQuery<VideoStatusResult>({
+ queryKey: ["videoStatus", data.id],
+ queryFn: skipToken,
+ });
const [isEditing, setIsEditing] = useState(false);
- const [title, setTitle] = useState(data.name);
+ const [displayTitle, setDisplayTitle] = useState(data.name);
+ const [editValue, setEditValue] = useState(data.name);
+ const [isTitleRevealing, setIsTitleRevealing] = useState(false);
const [upgradeModalOpen, setUpgradeModalOpen] = useState(false);
const [isSharingDialogOpen, setIsSharingDialogOpen] = useState(false);
const [linkCopied, setLinkCopied] = useState(false);
@@ -78,6 +87,13 @@ export const ShareHeader = ({
const [isOpeningBrandingSettings, setIsOpeningBrandingSettings] =
useState(false);
const copyOptionsRef = useRef<HTMLDivElement>(null);
+ const suppressTitleRevealRef = useRef(false);
+ const titleSwapTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(
+ null,
+ );
+ const titleRevealEndTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(
+ null,
+ );
useEffect(() => {
if (!showCopyOptions) return;
@@ -101,17 +117,67 @@ export const ShareHeader = ({
const { webUrl } = usePublicEnv();
+ const resolvedTitle = videoStatus?.name ?? data.name;
+
useEffect(() => {
- setTitle(data.name);
- }, [data.name]);
+ if (isEditing) return;
+ if (resolvedTitle === displayTitle) return;
+
+ if (suppressTitleRevealRef.current) {
+ suppressTitleRevealRef.current = false;
+ setDisplayTitle(resolvedTitle);
+ return;
+ }
+
+ const prefersReducedMotion =
+ typeof window !== "undefined" &&
+ window.matchMedia("(prefers-reduced-motion: reduce)").matches;
+
+ if (prefersReducedMotion) {
+ setDisplayTitle(resolvedTitle);
+ return;
+ }
+
+ setIsTitleRevealing(true);
+ if (titleSwapTimeoutRef.current) clearTimeout(titleSwapTimeoutRef.current);
+ if (titleRevealEndTimeoutRef.current)
+ clearTimeout(titleRevealEndTimeoutRef.current);
+
+ titleSwapTimeoutRef.current = setTimeout(() => {
+ setDisplayTitle(resolvedTitle);
+ }, 160);
+ titleRevealEndTimeoutRef.current = setTimeout(() => {
+ setIsTitleRevealing(false);
+ }, 1000);
+ }, [resolvedTitle, displayTitle, isEditing]);
+
+ useEffect(
+ () => () => {
+ if (titleSwapTimeoutRef.current)
+ clearTimeout(titleSwapTimeoutRef.current);
+ if (titleRevealEndTimeoutRef.current)
+ clearTimeout(titleRevealEndTimeoutRef.current);
+ },
+ [],
+ );
+
+ const startEditing = () => {
+ setEditValue(displayTitle);
+ setIsEditing(true);
+ };
const handleBlur = async () => {
setIsEditing(false);
- const next = title.trim();
- if (next === "" || next === data.name) return;
+ const next = editValue.trim();
+ if (next === "" || next === displayTitle) return;
try {
- await editTitle(data.id, title);
+ await editTitle(data.id, next);
toast.success("Video title updated");
+ suppressTitleRevealRef.current = true;
+ queryClient.setQueryData<VideoStatusResult>(
+ ["videoStatus", data.id],
+ (old) => (old ? { ...old, name: next } : old),
+ );
refresh();
} catch (error) {
if (error instanceof Error) {
@@ -401,34 +467,39 @@ export const ShareHeader = ({
<div className="min-w-0 flex-1">
{isEditing ? (
<input
- value={title}
- onChange={(e) => setTitle(e.target.value)}
+ value={editValue}
+ onChange={(e) => setEditValue(e.target.value)}
onBlur={handleBlur}
onKeyDown={handleKeyDown}
className="w-full min-w-0 text-xl sm:text-2xl"
/>
) : (
- <h1
- role={isOwner ? "button" : undefined}
- tabIndex={isOwner ? 0 : undefined}
- className="truncate text-xl sm:text-2xl"
- onClick={() => {
- if (isOwner) {
- setIsEditing(true);
- }
- }}
- onKeyDown={(event) => {
- if (
- isOwner &&
- (event.key === "Enter" || event.key === " ")
- ) {
- event.preventDefault();
- setIsEditing(true);
- }
- }}
- >
- {title}
- </h1>
+ <div className="relative inline-flex min-w-0 max-w-full align-middle">
+ <h1
+ role={isOwner ? "button" : undefined}
+ tabIndex={isOwner ? 0 : undefined}
+ className="truncate text-xl sm:text-2xl"
+ onClick={() => {
+ if (isOwner) {
+ startEditing();
+ }
+ }}
+ onKeyDown={(event) => {
+ if (
+ isOwner &&
+ (event.key === "Enter" || event.key === " ")
+ ) {
+ event.preventDefault();
+ startEditing();
+ }
+ }}
+ >
+ {displayTitle}
+ </h1>
+ {isTitleRevealing && (
+ <span aria-hidden className="ai-title-skeleton" />
+ )}
+ </div>
)}
</div>
</div>