feat(api): update ResultScreen to use fallback URL for embed snippet

This commit is contained in:
shay
2026-04-20 16:05:33 -04:00
parent 451cb45788
commit 795f49d0a8
2 changed files with 67 additions and 3 deletions
@@ -14,15 +14,20 @@ type Props = {
generating: boolean
generatedSvg: string | null
generateError: string | null
// Owner renders embed as /api/<u>; visitors get /api/<u>?<their settings>.
// We display whichever URL was used to produce the SVG above, so the
// snippet they copy matches what they're previewing.
embedUrl: string
onBack: () => void
onRegenerate: () => void
}
export function ResultScreen({ username, generating, generatedSvg, generateError, onBack, onRegenerate }: Props) {
export function ResultScreen({ username, generating, generatedSvg, generateError, embedUrl, onBack, onRegenerate }: Props) {
const safeSvg = useMemo(() => (generatedSvg ? sanitizeSvg(generatedSvg) : ''), [generatedSvg])
const [copied, setCopied] = useState(false)
const embedUrl = `${window.location.origin}/api/${encodeURIComponent(username)}`
const embedSnippet = `![${username}](${embedUrl})`
const fallbackUrl = `${window.location.origin}/api/${encodeURIComponent(username)}`
const finalUrl = embedUrl || fallbackUrl
const embedSnippet = `![${username}](${finalUrl})`
const copy = async () => {
try {