import { AppShellWithMenu } from '../FitzStudio/Appshell/Appshell'; import { Card, Grid, Title, Loader } from '@mantine/core'; import { useEffect, useState } from 'react'; import ReactECharts from 'echarts-for-react'; type ChartOption = any; function useChartOption(endpoint: string) { const [option, setOption] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { fetch(`/api/v1/charts/${endpoint}`) .then((res) => res.json()) .then((json) => setOption(json)) .catch(console.error) .finally(() => setLoading(false)); }, [endpoint]); return { option, loading }; } export function VisualizacionesRandom() { const charts = [ { title: 'Gráfico de barras', endpoint: 'bar' }, { title: 'Gráfico de líneas', endpoint: 'line' }, { title: 'Gráfico de pastel', endpoint: 'pie' }, { title: 'Scatter plot', endpoint: 'scatter' }, ]; return ( {charts.map(({ title, endpoint }, idx) => { const { option, loading } = useChartOption(endpoint); return ( {title} {loading || !option ? ( ) : ( )} ); })} ); }