Open source CapCut alternative.
TypeScript
feat(site): a library card plays its asset on a double-click
David Le02f9747d6933
diff --git a/site/src/cut/components/CameraRollView.tsx b/site/src/cut/components/CameraRollView.tsxindex 2a7442c2..3794dd6f 100644--- a/site/src/cut/components/CameraRollView.tsx+++ b/site/src/cut/components/CameraRollView.tsx@@ -13,13 +13,8 @@ import {AlertDialogHeader,AlertDialogTitle,} from "@/components/ui/alert-dialog";-import {- deleteFromLibrary,- libraryMediaUrl,- libraryPosterUrl,- type LibraryAsset,-} from "@/cut/lib/library";-import { useLightbox } from "@/cut/lib/lightbox";+import { deleteFromLibrary, type LibraryAsset } from "@/cut/lib/library";+import { lightboxItemFromLibrary, useLightbox } from "@/cut/lib/lightbox";import { patchLibrary, refetchLibrary, useLibrary } from "@/cut/lib/queries";import { shapeBand } from "@/cut/lib/types";import { Lightbox } from "./Lightbox";@@ -88,17 +83,7 @@ export function CameraRollView() {asset={a}area={TILE_AREA}onClick={() =>- useLightbox.getState().open({- kind: a.type,- src: libraryMediaUrl(a.fileName, a.residency),- name: a.name,- prompt: "",- assetId: null,- libraryId: a.id,- bare: true,- ...(a.width && a.height ? { ratio: a.width / a.height } : {}),- ...(libraryPosterUrl(a) ? { poster: libraryPosterUrl(a) } : {}),- })+ useLightbox.getState().open(lightboxItemFromLibrary(a, true))}onDelete={() => setDeleting(a)}/>diff --git a/site/src/cut/components/LibraryView.tsx b/site/src/cut/components/LibraryView.tsxindex a74989f8..da9edab7 100644--- a/site/src/cut/components/LibraryView.tsx+++ b/site/src/cut/components/LibraryView.tsx@@ -87,7 +87,7 @@ import {type LibraryData,} from "@/cut/lib/library";import { normalizeLink } from "@/cut/lib/link";-import { useLightbox } from "@/cut/lib/lightbox";+import { lightboxItemFromLibrary, useLightbox } from "@/cut/lib/lightbox";import { reportActivity } from "@/cut/lib/tabActivity";import { useNewProjectTarget } from "@/cut/lib/newProject";import { useListedResidencies, useLocalCompute } from "@/cut/lib/backend/hooks";@@ -917,21 +917,9 @@ export function LibraryView() {onClick={live(a.residency)? () =>- useLightbox.getState().open({- kind: a.type,- src: libraryMediaUrl(a.fileName, a.residency),- name: a.name,- prompt: "",- assetId: null,- libraryId: a.id,- bare: true,- ...(a.width && a.height- ? { ratio: a.width / a.height }- : {}),- ...(libraryPosterUrl(a)- ? { poster: libraryPosterUrl(a) }- : {}),- })+ useLightbox+ .getState()+ .open(lightboxItemFromLibrary(a, true)): () => setNeedsApp(true)}onDelete={@@ -1111,6 +1099,18 @@ export function LibraryCard({className="group flex flex-col"draggable={!offline}onClick={onClick}+ // Double-click plays the asset in the viewer, wherever the card sits:+ // the editor's panel keeps its single click for selection and drag.+ onDoubleClick={+ offline+ ? undefined+ : () =>+ useLightbox+ .getState()+ // Without a + button there is no project to add it to, so the+ // viewer opens bare.+ .open(lightboxItemFromLibrary(a, !onUse))+ }onDragStart={(e) => {setLibraryDragData(e, a);onDragStartExtra?.(e);diff --git a/site/src/cut/lib/lightbox.ts b/site/src/cut/lib/lightbox.tsindex 15fa4bd1..1a37dcd7 100644--- a/site/src/cut/lib/lightbox.ts+++ b/site/src/cut/lib/lightbox.ts@@ -2,6 +2,7 @@import { create } from "zustand";import type { AssetRef } from "./assetRef";+import { libraryMediaUrl, libraryPosterUrl, type LibraryAsset } from "./library";// The asset lightbox: a full-screen viewer opened from stock tiles, generated// media, chat asset cards, and library cards. Held in its own store so any@@ -45,6 +46,23 @@ export const lightboxItemFromRef = (ref: AssetRef): LightboxItem => ({...(ref.scope === "library" ? { libraryId: ref.id } : {}),});+/** The lightbox view of a library asset — what a library card opens on a+ * double-click. `bare` where the surface has no project to add anything to. */+export const lightboxItemFromLibrary = (+ a: LibraryAsset,+ bare = false,+): LightboxItem => ({+ kind: a.type,+ src: libraryMediaUrl(a.fileName, a.residency),+ name: a.name,+ prompt: "",+ assetId: null,+ libraryId: a.id,+ ...(bare ? { bare: true } : {}),+ ...(a.width && a.height ? { ratio: a.width / a.height } : {}),+ ...(libraryPosterUrl(a) ? { poster: libraryPosterUrl(a) } : {}),+});+interface LightboxState {item: LightboxItem | null;open: (item: LightboxItem) => void;