From a1d1813a51627b4ba0ec2c2f2ac7460a3b794990 Mon Sep 17 00:00:00 2001 From: shay Date: Wed, 27 May 2026 10:23:49 -0700 Subject: [PATCH] feat(api): add endpoint for retrieving growth data for the dashboard --- .../frontend/src/components/GrowthChart.tsx | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 generator/frontend/src/components/GrowthChart.tsx diff --git a/generator/frontend/src/components/GrowthChart.tsx b/generator/frontend/src/components/GrowthChart.tsx new file mode 100644 index 0000000..03c3ced --- /dev/null +++ b/generator/frontend/src/components/GrowthChart.tsx @@ -0,0 +1,84 @@ +import { useEffect, useState } from 'react' +import { fetchGrowth, type Growth } from '../lib/dev' + +type Mode = 'daily' | 'weekly' + +export function GrowthChart() { + const [data, setData] = useState(null) + const [mode, setMode] = useState('daily') + useEffect(() => { fetchGrowth().then(setData).catch(() => {}) }, []) + + const points = data ? (mode === 'daily' ? data.daily : data.weekly) : [] + const labels = points.map(p => 'day' in p ? p.day : p.week) + const requests = points.map(p => p.requests) + const users = points.map(p => p.users) + + return ( +
+
+
Growth
+
+ setMode('daily')}>day · 30 + setMode('weekly')}>week · 12 +
+
+ {points.length === 0 ? ( +
loading…
+ ) : ( +
+ + +
+ )} +
+ ) +} + +function Tab({ active, onClick, children }: { active: boolean; onClick: () => void; children: React.ReactNode }) { + return ( + + ) +} + +function Line({ label, values, labels, stroke }: { + label: string; values: number[]; labels: string[]; stroke: string +}) { + const width = 600 + const height = 70 + const max = Math.max(1, ...values) + const stepX = width / Math.max(1, values.length - 1) + const total = values.reduce((a, b) => a + b, 0) + const latest = values[values.length - 1] ?? 0 + const pts = values.map((v, i) => { + const x = i * stepX + const y = height - (v / max) * (height - 4) - 2 + return `${x.toFixed(1)},${y.toFixed(1)}` + }).join(' ') + const area = `0,${height} ${pts} ${width},${height}` + return ( +
+
+ {label} + + latest {latest.toLocaleString()} + total {total.toLocaleString()} + +
+ + + + +
+ {labels[0]} + {labels[labels.length - 1]} +
+
+ ) +}