diff --git a/landing/src/components/docs/copy-markdown-button.tsx b/landing/src/components/docs/copy-markdown-button.tsx index 57f1a489..5b960b40 100644 --- a/landing/src/components/docs/copy-markdown-button.tsx +++ b/landing/src/components/docs/copy-markdown-button.tsx @@ -2,18 +2,27 @@ import { Check, Copy } from "lucide-react"; import { useCallback, useState } from "react"; +import { toast } from "sonner"; import { Button } from "@/components/ui/button"; export function CopyMarkdownButton({ markdownUrl }: { markdownUrl: string }) { const [copied, setCopied] = useState(false); - const onClick = useCallback(async () => { - const res = await fetch(markdownUrl); - const text = await res.text(); - await navigator.clipboard.writeText(text); + const onClick = useCallback(() => { setCopied(true); setTimeout(() => setCopied(false), 2000); + + void fetch(markdownUrl) + .then((res) => { + if (!res.ok) throw new Error("fetch failed"); + return res.text(); + }) + .then((text) => navigator.clipboard.writeText(text)) + .catch(() => { + toast.error("Failed to copy markdown"); + setCopied(false); + }); }, [markdownUrl]); return (