Open source CapCut alternative.
TypeScript
feat(site): the Custom export preset row is clickable
David Le0110c3b327cd
diff --git a/site/src/app/claim/ClaimCredits.tsx b/site/src/app/claim/ClaimCredits.tsxdeleted file mode 100644index d814808b..00000000--- a/site/src/app/claim/ClaimCredits.tsx+++ /dev/null@@ -1,95 +0,0 @@-"use client";--import { useState } from "react";--import { CUT_APP_BASE } from "@/cut/lib/appBase";-import { authClient } from "@/lib/auth-client";-import { formatCreditExpiry } from "@/lib/credits/top-up";--type Props = {- claimed: boolean;- credits: string;- lifetime: string | null;- token: string;-};--// One button between the email link and the credit. Claiming needs the-// offered account's session; without one the button goes to sign-in and-// comes back here.-export function ClaimCredits({ claimed, credits, lifetime, token }: Props) {- const { data: session, isPending: sessionPending } = authClient.useSession();- const [state, setState] = useState<- | { kind: "idle" }- | { kind: "pending" }- | { kind: "done"; expiresAt: string | null }- | { kind: "error"; message: string }- >(claimed ? { kind: "done", expiresAt: null } : { kind: "idle" });-- const claim = async () => {- setState({ kind: "pending" });- const response = await fetch("/api/credits/offers/claim", {- body: JSON.stringify({ token }),- headers: { "Content-Type": "application/json" },- method: "POST",- });- if (response.status === 403) {- setState({- kind: "error",- message: "This offer belongs to a different account. Sign in with the address the email was sent to.",- });- return;- }- if (!response.ok) {- setState({ kind: "error", message: "That didn't go through. Try again." });- return;- }- const body = (await response.json()) as { expiresAt: string | null };- setState({ kind: "done", expiresAt: body.expiresAt });- };-- if (state.kind === "done") {- return (- <>- <p>- {credits} in AI credits is on your account.- {state.expiresAt ? ` It expires ${formatCreditExpiry(new Date(state.expiresAt))}.` : ""}- </p>- <a- href={CUT_APP_BASE}- className="inline-block rounded-lg bg-[#0F0E0D] px-6 py-3 text-sm font-semibold text-[#F5EFE0] no-underline"- >- Open the editor- </a>- </>- );- }-- const here = `/claim?token=${encodeURIComponent(token)}`;- return (- <>- <p>- {credits} in AI credits is waiting for you.- {lifetime ? ` Once claimed, it is good for ${lifetime}.` : ""}- </p>- {session ? (- <button- type="button"- onClick={claim}- disabled={state.kind === "pending"}- className="cursor-pointer rounded-lg bg-[#0F0E0D] px-6 py-3 text-sm font-semibold text-[#F5EFE0] disabled:opacity-60"- >- Claim {credits}- </button>- ) : (- <a- href={`/sign-in?callbackURL=${encodeURIComponent(here)}`}- aria-disabled={sessionPending}- className="inline-block rounded-lg bg-[#0F0E0D] px-6 py-3 text-sm font-semibold text-[#F5EFE0] no-underline"- >- Sign in to claim- </a>- )}- {state.kind === "error" && <p className="text-red-600">{state.message}</p>}- </>- );-}diff --git a/site/src/app/claim/page.tsx b/site/src/app/claim/page.tsxdeleted file mode 100644index e5818d0c..00000000--- a/site/src/app/claim/page.tsx+++ /dev/null@@ -1,50 +0,0 @@-import { Suspense } from "react";--import { ClaimCredits } from "@/app/claim/ClaimCredits";-import { LegalPageShell } from "@/app/legal/LegalPageShell";-import { creditMicrosToString } from "@/lib/credits/amounts";-import { formatUsdPlain } from "@/lib/credits/format-usd";-import { verifyCreditOfferToken } from "@/lib/credits/offers";-import { describeCreditLifetime } from "@/lib/email/send-credits-offered";-import { prisma } from "@/lib/prisma";--// Where the claim button in a credit offer email lands. The token is verified-// here, but the credit waits for a button press: link-prefetching mail-// scanners open URLs on the recipient's behalf, and a claim on load would-// start the credit's lifetime before the person ever saw it.-export default function ClaimPage({- searchParams,-}: {- searchParams: Promise<{ token?: string }>;-}) {- return (- <LegalPageShell>- <h1>Your credits</h1>- <Suspense fallback={<p>Checking this link…</p>}>- <Offer searchParams={searchParams} />- </Suspense>- </LegalPageShell>- );-}--async function Offer({ searchParams }: { searchParams: Promise<{ token?: string }> }) {- const { token } = await searchParams;- const offerId = token ? verifyCreditOfferToken(token) : null;- const offer = offerId- ? await prisma.creditOffer.findUnique({- select: { amountMicros: true, claimedAt: true, expiresAfterDays: true },- where: { id: offerId },- })- : null;- if (!offer || !token) {- return <p>This link is no longer valid.</p>;- }- return (- <ClaimCredits- claimed={offer.claimedAt !== null}- credits={formatUsdPlain(creditMicrosToString(offer.amountMicros))}- lifetime={describeCreditLifetime(offer.expiresAfterDays)}- token={token}- />- );-}diff --git a/site/src/cut/components/ExportDialog.tsx b/site/src/cut/components/ExportDialog.tsxindex a689506d..7a13fe90 100644--- a/site/src/cut/components/ExportDialog.tsx+++ b/site/src/cut/components/ExportDialog.tsx@@ -55,7 +55,10 @@ export function ExportDialog() {const [choice, setChoice] = useState<ExportChoice>(EXPORT_QUICK_PRESETS[1].choice);// The field's own text, so a decimal in progress ("1.") survives the parse.const [mbpsText, setMbpsText] = useState("");- const preset = quickPresetOf(choice, resolutions);+ // Custom is a row of its own: picked by click, it stays lit whatever the+ // options add up to, until a preset row is clicked.+ const [customPicked, setCustomPicked] = useState(false);+ const preset = customPicked ? null : quickPresetOf(choice, resolutions);const settings = useMemo(() => choiceSettings(choice, resolutions), [choice, resolutions]);const set = (patch: Partial<ExportChoice>) => setChoice((c) => ({ ...c, ...patch }));@@ -138,11 +141,17 @@ export function ExportDialog() {title={p.detail}onClick={() => {setMbpsText("");+ setCustomPicked(false);setChoice({ ...p.choice });}}/>))}- <PresetRow checked={preset === null} label="Custom" />+ <PresetRow+ checked={preset === null}+ label="Custom"+ title="Set every option yourself"+ onClick={() => setCustomPicked(true)}+ /></div><div className="grid grid-cols-[auto_1fr_10rem] content-start items-center gap-x-4 gap-y-2.5 px-6 pb-6 max-sm:grid-cols-[auto_1fr] max-sm:pt-6">@@ -299,7 +308,8 @@ const PILL ="flex h-7 shrink-0 items-center whitespace-nowrap rounded-lg border border-border bg-background px-3.5 text-sm transition-colors hover:border-input";// One preset in the left pane: the name, and what it stands for on the right.-// "Custom" has no click: it is the row that lights when the options match no preset.+// "Custom" is the row that lights when the options match no preset, and the+// one a click lands on to start from the options as they are.function PresetRow({checked,label,@@ -311,23 +321,22 @@ function PresetRow({label: string;detail?: string;title?: string;- onClick?: () => void;+ onClick: () => void;}) {- const className = cn(- "flex h-11 items-center justify-between rounded-lg px-4 text-left transition-colors",- onClick && "hover:bg-foreground/5",- checked && "bg-foreground/10"- );- const body = (- <>+ return (+ <button+ type="button"+ role="radio"+ aria-checked={checked}+ title={title}+ className={cn(+ "flex h-11 items-center justify-between rounded-lg px-4 text-left transition-colors hover:bg-foreground/5",+ checked && "bg-foreground/10"+ )}+ onClick={onClick}+ ><span className="text-sm font-medium">{label}</span>{detail && <span className="text-xs text-muted-foreground">{detail}</span>}- </>- );- if (!onClick) return <div className={className}>{body}</div>;- return (- <button type="button" role="radio" aria-checked={checked} title={title} className={className} onClick={onClick}>- {body}</button>);}