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

Function CloneButton

app/src/components/CloneButton.tsx:13–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11import { useMutation } from "react-query";
12
13export function CloneButton() {
14 const hasProAccess = useHasProAccess();
15 const language = useContext(AppContext).language;
16 const userId = useUserId();
17 const makeChartMutation = useMutation(
18 "makeChart",
19 async () => {
20 if (!userId) throw new Error("No user id");
21 const name = getFunFlowchartName(language as keyof typeof languages);
22 const fullText = docToString(useDoc.getState());
23 const response = await makeChart({
24 name,
25 user_id: userId,
26 chart: fullText,
27 });
28 return response;
29 },
30 {
31 retry: false,
32 onSuccess: (response: any) => {
33 queryClient.invalidateQueries(["auth", "hostedCharts"]);
34 window.open(`/u/${response.data[0].id}`, "_blank");
35 },
36 }
37 );
38 if (!hasProAccess) return null;
39 return (
40 <Button2
41 color="blue"
42 isLoading={makeChartMutation.isLoading}
43 onClick={() => {
44 makeChartMutation.mutate();
45 }}
46 data-session-activity="Clone Chart"
47 >
48 <Trans>Clone</Trans>
49 </Button2>
50 );
51}

Callers

nothing calls this directly

Calls 5

useHasProAccessFunction · 0.90
useUserIdFunction · 0.90
getFunFlowchartNameFunction · 0.90
docToStringFunction · 0.90
makeChartFunction · 0.90

Tested by

no test coverage detected