import { Link } from 'react-router-dom' import { useQuery } from '@tanstack/react-query' import { ResponsiveContainer, BarChart, Bar, XAxis, YAxis, Tooltip, CartesianGrid, } from 'recharts' import api from '../utils/api' import { formatDuration, sportColor, convertKm, distanceUnitLabel, formatElevation } from '../utils/format' import { useUnit } from '../hooks/useUnits' import SportIcon from '../components/ui/SportIcon' function StatTile({ label, value, sub }) { return (

{label}

{value}

{sub &&

{sub}

}
) } export default function SummaryPage() { const unit = useUnit() const distLabel = distanceUnitLabel(unit) const dist = km => `${convertKm(km, unit).toLocaleString(undefined, { maximumFractionDigits: 0 })} ${distLabel}` const { data, isLoading } = useQuery({ queryKey: ['stats-summary'], queryFn: () => api.get('/activities/stats/summary').then(r => r.data), }) const byYear = data?.by_year || [] const allTime = data?.all_time const chartData = [...byYear].reverse().map(y => ({ year: String(y.year), distance: Math.round(convertKm(y.distance_km, unit)), })) return (

Summary

← Activities
{isLoading ? (
Loading…
) : !allTime || allTime.count === 0 ? (

No activities yet

Import your data to see your totals

) : ( <> {/* All-time totals */}

All time

{/* Distance per year */} {chartData.length > 1 && (

Distance per year ({distLabel})

[`${v.toLocaleString()} ${distLabel}`, 'Distance']} />
)} {/* Per-year breakdown */}
{byYear.map(y => (

{y.year}

{y.count} activities {dist(y.distance_km)} {formatDuration(y.duration_s)} {formatElevation(y.elevation_m, unit)}
{y.by_sport.map(s => (
{(s.sport_type || 'other').replace(/_/g, ' ')} {s.count} act. {dist(s.distance_km)} {formatDuration(s.duration_s)}
))}
))}
)}
) }