()
| 25 | }; |
| 26 | |
| 27 | export default function New2() { |
| 28 | // Whether we're using AI to generate the chart |
| 29 | const [isAI, setIsAI] = useState(false); |
| 30 | const userId = useUserId(); |
| 31 | const navigate = useNavigate(); |
| 32 | const createChartMutation = useMutation( |
| 33 | async (options: CreateChartOptions) => { |
| 34 | if (!userId) throw new Error("No user id"); |
| 35 | |
| 36 | // Get Session Token |
| 37 | if (!supabase) throw new Error("No supabase"); |
| 38 | const { data } = await supabase.auth.getSession(); |
| 39 | if (!data.session) throw new Error("No Session"); |
| 40 | |
| 41 | // Get Template |
| 42 | const importTemplate = await import( |
| 43 | `../lib/templates/${options.template}-template.ts` |
| 44 | ); |
| 45 | let content: string = importTemplate.content; |
| 46 | const theme: FFTheme = importTemplate.theme; |
| 47 | const cytoscapeStyle = importTemplate.cytoscapeStyle ?? ""; |
| 48 | |
| 49 | const chart = `${content}\n=====${JSON.stringify({ |
| 50 | themeEditor: theme, |
| 51 | cytoscapeStyle, |
| 52 | })}=====`; |
| 53 | |
| 54 | return supabase |
| 55 | .from("user_charts") |
| 56 | .insert({ name: options.name, chart: chart, user_id: userId }) |
| 57 | .select(); |
| 58 | }, |
| 59 | { |
| 60 | onSettled: () => { |
| 61 | setIsAI(false); |
| 62 | }, |
| 63 | onSuccess: (response: any) => { |
| 64 | const chartId = response.data[0]?.id; |
| 65 | if (chartId) navigate(`/u/${chartId}`); |
| 66 | }, |
| 67 | } |
| 68 | ); |
| 69 | |
| 70 | const hasProAccess = useHasProAccess(); |
| 71 | const handleSubmit = useCallback( |
| 72 | (e: React.FormEvent<HTMLFormElement>) => { |
| 73 | e.preventDefault(); |
| 74 | if (!hasProAccess) { |
| 75 | showPaywall({ |
| 76 | title: createUnlimitedTitle(), |
| 77 | content: createUnlimitedContent(), |
| 78 | toPricingCode: "New", |
| 79 | }); |
| 80 | return; |
| 81 | } |
| 82 | const data = new FormData(e.currentTarget); |
| 83 | const name = data.get("name")?.toString(); |
| 84 | const template = data.get("template")?.toString(); |
nothing calls this directly
no test coverage detected