Open source CapCut alternative.
TypeScript
fix(site): share dialog keeps its layout while loading
David Le472a762c749e
diff --git a/site/src/cut/components/ShareDialog.tsx b/site/src/cut/components/ShareDialog.tsxindex adc7fee8..5699bbc6 100644--- a/site/src/cut/components/ShareDialog.tsx+++ b/site/src/cut/components/ShareDialog.tsx@@ -1,7 +1,7 @@"use client";import { useEffect, useState } from "react";-import { Check, ChevronDown, Globe, Link as LinkIcon, Loader2, Lock, X } from "lucide-react";+import { Check, ChevronDown, Globe, Link as LinkIcon, Lock, X } from "lucide-react";import { Button } from "@/components/ui/button";import {Dialog,@@ -25,6 +25,11 @@ import type { ShareFeatures } from "@/cut/lib/types";// open the link to anyone, always read-only. The advanced switches opt extra// surfaces in; with all of them off a viewer gets the preview and timeline// only. Every change PUTs immediately — closing the dialog is done.+//+// The dialog renders its final layout on the first frame and disables the+// controls until the fetch lands, so nothing reflows while it loads. The+// "Stop sharing" slot keeps its space for the same reason: creating a share+// by copying the link fills it in place.type ShareAccess = "restricted" | "public";@@ -174,166 +179,167 @@ export function ShareDialog({}};+ const busy = loading || saving;+return (<Dialog open onOpenChange={(open) => !open && onClose()}><DialogContent className="sm:max-w-sm"><DialogHeader><DialogTitle>Share project</DialogTitle></DialogHeader>- {loading ? (- <div className="grid h-32 place-items-center text-muted-foreground">- <Loader2 className="size-4 animate-spin" />- </div>- ) : (- <div className="flex flex-col gap-4">- <div className="flex flex-col gap-1.5">- <span className="text-[11px] font-medium tracking-wide text-muted-foreground uppercase">- People- </span>- <input- className="w-full rounded-lg border border-input bg-transparent px-2.5 py-2 text-[12.5px] outline-none focus:border-ring"- type="email"- placeholder="Invite by email, press Enter"- value={draft}- onChange={(e) => setDraft(e.target.value)}- onKeyDown={(e) => {- if (e.key === "Enter") {- e.preventDefault();- addEmail();- }- }}- />- {current.emails.length > 0 && (- <div className="flex flex-wrap gap-1">- {current.emails.map((email) => (- <span- key={email}- className="inline-flex items-center gap-1 rounded-full bg-muted py-0.5 pr-1 pl-2 text-[11.5px]"+ <div className="flex flex-col gap-4">+ <div className="flex flex-col gap-1.5">+ <span className="text-[11px] font-medium tracking-wide text-muted-foreground uppercase">+ People+ </span>+ <input+ className="w-full rounded-lg border border-input bg-transparent px-2.5 py-2 text-[12.5px] outline-none focus:border-ring disabled:opacity-60"+ type="email"+ placeholder="Invite by email, press Enter"+ disabled={loading}+ value={draft}+ onChange={(e) => setDraft(e.target.value)}+ onKeyDown={(e) => {+ if (e.key === "Enter") {+ e.preventDefault();+ addEmail();+ }+ }}+ />+ {current.emails.length > 0 && (+ <div className="flex flex-wrap gap-1">+ {current.emails.map((email) => (+ <span+ key={email}+ className="inline-flex items-center gap-1 rounded-full bg-muted py-0.5 pr-1 pl-2 text-[11.5px]"+ >+ {email}+ <button+ aria-label={`Remove ${email}`}+ className="grid size-4 place-items-center rounded-full text-muted-foreground hover:bg-black/10 hover:text-foreground"+ onClick={() => removeEmail(email)}>- {email}- <button- aria-label={`Remove ${email}`}- className="grid size-4 place-items-center rounded-full text-muted-foreground hover:bg-black/10 hover:text-foreground"- onClick={() => removeEmail(email)}- >- <X className="size-2.5" />- </button>- </span>- ))}- </div>- )}- </div>+ <X className="size-2.5" />+ </button>+ </span>+ ))}+ </div>+ )}+ </div>- <div className="flex flex-col gap-1.5">- <span className="text-[11px] font-medium tracking-wide text-muted-foreground uppercase">- General access- </span>- <DropdownMenu>- <DropdownMenuTrigger className="flex items-center gap-2 rounded-lg border border-input px-2.5 py-2 text-left text-[12.5px] transition-colors hover:border-ring">- {current.access === "public" ? (- <Globe className="size-4 text-muted-foreground" />- ) : (- <Lock className="size-4 text-muted-foreground" />- )}- <span className="min-w-0 flex-1">- <span className="block font-medium">- {current.access === "public" ? "Anyone with the link" : "Restricted"}- </span>- <span className="block text-[11px] text-muted-foreground">- {current.access === "public"- ? "Anyone can view — no sign-in needed"- : "Only people you invite can view, signed in"}- </span>+ <div className="flex flex-col gap-1.5">+ <span className="text-[11px] font-medium tracking-wide text-muted-foreground uppercase">+ General access+ </span>+ <DropdownMenu>+ <DropdownMenuTrigger+ disabled={loading}+ className="flex items-center gap-2 rounded-lg border border-input px-2.5 py-2 text-left text-[12.5px] transition-colors hover:border-ring disabled:opacity-60 disabled:hover:border-input"+ >+ {current.access === "public" ? (+ <Globe className="size-4 text-muted-foreground" />+ ) : (+ <Lock className="size-4 text-muted-foreground" />+ )}+ <span className="min-w-0 flex-1">+ <span className="block font-medium">+ {current.access === "public" ? "Anyone with the link" : "Restricted"}+ </span>+ <span className="block text-[11px] text-muted-foreground">+ {current.access === "public"+ ? "Anyone can view — no sign-in needed"+ : "Only people you invite can view, signed in"}</span>- <ChevronDown className="size-3.5 text-muted-foreground" />- </DropdownMenuTrigger>- <DropdownMenuContent align="start" className="w-72">- <DropdownMenuItem onClick={() => setAccess("restricted")}>- <Lock />- <span className="flex-1">- Restricted- <span className="block text-[10.5px] text-muted-foreground">- Only people you invite can view, signed in- </span>+ </span>+ <ChevronDown className="size-3.5 text-muted-foreground" />+ </DropdownMenuTrigger>+ <DropdownMenuContent align="start" className="w-72">+ <DropdownMenuItem onClick={() => setAccess("restricted")}>+ <Lock />+ <span className="flex-1">+ Restricted+ <span className="block text-[10.5px] text-muted-foreground">+ Only people you invite can view, signed in</span>- {current.access === "restricted" && (- <Check className="size-3.5 text-muted-foreground" />- )}- </DropdownMenuItem>- <DropdownMenuItem onClick={() => setAccess("public")}>- <Globe />- <span className="flex-1">- Anyone with the link- <span className="block text-[10.5px] text-muted-foreground">- Anyone can view — no sign-in needed- </span>+ </span>+ {current.access === "restricted" && (+ <Check className="size-3.5 text-muted-foreground" />+ )}+ </DropdownMenuItem>+ <DropdownMenuItem onClick={() => setAccess("public")}>+ <Globe />+ <span className="flex-1">+ Anyone with the link+ <span className="block text-[10.5px] text-muted-foreground">+ Anyone can view — no sign-in needed</span>- {current.access === "public" && (- <Check className="size-3.5 text-muted-foreground" />- )}- </DropdownMenuItem>- </DropdownMenuContent>- </DropdownMenu>- </div>+ </span>+ {current.access === "public" && (+ <Check className="size-3.5 text-muted-foreground" />+ )}+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ </div>- <details className="group">- <summary className="cursor-pointer list-none text-[11px] font-medium tracking-wide text-muted-foreground uppercase select-none">- <span className="inline-flex items-center gap-1">- Also share- <ChevronDown className="size-3 transition-transform group-open:rotate-180" />- </span>- </summary>- <p className="mt-1 text-[11px] leading-relaxed text-muted-foreground">- Viewers always get the preview and timeline, read-only. Switch- on anything else they should see.- </p>- <div className="mt-1 flex flex-col">- {FEATURE_ROWS.map(({ key, label, hint }) => (- <label- key={key}- className="flex min-h-9 cursor-pointer items-center justify-between gap-2.5"- >- <span className="text-[13px]">- {label}- <span className="block text-[10.5px] text-muted-foreground">{hint}</span>- </span>- <Switch- checked={current.features[key]}- onCheckedChange={(on) => setFeature(key, on)}- />- </label>- ))}- </div>- </details>+ <details className="group">+ <summary className="cursor-pointer list-none text-[11px] font-medium tracking-wide text-muted-foreground uppercase select-none">+ <span className="inline-flex items-center gap-1">+ Also share+ <ChevronDown className="size-3 transition-transform group-open:rotate-180" />+ </span>+ </summary>+ <p className="mt-1 text-[11px] leading-relaxed text-muted-foreground">+ Viewers always get the preview and timeline, read-only. Switch+ on anything else they should see.+ </p>+ <div className="mt-1 flex flex-col">+ {FEATURE_ROWS.map(({ key, label, hint }) => (+ <label+ key={key}+ className="flex min-h-9 cursor-pointer items-center justify-between gap-2.5"+ >+ <span className="text-[13px]">+ {label}+ <span className="block text-[10.5px] text-muted-foreground">{hint}</span>+ </span>+ <Switch+ checked={current.features[key]}+ disabled={loading}+ onCheckedChange={(on) => setFeature(key, on)}+ />+ </label>+ ))}+ </div>+ </details>- {error && <p className="text-sm text-red-600">{error}</p>}- </div>- )}- {!loading && (- <DialogFooter className="mt-1 flex-col gap-2 sm:flex-col">- <Button className="w-full" disabled={saving} onClick={() => void copyLink()}>- {copied ? (- <>- <Check data-icon="inline-start" /> Copied- </>- ) : (- <>- <LinkIcon data-icon="inline-start" /> Copy link- </>- )}- </Button>- {share && (- <Button- variant="ghost"- className="w-full text-muted-foreground hover:text-destructive"- disabled={saving}- onClick={() => void removeShare()}- >- Stop sharing- </Button>+ {error && <p className="text-sm text-red-600">{error}</p>}+ </div>+ <DialogFooter className="mt-1 flex-col gap-2 sm:flex-col">+ <Button className="w-full" disabled={busy} onClick={() => void copyLink()}>+ {copied ? (+ <>+ <Check data-icon="inline-start" /> Copied+ </>+ ) : (+ <>+ <LinkIcon data-icon="inline-start" /> Copy link+ </>)}- </DialogFooter>- )}+ </Button>+ <Button+ variant="ghost"+ aria-hidden={!share}+ tabIndex={share ? undefined : -1}+ className={`w-full text-muted-foreground hover:text-destructive ${+ share ? "" : "pointer-events-none invisible"+ }`}+ disabled={busy || !share}+ onClick={() => void removeShare()}+ >+ Stop sharing+ </Button>+ </DialogFooter></DialogContent></Dialog>);