caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

134 lines
5.9 KiB
TypeScript

"use client";
import { useEffect, useRef, useState } from "react";
import Link from "next/link";
import { ArrowRight, Loader2, Play } from "lucide-react";
import { Button } from "@/components/ui/button";
import { ErrorNote, ToolPanel } from "@/components/marketing/free-tools/shared";
import { VARIANT_COUNT, parseSource } from "@/src/features/create-compose/one-flow/plan";
import { previewReel, type ReelPreviewResult } from "@/src/features/reel-preview/api";
import { track } from "@/lib/track";
import { useTurnstileToken } from "./Turnstile";
const SITE_KEY = process.env.NEXT_PUBLIC_TURNSTILE_SITE_KEY || "";
export interface ReelPreviewRunnerProps {
/** The hero's own paste box is the source of the URL; this never shows its own input. */
readonly url: string;
/**
* Bumped by the hero form's own submit when the input holds a link, so the
* hero's primary button runs the free preview instead of jumping to
* sign-up. Runs as soon as the Turnstile token is ready.
*/
readonly runRequest?: number;
/** Hide this panel's own run button when the hero's primary button drives it. */
readonly hideRunButton?: boolean;
}
function signUpUrl(result: ReelPreviewResult): string {
const params = new URLSearchParams({ q: result.url, preset: result.preset_id, preview: result.preview_id });
return `/sign-up?${params.toString()}`;
}
/**
* Menivor Growth: the landing hero's "try before you sign up" step. Runs the
* free, public reel preview (`POST /public/reel-preview`, no sign-in) for
* whatever link the visitor pasted above and shows a real opening hook plus
* a real frame from the page/listing -- then "Sign up to get your 3 reels",
* which carries the exact previewed link + preset through sign-up so the
* paid run never re-asks anything. One component call, driven entirely by
* the hero's own input (mirrors `AppAuditRunner`'s `showInput={false}` mode).
*/
export function ReelPreviewRunner({ url, runRequest = 0, hideRunButton = false }: ReelPreviewRunnerProps) {
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
const [result, setResult] = useState<ReelPreviewResult | null>(null);
const [resultForUrl, setResultForUrl] = useState("");
const { token, ready, node } = useTurnstileToken(SITE_KEY);
const isLink = parseSource(url)?.kind === "link";
// A new link invalidates the previous preview's result (it was for a
// different page) without forcing a re-run the visitor didn't ask for.
useEffect(() => {
if (url !== resultForUrl) setResult(null);
}, [url, resultForUrl]);
const handledRequest = useRef(0);
useEffect(() => {
if (runRequest <= handledRequest.current || !ready || !isLink) return;
handledRequest.current = runRequest;
void run();
// run() reads the latest url/token from this render; re-running on its identity would loop.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [runRequest, ready, isLink]);
async function run() {
if (!isLink || loading) return;
setLoading(true);
setError("");
track("reel_preview_run", { source: "homepage-hero" });
try {
const data = await previewReel(url, token);
setResult(data);
setResultForUrl(url);
track("reel_preview_shown", { cached: data.cached, source_kind: data.source_kind });
} catch (err) {
setError(err instanceof Error ? err.message : "The preview failed. Please try again.");
} finally {
setLoading(false);
}
}
if (!isLink) return null;
return (
<ToolPanel>
{node("reel_preview")}
<div className="flex flex-wrap items-center justify-between gap-3">
<p className="text-sm text-muted-foreground">
{result && result.url === url
? "Here's a real preview of your reel -- no account needed."
: "See a real preview of your reel for this link, free, before you sign up."}
</p>
{!hideRunButton && !(result && result.url === url) && (
<Button type="button" size="lg" disabled={!ready || loading} onClick={() => void run()}>
{loading ? <Loader2 className="size-4 animate-spin" /> : <Play className="size-4" />}
{loading ? "Loading preview..." : "See a free preview"}
</Button>
)}
{hideRunButton && loading ? <Loader2 className="size-4 animate-spin text-muted-foreground" aria-label="Loading preview" /> : null}
</div>
{error ? <ErrorNote message={error} /> : null}
{result && result.url === url ? (
<div className="mt-5 flex flex-col gap-4 border-t border-border pt-5 sm:flex-row sm:items-center">
{result.frames[0] ? (
// eslint-disable-next-line @next/next/no-img-element -- a real, arbitrary third-party listing/page image; next/image's domain allowlist would need every customer's own host.
<img
src={result.frames[0]}
alt={result.title || "Reel preview frame"}
className="h-40 w-auto flex-shrink-0 rounded-lg border border-border object-cover sm:h-48"
loading="lazy"
/>
) : null}
<div className="flex-1 space-y-2">
{result.title ? <p className="text-sm font-medium">{result.title}</p> : null}
<p className="text-base">&ldquo;{result.hook.line}&rdquo;</p>
<p className="text-xs text-muted-foreground">
This is the opening line reel 1 of 3 would use. Sign up to render all 3, voiced and captioned.
</p>
<Button asChild size="lg" data-copy-source="src/features/create-compose/one-flow/plan.ts">
{/* copy-source: src/features/create-compose/one-flow/plan.ts VARIANT_COUNT */}
<Link href={signUpUrl(result)} onClick={() => track("signup_click", { source: "reel-preview" })}>
Sign up to get your {VARIANT_COUNT} reels <ArrowRight className="size-4" aria-hidden />
</Link>
</Button>
</div>
</div>
) : null}
</ToolPanel>
);
}