Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Elements: clip-only elements give a still where a picture is needed; Marketing hydrates cleanly

Adarsh3a6ce44663da
diff --git a/src/components/cinema/blockout-panel.tsx b/src/components/cinema/blockout-panel.tsx
index d1c93d43..dfaf38e7 100644
--- a/src/components/cinema/blockout-panel.tsx
+++ b/src/components/cinema/blockout-panel.tsx
@@ -23,7 +23,10 @@ import { cn } from "@/lib/utils";
import type { BuiltBlockout } from "./blockout-builder";
import { useCinemaGenerate } from "./hooks";
import { mediaDuration } from "./media";
-import { firstPhoto } from "@/lib/clip-thumb";
+import { pictureSource, stillLine } from "@/lib/clip-thumb";
+import { ElementThumb } from "@/components/element-thumb";
+import { useElementPictures } from "@/components/element-picture";
+import { UNAVAILABLE_OPTION, UnavailableNote, useUnavailableNote } from "@/components/ui/unavailable";
/**
* Blockout to film in Cinema's take composer (package blockout-film): the blockout (an uploaded grey-box render from any
@@ -243,6 +246,20 @@ export function BlockoutPanel(props: BlockoutPanelProps) {
}
};
+ // Elements with a photo or a clip: one with only a clip gives a still of it (made when picked).
+ const pictureElements = (elements.data ?? []).filter((e) => e.kind !== "voice" && pictureSource(e.references)).slice(0, 30);
+ const pics = useElementPictures(pictureElements);
+ const elementNote = useUnavailableNote(pictureElements.map((e) => ({ value: e.id, unavailable: pics.unavailable(e) })));
+ // References that are a still from an element's clip, by address: said under the reference.
+ const [stillsOf, setStillsOf] = useState<Record<string, string>>({});
+ const addElement = async (e: (typeof pictureElements)[number]) => {
+ const p = await pics.pick(e);
+ if (p === "unreadable") return elementNote.press({ value: e.id, unavailable: pics.reasonFor(e) }, () => {});
+ if (!p) return;
+ if (p.still) setStillsOf((m) => ({ ...m, [p.url]: e.name }));
+ addRef({ url: p.url, role: roleFor({ category: e.kind }), name: e.name });
+ };
+
const addRef = (r: Omit<BlockoutRefItem, "id">) => {
if (draft.refs.length >= BLOCKOUT.maxRefs) return toast.error(`Up to ${BLOCKOUT.maxRefs} references`);
setDraft((d) => ({ ...d, refs: [...d.refs, { ...r, id: nanoid(6) }], prompt: null }));
@@ -454,6 +471,7 @@ export function BlockoutPanel(props: BlockoutPanelProps) {
</option>
))}
</select>
+ {stillsOf[r.url] && <p className="text-[11px] leading-snug text-muted-foreground">{stillLine(stillsOf[r.url])}</p>}
<Input value={r.name ?? ""} placeholder="Name (optional)" onChange={(e) => setDraft((d) => ({ ...d, refs: d.refs.map((x) => (x.id === r.id ? { ...x, name: e.target.value.slice(0, 60) } : x)), prompt: null }))} className="h-7 px-1.5 text-[12.5px]" aria-label={`Reference ${i + 1} name`} />
</div>
))}
@@ -467,20 +485,38 @@ export function BlockoutPanel(props: BlockoutPanelProps) {
<button type="button" onClick={() => refInput.current?.click()} className="flex w-full items-center gap-2 rounded-lg px-2 py-2 text-left text-[13px] font-medium hover:bg-accent">
<Upload className="size-4" /> Upload a picture
</button>
- {!!elements.data?.some((e) => firstPhoto(e.references) && e.kind !== "voice") && <p className="px-2 pt-2 pb-1 text-[11px] font-medium tracking-wide text-muted-foreground uppercase">Elements · Soul Cast · Soul Location</p>}
+ {pictureElements.length > 0 && <p className="px-2 pt-2 pb-1 text-[11px] font-medium tracking-wide text-muted-foreground uppercase">Elements · Soul Cast · Soul Location</p>}
<div className="max-h-40 space-y-0.5 overflow-y-auto">
- {(elements.data ?? [])
- .filter((e) => firstPhoto(e.references) && e.kind !== "voice")
- .slice(0, 30)
- .map((e) => (
- <button key={e.id} type="button" onClick={() => addRef({ url: firstPhoto(e.references)!, role: roleFor({ category: e.kind }), name: e.name })} className="flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-[13px] hover:bg-accent">
- {/* eslint-disable-next-line @next/next/no-img-element */}
- <img src={firstPhoto(e.references)} alt="" className="size-7 rounded object-cover" />
+ {pictureElements.map((e) => {
+ const src = pictureSource(e.references)!;
+ const opt = { value: e.id, unavailable: pics.unavailable(e) };
+ const off = elementNote.isUnavailable(opt);
+ return (
+ <button
+ key={e.id}
+ type="button"
+ onClick={() => elementNote.press(opt, () => void addElement(e))}
+ {...elementNote.optionProps(opt)}
+ aria-busy={pics.busy === e.id || undefined}
+ className={cn("flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-[13px]", !off && "hover:bg-accent", off && UNAVAILABLE_OPTION)}
+ >
+ {"photo" in src ? (
+ // eslint-disable-next-line @next/next/no-img-element
+ <img src={src.photo} alt="" className="size-7 rounded object-cover" />
+ ) : (
+ <ElementThumb src={src.clip} mark="none" className="size-7 shrink-0 rounded object-cover" />
+ )}
<span className="min-w-0 flex-1 truncate">{e.name}</span>
- <span className="text-[11.5px] text-muted-foreground capitalize">{e.kind}</span>
+ {pics.busy === e.id ? (
+ <Loader2 className="size-3.5 animate-spin text-muted-foreground" aria-label={`Making a still from ${e.name}'s clip`} />
+ ) : (
+ <span className="text-[11.5px] text-muted-foreground capitalize">{"clip" in src ? `${e.kind} · clip` : e.kind}</span>
+ )}
</button>
- ))}
+ );
+ })}
</div>
+ <UnavailableNote {...elementNote.noteProps} />
<p className="px-2 pt-2 pb-1 text-[11px] font-medium tracking-wide text-muted-foreground uppercase">From your library</p>
<div className="grid max-h-44 grid-cols-4 gap-1 overflow-y-auto">
{(images.data ?? []).slice(0, 40).map((a) => (
@@ -493,6 +529,7 @@ export function BlockoutPanel(props: BlockoutPanelProps) {
</div>
</PopoverContent>
</Popover>
+ {pics.dialog}
<input ref={refInput} type="file" accept="image/png,image/jpeg,image/webp" hidden onChange={(e) => (e.target.files?.[0] && uploadRef(e.target.files[0]), (e.target.value = ""))} />
</div>
<p className="text-[12px] text-muted-foreground">Each still’s role is written into the prompt for you: the interior, who the mannequin becomes, the exterior, a prop.</p>
diff --git a/src/components/element-picture.tsx b/src/components/element-picture.tsx
new file mode 100644
index 00000000..13489319
--- /dev/null
+++ b/src/components/element-picture.tsx
@@ -0,0 +1,88 @@
+"use client";
+
+import dynamic from "next/dynamic";
+import { useState } from "react";
+import { uploadFile } from "@/lib/api";
+import type { StudioElement } from "@/lib/catalog/elements";
+import { addPhotoLabel, noStillWhy, pictureSource } from "@/lib/clip-thumb";
+import { toastError } from "@/lib/refusals";
+import type { Unavailable } from "@/lib/unavailable";
+import { grabClipFrame, useClipStills } from "./element-thumb";
+
+// The element dialog opens only when a photo is added from a picker, so it loads then.
+const ElementDialog = dynamic(() => import("@/components/elements-view").then((m) => m.ElementDialog), { ssr: false });
+
+/** A still's longest side when it is used as a picture (an avatar, an image reference). */
+const PICTURE_SIDE = 2048;
+
+/**
+ * A clip's still as a stored picture, made and uploaded once per clip: its address, or null when this browser can't read
+ * the clip. An upload that fails throws (and is tried again next time).
+ */
+const uploaded = new Map<string, Promise<string | null>>();
+function clipPicture(clip: string): Promise<string | null> {
+ let p = uploaded.get(clip);
+ if (!p) {
+ p = (async () => {
+ const blob = await grabClipFrame(clip, PICTURE_SIDE, 0.92);
+ if (!blob) return null;
+ return (await uploadFile(new File([blob], "still.jpg", { type: "image/jpeg" }))).url;
+ })();
+ uploaded.set(clip, p);
+ p.catch(() => uploaded.delete(clip));
+ }
+ return p;
+}
+
+/**
+ * Pictures from elements, for pickers that need a picture (Blockout's references, the marketing avatar). An element with a
+ * photo gives it; one with only a clip gives a still of its clip, made in the browser and uploaded when it is picked. A
+ * clip this browser can't read leaves its element listed but unavailable, with the way to fix it: "Add a photo to Maya"
+ * opens the element's dialog here.
+ */
+export function useElementPictures(elements: readonly StudioElement[]) {
+ const clipOnly = elements.flatMap((e) => {
+ const src = pictureSource(e.references);
+ return src && "clip" in src ? [{ id: e.id, clip: src.clip }] : [];
+ });
+ const states = useClipStills(clipOnly.map((c) => c.clip));
+ const [failed, setFailed] = useState<ReadonlySet<string>>(new Set());
+ const [busy, setBusy] = useState<string | null>(null);
+ const [editing, setEditing] = useState<StudioElement | null>(null);
+
+ const unreadable = (e: StudioElement) => {
+ const i = clipOnly.findIndex((c) => c.id === e.id);
+ return i >= 0 && (failed.has(e.id) || states[i] === null);
+ };
+ /** Why an element has no picture to give, with the fix: "Add a photo to Maya" opens its dialog. */
+ const reasonFor = (e: StudioElement): Unavailable => ({ why: noStillWhy(e.name), fix: { label: addPhotoLabel(e.name), run: () => setEditing(e) } });
+ /** Why an element can't give a picture now (undefined: it can). */
+ const unavailable = (e: StudioElement): Unavailable | undefined => (unreadable(e) ? reasonFor(e) : undefined);
+
+ /**
+ * The element's picture: its photo at once, else its clip's still once it is made and stored. "unreadable": its clip
+ * can't be read here (the caller says why with reasonFor); null: nothing to use, or the upload failed (said in a toast).
+ */
+ const pick = async (e: StudioElement): Promise<{ url: string; still: boolean } | "unreadable" | null> => {
+ const src = pictureSource(e.references);
+ if (!src) return null;
+ if ("photo" in src) return { url: src.photo, still: false };
+ setBusy(e.id);
+ try {
+ const url = await clipPicture(src.clip);
+ if (!url) {
+ setFailed((s) => new Set(s).add(e.id));
+ return "unreadable";
+ }
+ return { url, still: true };
+ } catch (err) {
+ toastError(err, `We couldn't save a still from ${e.name}'s clip. Try again`);
+ return null;
+ } finally {
+ setBusy(null);
+ }
+ };
+
+ const dialog = editing ? <ElementDialog open onOpenChange={(o) => !o && setEditing(null)} element={editing} /> : null;
+ return { pick, busy, unavailable, reasonFor, dialog };
+}
diff --git a/src/components/element-thumb.tsx b/src/components/element-thumb.tsx
index a622b44f..85e29675 100644
--- a/src/components/element-thumb.tsx
+++ b/src/components/element-thumb.tsx
@@ -2,12 +2,15 @@
import { Video } from "lucide-react";
import { useEffect, useState, type ReactNode } from "react";
-import { CLIP_FRAME_AT, frameSize, stillCache, thumbSource } from "@/lib/clip-thumb";
+import { CLIP_FRAME_AT, CLIP_FRAME_SIDE, frameSize, stillCache, thumbSource } from "@/lib/clip-thumb";
import { isClipRef } from "@/lib/catalog/elements";
import { cn } from "@/lib/utils";
-/** One frame of a clip, scaled down and kept as a JPEG object URL; null when this browser can't read the clip. */
-async function grabStill(clip: string): Promise<string | null> {
+/**
+ * One frame of a clip (at CLIP_FRAME_AT) as a JPEG, its longest side at most `maxSide`; null when this browser can't read
+ * the clip.
+ */
+export async function grabClipFrame(clip: string, maxSide = CLIP_FRAME_SIDE, quality = 0.85): Promise<Blob | null> {
if (typeof document === "undefined") return null;
const v = document.createElement("video");
v.muted = true;
@@ -29,7 +32,7 @@ async function grabStill(clip: string): Promise<string | null> {
v.currentTime = at;
await seeked;
}
- const size = frameSize(v.videoWidth, v.videoHeight);
+ const size = frameSize(v.videoWidth, v.videoHeight, maxSide);
if (!size.width) return null;
const c = document.createElement("canvas");
c.width = size.width;
@@ -37,8 +40,7 @@ async function grabStill(clip: string): Promise<string | null> {
const ctx = c.getContext("2d");
if (!ctx) return null;
ctx.drawImage(v, 0, 0, size.width, size.height);
- const blob = await new Promise<Blob | null>((r) => c.toBlob(r, "image/jpeg", 0.85));
- return blob ? URL.createObjectURL(blob) : null;
+ return await new Promise<Blob | null>((r) => c.toBlob(r, "image/jpeg", quality));
} catch {
return null;
} finally {
@@ -47,8 +49,33 @@ async function grabStill(clip: string): Promise<string | null> {
}
}
+/** A thumbnail still of a clip, kept as an object URL. */
+async function grabStill(clip: string): Promise<string | null> {
+ const blob = await grabClipFrame(clip);
+ return blob ? URL.createObjectURL(blob) : null;
+}
+
const stills = stillCache(grabStill);
+/**
+ * The thumbnail stills of several clips, grabbed (once each) while the caller shows them: a string when ready, null for
+ * a clip this browser can't read, undefined while it isn't known yet.
+ */
+export function useClipStills(clips: readonly string[]): (string | null | undefined)[] {
+ const [, setTick] = useState(0);
+ const key = clips.join("\n");
+ useEffect(() => {
+ let gone = false;
+ for (const c of key ? key.split("\n") : []) {
+ if (stills.peek(c) === undefined) void stills.get(c).then(() => !gone && setTick((t) => t + 1));
+ }
+ return () => {
+ gone = true;
+ };
+ }, [key]);
+ return clips.map((c) => stills.peek(c));
+}
+
/** The mark that says a thumbnail is a clip: a small camera on a dark disc. */
export function ClipMark({ className, size = "sm" }: { className?: string; size?: "xs" | "sm" }) {
return (
diff --git a/src/components/marketing/pickers.tsx b/src/components/marketing/pickers.tsx
index 2d17d56b..aef067ee 100644
--- a/src/components/marketing/pickers.tsx
+++ b/src/components/marketing/pickers.tsx
@@ -17,7 +17,10 @@ import type { ModelDef } from "@/lib/catalog/types";
import { cn } from "@/lib/utils";
import type { ModelInfo } from "./model-info";
import { useProducts } from "./hooks";
-import { firstPhoto } from "@/lib/clip-thumb";
+import { pictureSource, stillLine } from "@/lib/clip-thumb";
+import { ClipMark, ElementThumb } from "@/components/element-thumb";
+import { useElementPictures } from "@/components/element-picture";
+import { UNAVAILABLE_OPTION, UnavailableNote, useUnavailableNote } from "@/components/ui/unavailable";
/** The product a run uses: a saved product, or a one-off photo. */
export interface ProductChoice {
@@ -123,16 +126,26 @@ export function ProductSlot({ value, onChange, required, brandId, pulse }: { val
export function AvatarSlot({ value, onChange, pulse }: { value: SlotValue | null; onChange: (v: SlotValue | null) => void; pulse?: boolean }) {
const [open, setOpen] = useState(false);
const elements = useElements();
- const people = (elements.data ?? []).flatMap((e) => {
- const photo = e.kind === "character" ? firstPhoto(e.references) : undefined;
- return photo ? [{ ...e, photo }] : [];
- });
+ // Every character with a photo or a clip: one with only a clip gives a still of it (made when picked).
+ const people = (elements.data ?? []).filter((e) => e.kind === "character" && pictureSource(e.references));
+ const pics = useElementPictures(people);
+ const note = useUnavailableNote(people.map((e) => ({ value: e.id, unavailable: pics.unavailable(e) })));
+ // The character whose clip's still is the avatar (said under the characters and on the slot).
+ const [still, setStill] = useState<{ ref: string; id: string; name: string } | null>(null);
+ const usingStill = still && value?.ref === still.ref ? still : null;
const [busy, setBusy] = useState(false);
const input = useRef<HTMLInputElement>(null);
const choose = (v: SlotValue) => {
onChange(v);
setOpen(false);
};
+ const pickPerson = async (e: (typeof people)[number]) => {
+ const p = await pics.pick(e);
+ if (p === "unreadable") return note.press({ value: e.id, unavailable: pics.reasonFor(e) }, () => {});
+ if (!p) return;
+ setStill(p.still ? { ref: p.url, id: e.id, name: e.name } : null);
+ choose({ ref: p.url, preview: p.url, kind: "image", name: e.name });
+ };
return (
<div className="relative shrink-0">
<ResponsivePanel
@@ -140,12 +153,15 @@ export function AvatarSlot({ value, onChange, pulse }: { value: SlotValue | null
onOpenChange={setOpen}
title="Choose avatar"
description="Who presents or wears the product. Leave it empty and a model is made for you."
- tooltip={value ? (value.name ?? "Avatar") : "Avatar · Optional"}
+ tooltip={value ? (usingStill ? stillLine(usingStill.name) : (value.name ?? "Avatar")) : "Avatar · Optional"}
trigger={
- <button type="button" data-slot-key="avatar" className={cn(tile, value ? "bg-muted" : "border border-dashed border-border-strong text-muted-foreground hover:border-primary hover:text-brand-text", pulse && "animate-pulse ring-2 ring-primary")} aria-label={value ? `Avatar: ${value.name ?? "photo"}. Replace avatar` : "Add avatar"}>
+ <button type="button" data-slot-key="avatar" className={cn(tile, value ? "bg-muted" : "border border-dashed border-border-strong text-muted-foreground hover:border-primary hover:text-brand-text", pulse && "animate-pulse ring-2 ring-primary")} aria-label={value ? `Avatar: ${usingStill ? stillLine(usingStill.name) : (value.name ?? "photo")}. Replace avatar` : "Add avatar"}>
{value ? (
- // eslint-disable-next-line @next/next/no-img-element
- <img src={value.preview} alt="" className="size-full object-cover" />
+ <>
+ {/* eslint-disable-next-line @next/next/no-img-element */}
+ <img src={value.preview} alt="" className="size-full object-cover" />
+ {usingStill && <ClipMark size="xs" className="absolute right-1 bottom-1" />}
+ </>
) : (
<span className="flex flex-col items-center gap-0.5 text-[10px] font-medium">
<UserRound className="size-4" />
@@ -177,15 +193,44 @@ export function AvatarSlot({ value, onChange, pulse }: { value: SlotValue | null
<div className="space-y-1.5">
<p className="text-[12px] font-medium text-muted-foreground">Your characters</p>
{people.length ? (
- <div className="grid grid-cols-4 gap-2">
- {people.map((e) => (
- <button key={e.id} type="button" onClick={() => choose({ ref: e.photo, preview: e.photo, kind: "image", name: e.name })} className={cn("min-w-0 rounded-lg p-1 hover:bg-accent", value?.ref === e.photo && "bg-brand-faint")}>
- {/* eslint-disable-next-line @next/next/no-img-element */}
- <img src={e.photo} alt="" className="aspect-square w-full rounded-md object-cover" />
- <span className="mt-1 block truncate text-[11px]">{e.name}</span>
- </button>
- ))}
- </div>
+ <>
+ <div className="grid grid-cols-4 gap-2">
+ {people.map((e) => {
+ const src = pictureSource(e.references)!;
+ const photo = "photo" in src ? src.photo : undefined;
+ const opt = { value: e.id, unavailable: pics.unavailable(e) };
+ const off = note.isUnavailable(opt);
+ const on = !off && (photo ? value?.ref === photo : usingStill?.id === e.id);
+ return (
+ <button
+ key={e.id}
+ type="button"
+ onClick={() => note.press(opt, () => void pickPerson(e))}
+ {...note.optionProps(opt)}
+ aria-busy={pics.busy === e.id || undefined}
+ className={cn("min-w-0 rounded-lg p-1", !off && "hover:bg-accent", on && "bg-brand-faint", off && UNAVAILABLE_OPTION)}
+ >
+ {photo ? (
+ // eslint-disable-next-line @next/next/no-img-element
+ <img src={photo} alt="" className="aspect-square w-full rounded-md object-cover" />
+ ) : (
+ <span className="relative block">
+ <ElementThumb src={"clip" in src ? src.clip : ""} mark="small" className="aspect-square w-full rounded-md object-cover" />
+ {pics.busy === e.id && (
+ <span className="absolute inset-0 grid place-items-center rounded-md bg-background/60">
+ <Loader2 className="size-4 animate-spin" />
+ </span>
+ )}
+ </span>
+ )}
+ <span className="mt-1 block truncate text-[11px]">{e.name}</span>
+ </button>
+ );
+ })}
+ </div>
+ <UnavailableNote {...note.noteProps} />
+ {usingStill && <p className="text-[12px] text-muted-foreground">{stillLine(usingStill.name)}</p>}
+ </>
) : (
<p className="text-[12px] text-muted-foreground">Save people you reuse as characters in Elements.</p>
)}
@@ -196,6 +241,7 @@ export function AvatarSlot({ value, onChange, pulse }: { value: SlotValue | null
</div>
</div>
</ResponsivePanel>
+ {pics.dialog}
{value && (
<button type="button" onClick={() => onChange(null)} aria-label="Remove avatar" className="absolute -top-1.5 -right-1.5 grid size-5 place-items-center rounded-full border bg-background text-muted-foreground shadow-soft hover:text-foreground">
<X className="size-3" />
diff --git a/src/lib/api.ts b/src/lib/api.ts
index 9536a32c..7a6d1db4 100644
--- a/src/lib/api.ts
+++ b/src/lib/api.ts
@@ -1070,10 +1070,17 @@ export function useStatus() {
/**
* The name this viewer reads for this install's GPUs (src/lib/place-name.ts): `label` as set ("Our GPUs"), `text` inside
* a sentence ("our GPUs"). Null while hosted runs are off for this viewer (the owner; any viewer of an install with them
- * off): its pages keep their own words.
+ * off): its pages keep their own words. Null until the page has hydrated too, as the server rendered it: a status that
+ * answers before part of the page hydrates would otherwise change its words mid-hydration.
*/
export function usePlaceName(): Place | null {
const v = useStatus().data?.viewer;
+ const hydrated = useHydrated();
+ return hydrated ? placeNameFor(v) : null;
+}
+
+/** The place name a viewer reads (usePlaceName once hydrated): none unless hosted runs are on for them. */
+export function placeNameFor(v: { hosted?: boolean; placeName?: string } | undefined): Place | null {
return v?.hosted ? placeOf(v.placeName) : null;
}
diff --git a/src/lib/clip-thumb.ts b/src/lib/clip-thumb.ts
index f70e6ce9..91a0c94b 100644
--- a/src/lib/clip-thumb.ts
+++ b/src/lib/clip-thumb.ts
@@ -79,3 +79,21 @@ export function referenceWords(references: readonly string[]): string {
const words = [photos && `${photos} photo${photos > 1 ? "s" : ""}`, clips && `${clips} clip${clips > 1 ? "s" : ""}`].filter(Boolean);
return words.join(" · ");
}
+
+/**
+ * Where an element's picture comes from where a picture is needed (an avatar, an image reference): its first photo, else
+ * a still from its clip (made in the browser and uploaded), else nothing.
+ */
+export function pictureSource(references: readonly string[]): { photo: string } | { clip: string } | null {
+ const photo = firstPhoto(references);
+ if (photo) return { photo };
+ const clip = references.find(isClipRef);
+ return clip ? { clip } : null;
+}
+
+/** The line under a picture made from an element's clip. */
+export const stillLine = (name: string) => `Using a still from ${name}'s clip`;
+
+/** Why a clip-only element has no picture to give, and the way to give it one. */
+export const noStillWhy = (name: string) => `${name}'s clip can't be read here, so there is no still to use`;
+export const addPhotoLabel = (name: string) => `Add a photo to ${name}`;
diff --git a/tests/clip-thumb.test.ts b/tests/clip-thumb.test.ts
index 577e61cd..1ec7354e 100644
--- a/tests/clip-thumb.test.ts
+++ b/tests/clip-thumb.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
-import { firstPhoto, frameSize, referenceWords, stillCache, thumbSource } from "@/lib/clip-thumb";
+import { addPhotoLabel, firstPhoto, frameSize, noStillWhy, pictureSource, referenceWords, stillCache, stillLine, thumbSource } from "@/lib/clip-thumb";
describe("thumbSource", () => {
it("draws a photo as itself", () => {
@@ -76,3 +76,18 @@ describe("referenceWords", () => {
expect(referenceWords([])).toBe("");
});
});
+
+describe("pictureSource", () => {
+ it("gives a photo first, else the clip to take a still from, else nothing", () => {
+ expect(pictureSource(["/a.mp4", "/b.jpg"])).toEqual({ photo: "/b.jpg" });
+ expect(pictureSource(["/b.jpg"])).toEqual({ photo: "/b.jpg" });
+ expect(pictureSource(["/a.mp4", "/c.webm"])).toEqual({ clip: "/a.mp4" });
+ expect(pictureSource([])).toBeNull();
+ });
+
+ it("says where the picture came from, and how to give one when the clip can't be read", () => {
+ expect(stillLine("Maya")).toBe("Using a still from Maya's clip");
+ expect(noStillWhy("Maya")).toBe("Maya's clip can't be read here, so there is no still to use");
+ expect(addPhotoLabel("Maya")).toBe("Add a photo to Maya");
+ });
+});
diff --git a/tests/place-name.test.ts b/tests/place-name.test.ts
index bc2e6d3f..5fed5ee0 100644
--- a/tests/place-name.test.ts
+++ b/tests/place-name.test.ts
@@ -23,7 +23,7 @@ const billing = await import("@/server/billing");
const auth = await import("@/server/auth");
const { visitorStatus } = await import("@/server/account-gpu");
const { ownGpuQuiet } = await import("@/server/hosted-run");
-const { usePlaceName } = await import("@/lib/api");
+const { placeNameFor, usePlaceName } = await import("@/lib/api");
let fake: FakeBilling;
let accountId = "";
@@ -139,9 +139,14 @@ describe("the page's place name", () => {
return seen;
};
it("none for the owner and while hosted runs are off; the name (or Our GPUs) while they are on", () => {
+ expect(placeNameFor(undefined)).toBeNull();
+ expect(placeNameFor({ placeName: "Ignored" })).toBeNull();
+ expect(placeNameFor({ hosted: true })).toEqual({ label: "Our GPUs", text: "our GPUs" });
+ expect(placeNameFor({ hosted: true, placeName: "Ana's render box" })).toEqual({ label: "Ana's render box", text: "Ana's render box" });
+ });
+
+ it("none while the page renders on the server and hydrates, as the server rendered it, even with the status known", () => {
expect(read(undefined)).toBeNull();
- expect(read({ kind: "account", gpu: { connected: false }, placeName: "Ignored" })).toBeNull();
- expect(read({ kind: "account", gpu: { connected: false }, hosted: true })).toEqual({ label: "Our GPUs", text: "our GPUs" });
- expect(read({ kind: "guest", gpu: { connected: false }, hosted: true, placeName: "Ana's render box" })).toEqual({ label: "Ana's render box", text: "Ana's render box" });
+ expect(read({ kind: "guest", gpu: { connected: false }, hosted: true, placeName: "Ana's render box" })).toBeNull();
});
});