MCPcopy
hub / github.com/tone-row/flowchart-fun / DownloadDropdown

Function DownloadDropdown

app/src/components/DownloadDropdown.tsx:11–166  ·  view source on GitHub ↗
({ children }: { children: React.ReactNode })

Source from the content-addressed store, hash-verified

9import * as Toast from "@radix-ui/react-toast";
10
11export function DownloadDropdown({ children }: { children: React.ReactNode }) {
12 const hasProAccess = useHasProAccess();
13 const filename = useDownloadFilename();
14 const watermark = !hasProAccess;
15 const scale = hasProAccess ? AUTH_IMG_SCALE : UNAUTH_IMG_SCALE;
16
17 // store a string for a recently completed action we will use to show a checkmark in certain cases
18 const [message, setMessage] = useState<string | null>(null);
19
20 const handleDownload = async (format: string) => {
21 if (!window.__cy) return;
22
23 if (format === "svg" && hasProAccess) {
24 const svg = await getSvg({ cy: window.__cy });
25 downloadSvg({ svg, filename });
26 } else {
27 try {
28 const { canvas } = await getCanvas({
29 cy: window.__cy,
30 type: format as "png" | "jpg",
31 watermark,
32 scale,
33 });
34 downloadCanvas({
35 canvas,
36 filename,
37 type: format as "png" | "jpg",
38 cleanup: () => {},
39 });
40 } catch (err) {
41 console.error(`Failed to download ${format}:`, err);
42 }
43 }
44 };
45
46 const handleCopy = async (format: string) => {
47 if (!window.__cy) return;
48
49 // if the type is svg, copy code
50 if (format === "svg") {
51 const svg = await getSvg({ cy: window.__cy });
52 navigator.clipboard.writeText(svg);
53 setMessage(t`Copied SVG code to clipboard`);
54 return;
55 }
56
57 const { canvas } = await getCanvas({
58 cy: window.__cy,
59 type: format as "png" | "jpg",
60 watermark,
61 scale,
62 });
63
64 canvas.toBlob(async (blob) => {
65 if (blob) {
66 try {
67 await navigator.clipboard.write([
68 new ClipboardItem({ [blob.type]: blob }),

Callers

nothing calls this directly

Calls 5

useHasProAccessFunction · 0.90
useDownloadFilenameFunction · 0.90
handleDownloadFunction · 0.85
handleSvgActionFunction · 0.85
handleCopyFunction · 0.85

Tested by

no test coverage detected