Open source CapCut alternative.
TypeScript
feat(site): hover-play chat videos with audio in the shot grid and activity feed
David Leb7b973d08a3a
diff --git a/site/src/cut/components/ChatAssets.tsx b/site/src/cut/components/ChatAssets.tsxindex 53733673..06a64085 100644--- a/site/src/cut/components/ChatAssets.tsx+++ b/site/src/cut/components/ChatAssets.tsx@@ -1,6 +1,6 @@"use client";-import { useEffect, useRef, type ReactNode } from "react";+import { useEffect, type ReactNode } from "react";import type React from "react";import { Copy, ExternalLink, FileText, Film, Loader2, Maximize2, Plus } from "lucide-react";import { DropdownMenuItem } from "@/components/ui/dropdown-menu";@@ -14,6 +14,7 @@ import {type AssetRefKind,} from "@/cut/lib/assetRef";import { useElapsed } from "@/cut/hooks/useElapsed";+import { useHoverPlay } from "@/cut/hooks/useHoverPlay";import { useInView } from "@/cut/hooks/useInView";import { useGenerate } from "@/cut/lib/generate";import { lightboxItemFromRef, useLightbox } from "@/cut/lib/lightbox";@@ -215,7 +216,7 @@ const scrimButton = scrimIconButton;/** Image / video tile: the preview fills the card at the media's own aspect,* sized so portrait and landscape both sit comfortably in the chat column. */function MediaCard({ item, asset }: ChatCardProps) {- const videoRef = useRef<HTMLVideoElement>(null);+ const { ref: videoRef, handlers: hoverPlay } = useHoverPlay();// Chat scrollback holds every card ever made; media loads only once the// card actually scrolls into view.const [tileRef, seen] = useInView<HTMLDivElement>();@@ -231,25 +232,7 @@ function MediaCard({ item, asset }: ChatCardProps) {title={`${ref.name} — double-click to expand · drag to the timeline`}{...dragProps(item, asset)}onDoubleClick={() => expandRef(item, asset)}- onMouseEnter={() => {- const v = videoRef.current;- if (!v) return;- v.muted = false;- void v.play().catch(() => {- // Before any page interaction the browser refuses sound — keep the- // silent preview rather than none.- v.muted = true;- void v.play().catch(() => {});- });- }}- onMouseLeave={() => {- const v = videoRef.current;- if (v) {- v.pause();- v.muted = true;- v.currentTime = 0.1;- }- }}+ {...(item.kind === "video" ? hoverPlay : {})}>{item.kind === "video" ? (// Native first frame as the poster — full-resolution, no blurry thumb.diff --git a/site/src/cut/components/SceneCard.tsx b/site/src/cut/components/SceneCard.tsxindex 8daf4902..e6b50048 100644--- a/site/src/cut/components/SceneCard.tsx+++ b/site/src/cut/components/SceneCard.tsx@@ -12,6 +12,7 @@ import {X,} from "lucide-react";import { Button } from "@/components/ui/button";+import { useHoverPlay } from "../hooks/useHoverPlay";import { refFromAsset, type AssetRef } from "../lib/assetRef";import { lightboxItemFromRef, useLightbox } from "../lib/lightbox";import { formatDuration, useGenScene, type SceneRun } from "../lib/genScene";@@ -291,6 +292,7 @@ function ShotTile({const ratio = media?.width && media?.height ? media.width / media.height : baseRatio;const inFlight = SHOT_INFLIGHT.has(shot.status);const view = () => ref && useLightbox.getState().open(lightboxItemFromRef(ref));+ const { ref: videoRef, handlers: hoverPlay } = useHoverPlay();return (<div className="flex min-w-0 flex-col gap-1"><div@@ -303,12 +305,15 @@ function ShotTile({// The tile fills its column at the run's aspect; a tall 9:16 shot is// capped so two columns of a long plan stay a scannable height.style={{ aspectRatio: ratio, maxHeight: baseRatio < 1 ? 200 : undefined }}+ {...(clip && ref ? hoverPlay : {})}>{clip && ref ? (<video+ ref={videoRef}src={`${ref.url}#t=0.1`}preload="metadata"muted+ loopplaysInlineclassName="size-full object-cover"/>@@ -432,6 +437,7 @@ function FeedEntry({pulse: boolean;}) {const [expanded, setExpanded] = useState(false);+ const { ref: videoRef, handlers: hoverPlay } = useHoverPlay();const inPlace = item?.kind === "image" || item?.kind === "video";const caption = (<span@@ -456,12 +462,15 @@ function FeedEntry({style={{ width, aspectRatio: ratio }}title={`${item.name} — click to minimize`}onClick={() => setExpanded(false)}+ {...(item.kind === "video" ? hoverPlay : {})}>{item.kind === "video" ? (<video+ ref={videoRef}src={`${item.url}#t=0.1`}preload="metadata"muted+ loopplaysInlineclassName="size-full object-cover"/>diff --git a/site/src/cut/hooks/useHoverPlay.ts b/site/src/cut/hooks/useHoverPlay.tsnew file mode 100644index 00000000..f5582105--- /dev/null+++ b/site/src/cut/hooks/useHoverPlay.ts@@ -0,0 +1,33 @@+"use client";++import { useRef } from "react";++/**+ * Hover-to-play for a muted <video> poster: entering plays with sound, leaving+ * pauses, re-mutes, and returns to the first frame. Sound needs a prior page+ * interaction; if the browser refuses it, playback falls back to silent rather+ * than not starting at all. Attach `ref` to the <video> and spread `handlers`+ * on the hover target (the tile, not the video, so scrims stay hoverable).+ */+export function useHoverPlay() {+ const ref = useRef<HTMLVideoElement>(null);+ const handlers = {+ onMouseEnter: () => {+ const v = ref.current;+ if (!v) return;+ v.muted = false;+ void v.play().catch(() => {+ v.muted = true;+ void v.play().catch(() => {});+ });+ },+ onMouseLeave: () => {+ const v = ref.current;+ if (!v) return;+ v.pause();+ v.muted = true;+ v.currentTime = 0.1;+ },+ };+ return { ref, handlers };+}