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

Function LoadFileButton

app/src/components/LoadFileButton.tsx:14–134  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12import { docToString } from "../lib/useDoc";
13
14export function LoadFileButton() {
15 const [open, setOpen] = useState(false);
16 const [doc, setDoc] = useState("");
17 const [chart, setChart] = useState<null | Awaited<
18 ReturnType<typeof prepareChart>
19 >>(null);
20 const hasProAccess = useHasProAccess();
21
22 return (
23 <>
24 <input
25 type="file"
26 accept=".txt"
27 data-testid="load-file-input"
28 className="sr-only"
29 onChange={(event) => {
30 const file = (event.target as HTMLInputElement).files?.[0];
31 if (!file) return;
32 const reader = new FileReader();
33 reader.onload = async (event) => {
34 const result = event.target?.result as string;
35 try {
36 prepareChart({
37 doc: result,
38 set: false,
39 details: {
40 id: "",
41 title: "",
42 isHosted: false,
43 },
44 })
45 .then((chart) => {
46 if (chart) {
47 // build a chart with a normal expiry date
48 const { text, details, ...rest } = chart;
49 const meta = { ...rest.meta, expires: getExpirationDate() };
50 const doc = docToString({ text, meta, details });
51 setChart(chart);
52 setDoc(doc);
53 setOpen(true);
54 } else {
55 setOpen(false);
56 }
57 })
58 .catch((error) => {
59 console.error(error);
60 });
61 } catch (error) {
62 console.error(error);
63 }
64 };
65 reader.readAsText(file);
66 }}
67 />
68 <EditorActionTextButton
69 icon={PiFolderOpenDuotone}
70 data-testid="load-file-button"
71 data-session-activity="Load File"

Callers

nothing calls this directly

Calls 5

useHasProAccessFunction · 0.90
prepareChartFunction · 0.90
getExpirationDateFunction · 0.90
docToStringFunction · 0.90
showPaywallFunction · 0.90

Tested by

no test coverage detected