Skip to content

armgit / lyftr

Public Imported from GitHub
0

Self-hosted fitness tracker. Log workouts, track nutrition, and monitor progress. Docker deployment, mobile-friendly.

feat: dashboard redesign, Docker deployment, and repo polish

Cawlumm71103a5240c1
diff --git a/.env.example b/.env.example
new file mode 100644
index 0000000..3f9d0db
--- /dev/null
+++ b/.env.example
@@ -0,0 +1,6 @@
+# Required
+JWT_SECRET=change-me-to-a-random-32-plus-character-string
+
+# Optional
+CORS_ORIGIN=http://localhost
+PORT=80
diff --git a/.gitignore b/.gitignore
index 24b04a0..fdfe3bb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -47,5 +47,6 @@ tmp/
temp/
*.tmp
-# design docs
-docs/
+# design docs (keep screenshots for README)
+docs/*.md
+docs/*.txt
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..22fb06d
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2026 cwlumm
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..c51a2f6
--- /dev/null
+++ b/README.md
@@ -0,0 +1,112 @@
+# Lyftr
+
+**Self-hosted fitness tracker. Your data, your server.**
+
+<p align="center">
+ <img src="docs/screenshots/dashboard-mobile.png" width="220" alt="Dashboard" />
+ <img src="docs/screenshots/workouts-mobile.png" width="220" alt="Workouts" />
+ <img src="docs/screenshots/programs-mobile.png" width="220" alt="Programs" />
+</p>
+
+<p align="center">
+ <img src="docs/screenshots/dashboard-desktop.png" width="700" alt="Dashboard desktop" />
+</p>
+
+## Features
+
+- **Workout logging** — exercise library with sets, reps, and weight tracking
+- **Program builder** — create reusable workout templates
+- **Nutrition tracking** — log food and track macros against daily targets
+- **Weight tracking** — daily entries with trend visualization
+- **Dashboard** — volume charts, consistency heatmap, muscle balance at a glance
+- **Active workout mode** — guided set-by-set experience
+- **Mobile-first design** — works great in a phone browser
+
+## Self-Hosting with Docker
+
+### Prerequisites
+
+- Docker and Docker Compose installed
+- 512 MB RAM minimum
+
+### Quick Start
+
+```bash
+git clone https://github.com/Cawlumm/lyftr.git
+cd lyftr
+cp .env.example .env
+# Edit .env — set a strong JWT_SECRET (32+ characters)
+docker compose up -d
+```
+
+Open http://localhost in your browser and create your account.
+
+### Configuration
+
+| Variable | Default | Description |
+|----------|---------|-------------|
+| `JWT_SECRET` | *required* | Min 32-char secret for JWT signing |
+| `CORS_ORIGIN` | `http://localhost` | Frontend origin — change if using a custom domain |
+| `PORT` | `80` | Host port for the web interface |
+
+All variables go in `.env` at the project root (copy from `.env.example`).
+
+### Data Persistence
+
+Workout data is stored in `./data/lyftr.db` (SQLite). Back this file up regularly.
+
+```bash
+# One-off backup
+cp ./data/lyftr.db ./data/lyftr.db.backup
+
+# Update to the latest version
+docker compose pull
+docker compose up -d
+```
+
+### Running on a VPS
+
+```bash
+# On your server (Ubuntu/Debian)
+sudo apt update && sudo apt install -y docker.io docker-compose-plugin
+
+git clone https://github.com/Cawlumm/lyftr.git
+cd lyftr
+cp .env.example .env
+nano .env # set JWT_SECRET and CORS_ORIGIN to your domain
+
+docker compose up -d
+```
+
+Point your domain at the server IP, update `CORS_ORIGIN` in `.env`, then restart:
+
+```bash
+docker compose up -d
+```
+
+For HTTPS, place Lyftr behind a reverse proxy such as Caddy or nginx with a Let's Encrypt certificate.
+
+## Tech Stack
+
+| Layer | Technology |
+|-------|-----------|
+| Backend | Go, Gin, SQLite |
+| Frontend | React, TypeScript, Tailwind CSS, Vite |
+| Auth | JWT with refresh tokens |
+| Deployment | Docker, nginx |
+
+## Development
+
+```bash
+# Backend (runs on :3000)
+cd backend && go run main.go
+
+# Frontend (runs on :5173, proxies /api to :3000)
+cd web && npm install && npm run dev
+```
+
+Environment variables are read from a `.env` file in each directory. See `backend/config/config.go` for all supported variables.
+
+## License
+
+MIT
diff --git a/backend/.dockerignore b/backend/.dockerignore
new file mode 100644
index 0000000..899c7b7
--- /dev/null
+++ b/backend/.dockerignore
@@ -0,0 +1,4 @@
+data/
+*.db
+.env
+tmp/
diff --git a/backend/Dockerfile b/backend/Dockerfile
new file mode 100644
index 0000000..395064b
--- /dev/null
+++ b/backend/Dockerfile
@@ -0,0 +1,29 @@
+# Stage 1: Build
+FROM golang:1.23-alpine AS builder
+
+WORKDIR /build
+
+# Download dependencies first (layer cache)
+COPY go.mod go.sum ./
+RUN go mod download
+
+# Copy source and build a statically linked binary
+COPY . .
+RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o lyftr-api ./...
+
+# Stage 2: Runtime
+FROM alpine:3.19
+
+# ca-certificates for any outbound TLS calls; wget for healthcheck
+RUN apk add --no-cache ca-certificates wget
+
+WORKDIR /app
+
+COPY --from=builder /build/lyftr-api .
+
+# Persistent data directory (mount a volume here)
+RUN mkdir -p /app/data
+
+EXPOSE 3000
+
+ENTRYPOINT ["/app/lyftr-api"]
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..4c5d041
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,31 @@
+version: '3.8'
+
+services:
+ backend:
+ build: ./backend
+ restart: unless-stopped
+ volumes:
+ - ./data:/app/data
+ environment:
+ - ENV=production
+ - PORT=3000
+ - JWT_SECRET=${JWT_SECRET}
+ - CORS_ORIGIN=${CORS_ORIGIN:-http://localhost}
+ - DB_TYPE=sqlite
+ - DB_PATH=/app/data/lyftr.db
+ expose:
+ - "3000"
+ healthcheck:
+ test: ["CMD", "wget", "-qO-", "http://localhost:3000/health"]
+ interval: 30s
+ timeout: 10s
+ retries: 3
+
+ frontend:
+ build: ./web
+ restart: unless-stopped
+ ports:
+ - "${PORT:-80}:80"
+ depends_on:
+ backend:
+ condition: service_healthy
diff --git a/docs/screenshots/active-workout-desktop.png b/docs/screenshots/active-workout-desktop.png
new file mode 100644
index 0000000..d21937b
Binary files /dev/null and b/docs/screenshots/active-workout-desktop.png differ
diff --git a/docs/screenshots/active-workout-mobile.png b/docs/screenshots/active-workout-mobile.png
new file mode 100644
index 0000000..d45e5c9
Binary files /dev/null and b/docs/screenshots/active-workout-mobile.png differ
diff --git a/docs/screenshots/dashboard-desktop.png b/docs/screenshots/dashboard-desktop.png
new file mode 100644
index 0000000..b945160
Binary files /dev/null and b/docs/screenshots/dashboard-desktop.png differ
diff --git a/docs/screenshots/dashboard-mobile.png b/docs/screenshots/dashboard-mobile.png
new file mode 100644
index 0000000..8989c0f
Binary files /dev/null and b/docs/screenshots/dashboard-mobile.png differ
diff --git a/docs/screenshots/programs-desktop.png b/docs/screenshots/programs-desktop.png
new file mode 100644
index 0000000..450c888
Binary files /dev/null and b/docs/screenshots/programs-desktop.png differ
diff --git a/docs/screenshots/programs-mobile.png b/docs/screenshots/programs-mobile.png
new file mode 100644
index 0000000..dc7bd3a
Binary files /dev/null and b/docs/screenshots/programs-mobile.png differ
diff --git a/docs/screenshots/workouts-desktop.png b/docs/screenshots/workouts-desktop.png
new file mode 100644
index 0000000..36d7755
Binary files /dev/null and b/docs/screenshots/workouts-desktop.png differ
diff --git a/docs/screenshots/workouts-mobile.png b/docs/screenshots/workouts-mobile.png
new file mode 100644
index 0000000..516fea6
Binary files /dev/null and b/docs/screenshots/workouts-mobile.png differ
diff --git a/web/.dockerignore b/web/.dockerignore
new file mode 100644
index 0000000..deed335
--- /dev/null
+++ b/web/.dockerignore
@@ -0,0 +1,3 @@
+node_modules/
+dist/
+.env
diff --git a/web/Dockerfile b/web/Dockerfile
new file mode 100644
index 0000000..154feeb
--- /dev/null
+++ b/web/Dockerfile
@@ -0,0 +1,25 @@
+# Stage 1: Build
+FROM node:20-alpine AS builder
+
+WORKDIR /app
+
+# Install dependencies first (layer cache)
+COPY package.json package-lock.json ./
+RUN npm ci
+
+# Copy source and build
+COPY . .
+RUN npm run build
+
+# Stage 2: Runtime
+FROM nginx:alpine
+
+# Custom nginx config for SPA + API proxy
+COPY nginx.conf /etc/nginx/conf.d/default.conf
+
+# Copy built assets
+COPY --from=builder /app/dist /usr/share/nginx/html
+
+EXPOSE 80
+
+CMD ["nginx", "-g", "daemon off;"]
diff --git a/web/nginx.conf b/web/nginx.conf
new file mode 100644
index 0000000..51a8e60
--- /dev/null
+++ b/web/nginx.conf
@@ -0,0 +1,43 @@
+server {
+ listen 80;
+ server_name _;
+
+ root /usr/share/nginx/html;
+ index index.html;
+
+ # Gzip compression
+ gzip on;
+ gzip_vary on;
+ gzip_min_length 1024;
+ gzip_proxied any;
+ gzip_types
+ text/plain
+ text/css
+ text/javascript
+ application/javascript
+ application/json
+ image/svg+xml;
+
+ # Proxy API requests to the backend service
+ location /api/ {
+ proxy_pass http://backend:3000/api/;
+ proxy_http_version 1.1;
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ proxy_read_timeout 60s;
+ }
+
+ # SPA fallback — serve index.html for all non-file routes
+ location / {
+ try_files $uri $uri/ /index.html;
+ }
+
+ # Cache static assets aggressively
+ location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?)$ {
+ expires 1y;
+ add_header Cache-Control "public, immutable";
+ try_files $uri =404;
+ }
+}
diff --git a/web/package-lock.json b/web/package-lock.json
index ab143b9..fffd575 100644
--- a/web/package-lock.json
+++ b/web/package-lock.json
@@ -20,6 +20,7 @@
"zustand": "^4.4.6"
},
"devDependencies": {
+ "@playwright/test": "^1.59.1",
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.14.0",
@@ -922,6 +923,21 @@
"node": ">= 8"
}
},
+ "node_modules/@playwright/test": {
+ "version": "1.59.1",
+ "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.59.1.tgz",
+ "integrity": "sha512-PG6q63nQg5c9rIi4/Z5lR5IVF7yU5MqmKaPOe0HSc0O2cX1fPi96sUQu5j7eo4gKCkB2AnNGoWt7y4/Xx3Kcqg==",
+ "dev": true,
+ "dependencies": {
+ "playwright": "1.59.1"
+ },
+ "bin": {
+ "playwright": "cli.js"
+ },
+ "engines": {
+ "node": ">=18"
+ }
+ },
"node_modules/@remix-run/router": {
"version": "1.23.2",
"resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.23.2.tgz",
@@ -3546,6 +3562,50 @@
"node": ">= 6"
}
},
+ "node_modules/playwright": {
+ "version": "1.59.1",
+ "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.59.1.tgz",
+ "integrity": "sha512-C8oWjPR3F81yljW9o5OxcWzfh6avkVwDD2VYdwIGqTkl+OGFISgypqzfu7dOe4QNLL2aqcWBmI3PMtLIK233lw==",
+ "dev": true,
+ "dependencies": {
+ "playwright-core": "1.59.1"
+ },
+ "bin": {
+ "playwright": "cli.js"
+ },
+ "engines": {
+ "node": ">=18"
+ },
+ "optionalDependencies": {
+ "fsevents": "2.3.2"
+ }
+ },
+ "node_modules/playwright-core": {
+ "version": "1.59.1",
+ "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.59.1.tgz",
+ "integrity": "sha512-HBV/RJg81z5BiiZ9yPzIiClYV/QMsDCKUyogwH9p3MCP6IYjUFu/MActgYAvK0oWyV9NlwM3GLBjADyWgydVyg==",
+ "dev": true,
+ "bin": {
+ "playwright-core": "cli.js"
+ },
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/playwright/node_modules/fsevents": {
+ "version": "2.3.2",
+ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
+ "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
+ "dev": true,
+ "hasInstallScript": true,
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
+ }
+ },
"node_modules/postcss": {
"version": "8.5.10",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.10.tgz",
diff --git a/web/package.json b/web/package.json
index 75f396b..d129a4c 100644
--- a/web/package.json
+++ b/web/package.json
@@ -23,6 +23,7 @@
"zustand": "^4.4.6"
},
"devDependencies": {
+ "@playwright/test": "^1.59.1",
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.14.0",
diff --git a/web/src/components/Layout.tsx b/web/src/components/Layout.tsx
index 3aeaa98..39280d2 100644
--- a/web/src/components/Layout.tsx
+++ b/web/src/components/Layout.tsx
@@ -164,7 +164,7 @@ export default function Layout() {
</div>
</header>
- <main className="flex-1 max-w-6xl mx-auto w-full px-5 py-7 animate-fade-in">
+ <main className="flex-1 max-w-6xl mx-auto w-full min-w-0 overflow-x-hidden px-5 py-7 animate-fade-in">
<Outlet />
</main>
diff --git a/web/src/pages/Dashboard.tsx b/web/src/pages/Dashboard.tsx
index ab48580..10ceb41 100644
--- a/web/src/pages/Dashboard.tsx
+++ b/web/src/pages/Dashboard.tsx
@@ -1,69 +1,155 @@
import { useState, useEffect } from 'react'
-import { format } from 'date-fns'
+import { format, startOfWeek, isSameDay, eachDayOfInterval, endOfWeek, subWeeks } from 'date-fns'
import {
- Dumbbell, Utensils, Flame, Plus,
- Apple, Beef, Zap, ArrowRight,
- CheckCircle2, AlertCircle, Play, Timer,
+ Dumbbell, Flame, ArrowRight, Beef,
+ AlertCircle, Play, Timer, TrendingUp, Scale, Activity,
} from 'lucide-react'
+import {
+ BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer, Cell,
+ LineChart, Line, PieChart, Pie, Legend,
+} from 'recharts'
import Loading from '../components/Loading'
import { workoutAPI, foodAPI, weightAPI, userAPI } from '../services/api'
import { useWorkoutSession } from '../stores/workoutSession'
+import { useAuthStore } from '../stores/auth'
import { useNavigate, Link } from 'react-router-dom'
import * as types from '../types'
+import { muscleColor } from '../utils/exerciseUtils'
const TODAY = new Date()
+function greeting() {
+ const h = TODAY.getHours()
+ if (h < 12) return 'Good morning'
+ if (h < 17) return 'Good afternoon'
+ return 'Good evening'
+}
+
+const calcVolume = (w: types.Workout) =>
+ w.exercises.reduce((s, ex) => s + ex.sets.reduce((ss, set) => ss + set.reps * set.weight, 0), 0)
+
+const DEFAULT_FOOD: types.DailyStats = {
+ date: format(TODAY, 'yyyy-MM-dd'),
+ total_calories: 0, total_protein: 0, total_carbs: 0, total_fat: 0, workout_count: 0,
+}
+const DEFAULT_SETTINGS: types.UserSettings = {
+ user_id: 0, weight_unit: 'lbs', calorie_target: 2000,
+ protein_target: 150, carb_target: 250, fat_target: 65,
+}
+
+// Hex colors for recharts (can't use Tailwind classes)
+const MUSCLE_HEX: Record<string, string> = {
+ chest: '#f87171',
+ back: '#60a5fa',
+ shoulders: '#818cf8',
+ biceps: '#f472b6',
+ triceps: '#a78bfa',
+ legs: '#34d399',
+ quadriceps: '#34d399',
+ hamstrings: '#6ee7b7',
+ glutes: '#86efac',
+ calves: '#4ade80',
+ core: '#fbbf24',
+ abs: '#fbbf24',
+ forearms: '#fb923c',
+ traps: '#94a3b8',
+ lats: '#38bdf8',
+ 'full body': '#e879f9',
+}
+const muscleHex = (m: string) => MUSCLE_HEX[m?.toLowerCase()] ?? '#6366f1'
+
+const MUSCLE_ROAST: Record<string, string> = {
+ chest: 'All chest, no legs. Classic bro.',
+ back: 'Built like a refrigerator. Respect.',
+ shoulders: "Can't fit through doorways. Good.",
+ biceps: 'Mirror selfies loading…',
+ triceps: 'Horseshoe gang. Handshakes must be terrifying.',
+ legs: "Actually training legs. You're a unicorn.",
+ quadriceps: "Quads for days. Jeans don't stand a chance.",
+ hamstrings: 'Posterior chain warrior. Deadlift god incoming.',
+ glutes: 'Glute guy/gal. We respect the commitment.',
+ calves: 'Calf king/queen. The rarest of all lifters.',
+ core: 'Beach season ready 365 days a year.',
+ abs: 'Six pack incoming. Or already here. Either way.',
+ forearms: 'Popeye called. He wants his arms back.',
+ traps: 'No neck, no problem.',
+ lats: 'Walking around like a cobra. Wings deployed.',
+ 'full body': 'A true all-rounder. Or you just did burpees.',
+}
+const muscleRoast = (m: string) => MUSCLE_ROAST[m?.toLowerCase()] ?? 'Mysterious training patterns. We respect it.'
+
+function MuscleSparkline({ values, color, isTop }: { values: number[], color: string, isTop: boolean }) {
+ if (values.length < 2) return <div className="w-14 h-6 flex-shrink-0" />
+ const max = Math.max(...values)
+ const min = Math.min(...values)
+ const range = max - min || 1
+ const W = 56, H = 24
+ const pts = values.map((v, i) => [
+ (i / (values.length - 1)) * W,
+ H - 4 - ((v - min) / range) * (H - 8),
+ ])
+ const d = pts.map((p, i) => `${i === 0 ? 'M' : 'L'}${p[0].toFixed(1)},${p[1].toFixed(1)}`).join(' ')
+ // Filled area path
+ const area = `${d} L${W},${H} L0,${H} Z`
+ return (
+ <svg width={W} height={H} className="flex-shrink-0 overflow-visible">
+ {isTop && (
+ <path d={area} fill={color} fillOpacity={0.12} />
+ )}
+ <path d={d} fill="none" stroke={color} strokeWidth={isTop ? 2 : 1.5}
+ strokeLinecap="round" strokeLinejoin="round"
+ strokeOpacity={isTop ? 1 : 0.6}
+ />
+ {/* End dot */}
+ <circle
+ cx={pts[pts.length - 1][0]}
+ cy={pts[pts.length - 1][1]}
+ r={isTop ? 2.5 : 1.5}
+ fill={color}
+ fillOpacity={isTop ? 1 : 0.7}
+ />
+ </svg>
+ )
+}
+
+const TOOLTIP_STYLE = {
+ background: 'var(--color-surface-raised, #1e1e2e)',
+ border: '1px solid var(--color-surface-border, #2d2d3a)',
+ borderRadius: 8,
+ fontSize: 11,
+ color: 'var(--color-tx-primary, #f1f5f9)',
+}
+
export default function Dashboard() {
const navigate = useNavigate()
const { session } = useWorkoutSession()
- const [stats, setStats] = useState<{
- weight?: types.WeightLog | null
- weightStats?: types.WeightStats
- food?: types.DailyStats
- workouts: types.Workout[]
- settings?: types.UserSettings
- }>({
- workouts: [],
- })
+ const { user } = useAuthStore()
+
+ const [workouts, setWorkouts] = useState<types.Workout[]>([])
+ const [food, setFood] = useState<types.DailyStats>(DEFAULT_FOOD)
+ const [weightLogs, setWeightLogs] = useState<types.WeightLog[]>([])
+ const [settings, setSettings] = useState<types.UserSettings>(DEFAULT_SETTINGS)
const [loading, setLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
useEffect(() => {
- const load = async () => {
- try {
- const [workouts, foodStats, weightStats, settings] = await Promise.all([
- workoutAPI.list({ limit: 10 }),
- foodAPI.stats(format(TODAY, 'yyyy-MM-dd')).catch(() => ({
- date: format(TODAY, 'yyyy-MM-dd'),
- total_calories: 0, total_protein: 0, total_carbs: 0, total_fat: 0, workout_count: 0
- })),
- weightAPI.stats().catch(() => ({ latest: 0, starting: 0, total_entries: 0 })),
- userAPI.getSettings().catch(() => ({
- user_id: 0, weight_unit: 'lbs' as const, calorie_target: 2000,
- protein_target: 150, carb_target: 250, fat_target: 65
- })),
- ])
-
- setStats({
- workouts: workouts || [],
- food: foodStats,
- weightStats,
- settings,
- weight: workouts?.[0] ? null : null, // Placeholder
- })
- } catch (err: any) {
- setError(err.message || 'Failed to load dashboard')
- } finally {
- setLoading(false)
- }
- }
-
- load()
+ Promise.all([
+ workoutAPI.list({ limit: 84 }), // 12 weeks × 7 days max
+ foodAPI.stats(format(TODAY, 'yyyy-MM-dd')).catch(() => DEFAULT_FOOD),
+ weightAPI.list({ limit: 14 }).catch(() => []),
+ userAPI.getSettings().catch(() => DEFAULT_SETTINGS),
+ ])
+ .then(([ws, fs, wl, s]) => {
+ setWorkouts(ws || [])
+ setFood(fs || DEFAULT_FOOD)
+ setWeightLogs(wl || [])
+ setSettings(s || DEFAULT_SETTINGS)
+ })
+ .catch(err => setError(err.message || 'Failed to load'))
+ .finally(() => setLoading(false))
}, [])
- if (loading) {
- return <Loading />
- }
+ if (loading) return <Loading />
if (error) {
return (
@@ -74,32 +160,103 @@ export default function Dashboard() {
)
}
- const lastWorkout = stats.workouts[0]
- const foodData = stats.food
- const settings = stats.settings!
- const calBurned = (foodData?.total_calories || 0) - settings.calorie_target
- const proteinPct = Math.min(100, ((foodData?.total_protein || 0) / settings.protein_target) * 100)
- const carbsPct = Math.min(100, ((foodData?.total_carbs || 0) / settings.carb_target) * 100)
- const fatPct = Math.min(100, ((foodData?.total_fat || 0) / settings.fat_target) * 100)
- const calPct = Math.min(100, ((foodData?.total_calories || 0) / settings.calorie_target) * 100)
+ // ── Derived data ────────────────────────────────
+ const weekStart = startOfWeek(TODAY, { weekStartsOn: 1 })
+ const weekWorkouts = workouts.filter(w => new Date(w.started_at) >= weekStart)
+ const lastWorkout = workouts[0] ?? null
+
+ // Volume chart: last 7 workouts oldest→newest
+ const chartData = workouts.slice(0, 7).reverse().map(w => ({
+ date: format(new Date(w.started_at), 'M/d'),
+ volume: Math.round(calcVolume(w)),
+ name: w.name,
+ }))
+
+ // Current week dots
+ const weekDays = eachDayOfInterval({ start: weekStart, end: endOfWeek(TODAY, { weekStartsOn: 1 }) })
+
+ // Heatmap: 12 weeks, Mon–Sun columns
+ const heatmapStart = startOfWeek(subWeeks(TODAY, 11), { weekStartsOn: 1 })
+ const heatmapEnd = endOfWeek(TODAY, { weekStartsOn: 1 })
+ const heatmapDays = eachDayOfInterval({ start: heatmapStart, end: heatmapEnd })
+ // map dateString → count
+ const workoutDayMap = new Map<string, number>()
+ workouts.forEach(w => {
+ const k = format(new Date(w.started_at), 'yyyy-MM-dd')
+ workoutDayMap.set(k, (workoutDayMap.get(k) || 0) + 1)
+ })
+ // chunk into weeks
+ const heatmapWeeks: Date[][] = []
+ for (let i = 0; i < heatmapDays.length; i += 7) {
+ heatmapWeeks.push(heatmapDays.slice(i, i + 7))
+ }
+ // month labels: show month name on first week that starts in that month
+ const monthLabels: (string | null)[] = heatmapWeeks.map((week, i) => {
+ const m = format(week[0], 'MMM')
+ if (i === 0) return m
+ const prev = format(heatmapWeeks[i - 1][0], 'MMM')
+ return m !== prev ? m : null
+ })
+
+ // Muscle group donut: sets per muscle across all fetched workouts
+ const muscleMap = new Map<string, number>()
+ workouts.forEach(w => {
+ w.exercises.forEach(ex => {
+ const mg = ex.exercise.muscle_group || 'other'
+ muscleMap.set(mg, (muscleMap.get(mg) || 0) + ex.sets.length)
+ })
+ })
+ const muscleData = Array.from(muscleMap.entries())
+ .sort((a, b) => b[1] - a[1])
+ .slice(0, 8) // top 8 groups
+ .map(([name, value]) => ({ name, value }))
+ const totalMuscSets = muscleData.reduce((s, d) => s + d.value, 0)
+
+ // Sparklines: sets per muscle per workout (last 10, oldest→newest)
+ const sparklineWorkouts = workouts.slice(0, 10).reverse()
+ const muscleSparklines = new Map<string, number[]>()
+ muscleData.forEach(({ name }) => {
+ muscleSparklines.set(name, sparklineWorkouts.map(w =>
+ w.exercises
+ .filter(ex => ex.exercise.muscle_group === name)
+ .reduce((s, ex) => s + ex.sets.length, 0)
+ ))
+ })
+ const topMuscle = muscleData[0]?.name ?? null
+
+ // Nutrition %
+ const calPct = Math.min(100, (food.total_calories / settings.calorie_target) * 100) || 0
+ const protPct = Math.min(100, (food.total_protein / settings.protein_target) * 100) || 0
+ const carbsPct = Math.min(100, (food.total_carbs / settings.carb_target) * 100) || 0
+ const fatPct = Math.min(100, (food.total_fat / settings.fat_target) * 100) || 0
+
+ // Weight sparkline
+ const sparkData = [...weightLogs].reverse().map(l => ({
+ date: format(new Date(l.logged_at), 'M/d'),
+ weight: l.weight,
+ }))
+
+ const username = user?.email?.split('@')[0] ?? 'there'
return (
<div className="space-y-4 animate-slide-up">
+
{/* ── Header ─────────────────────────────────── */}
- <div className="flex justify-between items-start">
- <div>
- <p className="text-tx-muted text-xs font-medium uppercase tracking-wider">
+ <div className="flex justify-between items-start gap-3">
+ <div className="min-w-0">
+ <p className="text-[11px] text-tx-muted uppercase tracking-wider font-medium">
{format(TODAY, 'EEEE, MMMM d')}
</p>
- <h1 className="font-display font-bold text-2xl text-tx-primary mt-0.5">
- Your progress today
+ <h1 className="font-display font-bold text-2xl text-tx-primary mt-0.5 truncate">
+ {greeting()}, {username}
</h1>
</div>
<button
- onClick={() => navigate(session ? '/workout/active' : '/workout/start')}
- className="btn-primary btn-sm"
+ onClick={() => navigate('/workout/start')}
+ className="btn-primary btn-sm flex-shrink-0"
>
- <Play className="w-3.5 h-3.5" /> {session ? 'Resume' : 'Start Workout'}
+ <Play className="w-3.5 h-3.5" />
+ {session ? 'Resume' : 'Start'}
</button>
</div>
@@ -118,160 +275,424 @@ export default function Dashboard() {
<p className="text-xs text-amber-400/70">{session.name} — tap to resume</p>
</div>
</div>
- <ArrowRight className="w-4 h-4 text-amber-400" />
+ <ArrowRight className="w-4 h-4 text-amber-400 flex-shrink-0" />
</Link>
)}
- {/* ── Top stat cards ─────────────────────────── */}
- <div className="grid grid-cols-2 lg:grid-cols-3 gap-3">
- {/* Calories */}
- <div className="card p-4">
- <div className="flex items-center justify-between mb-2">
- <span className="stat-label">Calories</span>
- <Flame className="w-3.5 h-3.5 text-tx-muted" />
+ {/* ── KPI strip ──────────────────────────────── */}
+ <div className="grid grid-cols-3 gap-2">
+ <div className="card p-3 flex flex-col gap-1.5">
+ <div className="flex items-center justify-between">
+ <span className="text-[10px] text-tx-muted uppercase tracking-wide font-medium">Week</span>
+ <Dumbbell className="w-3 h-3 text-tx-muted" />
</div>
- <div className="flex items-end gap-1">
- <span className="stat-value text-2xl">{Math.round(foodData?.total_calories || 0)}</span>
- <span className="text-tx-muted text-xs mb-0.5">/ {settings.calorie_target}</span>
+ <p className="text-xl font-bold text-tx-primary leading-none">{weekWorkouts.length}</p>
+ <p className="text-[10px] text-tx-muted">sessions</p>
+ </div>
+
+ <div className="card p-3 flex flex-col gap-1.5">
+ <div className="flex items-center justify-between">
+ <span className="text-[10px] text-tx-muted uppercase tracking-wide font-medium">Cals</span>
+ <Flame className="w-3 h-3 text-tx-muted" />
</div>
- <div className="progress-track mt-2">
+ <p className="text-xl font-bold text-tx-primary leading-none">
+ {Math.round(food.total_calories)}
+ </p>
+ <div className="progress-track">
<div className="progress-bar" style={{ width: `${calPct}%`, background: '#00b8d9' }} />
</div>
</div>
- {/* Protein */}
- <div className="card p-4">
- <div className="flex items-center justify-between mb-2">
- <span className="stat-label">Protein</span>
- <Beef className="w-3.5 h-3.5 text-tx-muted" />
+ <div className="card p-3 flex flex-col gap-1.5">
+ <div className="flex items-center justify-between">
+ <span className="text-[10px] text-tx-muted uppercase tracking-wide font-medium">Protein</span>
+ <Beef className="w-3 h-3 text-tx-muted" />
</div>
- <div className="flex items-end gap-1">
- <span className="stat-value text-2xl">{Math.round(foodData?.total_protein || 0)}</span>
- <span className="text-tx-muted text-xs mb-0.5">g</span>
- </div>
- <div className="progress-track mt-2">
- <div className="progress-bar" style={{ width: `${proteinPct}%`, background: '#f59e0b' }} />
+ <p className="text-xl font-bold text-tx-primary leading-none">
+ {Math.round(food.total_protein)}<span className="text-xs text-tx-muted font-normal">g</span>
+ </p>
+ <div className="progress-track">
+ <div className="progress-bar" style={{ width: `${protPct}%`, background: '#f59e0b' }} />
</div>
</div>
+ </div>
- {/* Workouts */}
- <div className="card p-4">
- <div className="flex items-center justify-between mb-2">
- <span className="stat-label">This Week</span>
- <Dumbbell className="w-3.5 h-3.5 text-tx-muted" />
- </div>
- <div className="flex items-end gap-1">
- <span className="stat-value text-2xl">{stats.workouts.length}</span>
- <span className="text-tx-muted text-xs mb-0.5">sessions</span>
+ {/* ── Volume trend chart ─────────────────────── */}
+ <div className="card p-4">
+ <div className="flex items-center justify-between mb-3">
+ <div className="flex items-center gap-2">
+ <TrendingUp className="w-4 h-4 text-brand-500" />
+ <h2 className="section-title">Volume Trend</h2>
</div>
+ <span className="text-xs text-tx-muted">
+ {chartData.length > 0 ? `last ${chartData.length} workouts` : ''}
+ </span>
</div>
+
+ {chartData.length === 0 ? (
+ <div className="flex flex-col items-center justify-center py-8 gap-2">
+ <Dumbbell className="w-6 h-6 text-tx-muted opacity-40" />
+ <p className="text-xs text-tx-muted">Log workouts to see trends</p>
+ </div>
+ ) : (
+ <>
+ <div className="w-full min-w-0">
+ <ResponsiveContainer width="100%" height={110}>
+ <BarChart data={chartData} barSize={18} barCategoryGap="30%">
+ <XAxis
+ dataKey="date"
+ tick={{ fontSize: 10, fill: 'var(--color-tx-muted, #9ca3af)' }}
+ axisLine={false}
+ tickLine={false}
+ />
+ <YAxis hide />
+ <Tooltip
+ contentStyle={TOOLTIP_STYLE}
+ formatter={(v: number) => [`${v.toLocaleString()} lbs`, 'Volume']}
+ labelFormatter={(label: string) => chartData.find(d => d.date === label)?.name || label}
+ cursor={{ fill: 'rgba(99,102,241,0.08)', radius: 4 }}
+ />
+ <Bar dataKey="volume" radius={[4, 4, 0, 0]}>
+ {chartData.map((_, i) => (
+ <Cell key={i} fill="#6366f1" fillOpacity={i === chartData.length - 1 ? 1 : 0.25} />
+ ))}
+ </Bar>
+ </BarChart>
+ </ResponsiveContainer>
+ </div>
+
+ {/* Current week day dots */}
+ <div className="flex items-center justify-between mt-3 px-1">
+ {weekDays.map((day, i) => {
+ const hasWorkout = workouts.some(w => isSameDay(new Date(w.started_at), day))
+ const isToday = isSameDay(day, TODAY)
+ const isFuture = day > TODAY
+ return (
+ <div key={i} className="flex flex-col items-center gap-1">
+ <span className={`text-[9px] font-medium ${isToday ? 'text-brand-400' : 'text-tx-muted'}`}>
+ {format(day, 'EEEEE')}
+ </span>
+ <div className={`w-2 h-2 rounded-full transition-colors ${
+ hasWorkout ? 'bg-brand-500' :
+ isToday ? 'bg-brand-500/30 ring-1 ring-brand-500/50' :
+ isFuture ? 'bg-surface-border/30' :
+ 'bg-surface-border'
+ }`} />
+ </div>
+ )
+ })}
+ </div>
+ </>
+ )}
</div>
- {/* ── Middle row ─────────────────────────────── */}
- <div className="grid lg:grid-cols-2 gap-4">
- {/* Today's nutrition */}
- <div className="card p-5">
- <div className="flex items-center justify-between mb-4">
- <h2 className="section-title">Today's Nutrition</h2>
- <button className="btn-ghost btn-sm">
- <Utensils className="w-3.5 h-3.5" /> Log
- </button>
+ {/* ── Frequency heatmap ──────────────────────── */}
+ <div className="card p-4">
+ <div className="flex items-center justify-between mb-3">
+ <div className="flex items-center gap-2">
+ <Activity className="w-4 h-4 text-brand-500" />
+ <h2 className="section-title">Consistency</h2>
</div>
+ <span className="text-xs text-tx-muted">12 weeks</span>
+ </div>
- <div className="space-y-3">
- <div className="flex items-center gap-3">
- <div className="w-7 h-7 rounded-md flex items-center justify-center flex-shrink-0 bg-blue-500/10 border border-blue-500/30">
- <Beef className="w-3.5 h-3.5 text-blue-400" />
- </div>
- <div className="flex-1">
- <div className="flex justify-between items-center mb-1">
- <span className="text-xs text-tx-secondary">Protein</span>
- <span className="text-xs font-semibold text-tx-primary">
- {Math.round(foodData?.total_protein || 0)}g / {settings.protein_target}g
- </span>
- </div>
- <div className="progress-track">
- <div className="progress-bar" style={{ width: `${proteinPct}%`, background: '#3b82f6' }} />
+ {workouts.length === 0 ? (
+ <div className="flex flex-col items-center justify-center py-6 gap-2">
+ <p className="text-xs text-tx-muted">Start working out to build your streak</p>
+ </div>
+ ) : (
+ <>
+ {/* CSS grid: 1 auto col (day labels) + N 1fr cols (weeks) */}
+ <div
+ className="w-full"
+ style={{ display: 'grid', gridTemplateColumns: `1.25rem repeat(${heatmapWeeks.length}, 1fr)`, gap: '2px' }}
+ >
+ {/* Row 0: spacer + month labels */}
+ <div />
+ {heatmapWeeks.map((_, i) => (
+ <div key={i} className="text-[9px] text-tx-muted font-medium truncate leading-none pb-0.5">
+ {monthLabels[i] ?? ''}
</div>
- </div>
+ ))}
+
+ {/* Rows 1–7: day label + cells */}
+ {(['M', '', 'W', '', 'F', '', 'S'] as const).map((lbl, dayIdx) => (
+ [
+ <div key={`lbl-${dayIdx}`} className="text-[9px] text-tx-muted/60 font-medium flex items-center leading-none">
+ {lbl}
+ </div>,
+ ...heatmapWeeks.map((week, wi) => {
+ const day = week[dayIdx]
+ const k = format(day, 'yyyy-MM-dd')
+ const count = workoutDayMap.get(k) || 0
+ const future = day > TODAY
+ return (
+ <div
+ key={`${wi}-${dayIdx}`}
+ title={`${format(day, 'MMM d')}${count > 0 ? ` · ${count} workout${count > 1 ? 's' : ''}` : ''}`}
+ className={`h-3 rounded-[2px] transition-colors ${
+ future ? 'bg-surface-muted/20' :
+ count === 0 ? 'bg-surface-muted/50' :
+ count === 1 ? 'bg-brand-500/50' :
+ 'bg-brand-500'
+ }`}
+ />
+ )
+ }),
+ ]
+ ))}
</div>
- <div className="flex items-center gap-3">
- <div className="w-7 h-7 rounded-md flex items-center justify-center flex-shrink-0 bg-amber-500/10 border border-amber-500/30">
- <Apple className="w-3.5 h-3.5 text-amber-400" />
- </div>
- <div className="flex-1">
- <div className="flex justify-between items-center mb-1">
- <span className="text-xs text-tx-secondary">Carbs</span>
- <span className="text-xs font-semibold text-tx-primary">
- {Math.round(foodData?.total_carbs || 0)}g / {settings.carb_target}g
- </span>
- </div>
- <div className="progress-track">
- <div className="progress-bar" style={{ width: `${carbsPct}%`, background: '#f59e0b' }} />
+ {/* Legend */}
+ <div className="flex items-center gap-1.5 mt-2 justify-end">
+ <span className="text-[9px] text-tx-muted">Less</span>
+ {['bg-surface-muted/50', 'bg-brand-500/30', 'bg-brand-500/60', 'bg-brand-500'].map((cls, i) => (
+ <div key={i} className={`w-3 h-3 rounded-[3px] ${cls}`} />
+ ))}
+ <span className="text-[9px] text-tx-muted">More</span>
+ </div>
+ </>
+ )}
+ </div>
+
+ {/* ── Last workout + Nutrition ───────────────── */}
+ <div className="grid lg:grid-cols-2 gap-4 min-w-0">
+
+ {lastWorkout ? (() => {
+ const totalSets = lastWorkout.exercises.reduce((s, ex) => s + ex.sets.length, 0)
+ const totalVolume = Math.round(calcVolume(lastWorkout))
+ const mins = Math.round(lastWorkout.duration / 60)
+ return (
+ <div className="card p-4 overflow-hidden min-w-0">
+ <div className="flex items-start justify-between gap-2 mb-3">
+ <div className="min-w-0">
+ <p className="text-sm font-semibold text-tx-primary truncate">{lastWorkout.name}</p>
+ <p className="text-xs text-tx-muted mt-0.5">
+ {format(new Date(lastWorkout.started_at), 'MMM d')}
+ {mins > 0 && ` · ${mins} min`}
+ {totalSets > 0 && ` · ${totalSets} sets`}
+ {totalVolume > 0 && ` · ${totalVolume.toLocaleString()} lbs`}
+ </p>
</div>
+ <Link to="/workouts" className="flex items-center gap-0.5 text-xs text-brand-400 hover:text-brand-300 flex-shrink-0 transition-colors">
+ All <ArrowRight className="w-3 h-3" />
+ </Link>
</div>
- </div>
- <div className="flex items-center gap-3">
- <div className="w-7 h-7 rounded-md flex items-center justify-center flex-shrink-0 bg-purple-500/10 border border-purple-500/30">
- <Zap className="w-3.5 h-3.5 text-purple-400" />
+ <div className="divide-y divide-surface-border/60">
+ {lastWorkout.exercises.slice(0, 4).map((ex) => {
+ const best = ex.sets.length > 0
+ ? ex.sets.reduce((b, s) => s.weight > b.weight ? s : b, ex.sets[0])
+ : null
+ return (
+ <div key={ex.id} className="flex items-center gap-2.5 py-2.5">
+ {ex.exercise.image_url ? (
+ <img
+ src={ex.exercise.image_url}
+ alt=""
+ loading="lazy"
+ className="w-8 h-8 rounded-lg object-cover flex-shrink-0 bg-surface-muted"
+ onError={e => { (e.target as HTMLImageElement).style.display = 'none' }}
+ />
+ ) : (
+ <div className="w-8 h-8 rounded-lg bg-brand-500/10 border border-brand-500/20 flex items-center justify-center flex-shrink-0">
+ <Dumbbell className="w-3.5 h-3.5 text-brand-500" />
+ </div>
+ )}
+ <div className="flex-1 min-w-0">
+ <p className="text-sm text-tx-secondary truncate">{ex.exercise.name}</p>
+ <span className={`text-[10px] px-1 py-0.5 rounded ${muscleColor(ex.exercise.muscle_group)}`}>
+ {ex.exercise.muscle_group}
+ </span>
+ </div>
+ {best && (
+ <span className="text-xs text-tx-muted tabular-nums flex-shrink-0">
+ {ex.sets.length}×{best.weight > 0 ? ` ${best.weight}lb` : ' BW'}
+ </span>
+ )}
+ </div>
+ )
+ })}
</div>
- <div className="flex-1">
+
+ {lastWorkout.exercises.length > 4 && (
+ <p className="text-xs text-tx-muted text-center pt-2">
+ +{lastWorkout.exercises.length - 4} more exercises
+ </p>
+ )}
+ </div>
+ )
+ })() : (
+ <div className="card p-4 flex flex-col items-center justify-center min-h-36 gap-2">
+ <Dumbbell className="w-7 h-7 text-tx-muted opacity-40" />
+ <p className="text-sm text-tx-muted">No workouts logged yet</p>
+ <button
+ onClick={() => navigate('/workout/start')}
+ className="text-xs text-brand-400 hover:text-brand-300 font-medium transition-colors mt-1"
+ >
+ Start your first workout →
+ </button>
+ </div>
+ )}
+
+ {/* Nutrition */}
+ <div className="card p-4 overflow-hidden min-w-0">
+ <div className="flex items-center justify-between mb-3">
+ <h2 className="section-title">Today's Nutrition</h2>
+ <Link to="/food" className="text-xs text-brand-400 hover:text-brand-300 transition-colors flex-shrink-0">
+ Log →
+ </Link>
+ </div>
+
+ {/* Calorie total */}
+ <div className="flex items-baseline gap-1.5 mb-3">
+ <span className="text-3xl font-bold text-tx-primary tabular-nums leading-none">
+ {Math.round(food.total_calories)}
+ </span>
+ <span className="text-xs text-tx-muted">/ {settings.calorie_target} kcal</span>
+ <div className="flex-1" />
+ <span className="text-xs text-tx-muted tabular-nums">{Math.round(calPct)}%</span>
+ </div>
+ <div className="progress-track mb-4">
+ <div className="progress-bar" style={{ width: `${calPct}%`, background: '#00b8d9' }} />
+ </div>
+
+ {/* Macros */}
+ <div className="space-y-2.5">
+ {[
+ { label: 'Protein', val: food.total_protein, target: settings.protein_target, pct: protPct, color: '#3b82f6' },
+ { label: 'Carbs', val: food.total_carbs, target: settings.carb_target, pct: carbsPct, color: '#f59e0b' },
+ { label: 'Fat', val: food.total_fat, target: settings.fat_target, pct: fatPct, color: '#8b5cf6' },
+ ].map(m => (
+ <div key={m.label}>
<div className="flex justify-between items-center mb-1">
- <span className="text-xs text-tx-secondary">Fat</span>
- <span className="text-xs font-semibold text-tx-primary">
- {Math.round(foodData?.total_fat || 0)}g / {settings.fat_target}g
+ <span className="text-xs text-tx-muted">{m.label}</span>
+ <span className="text-xs font-semibold text-tx-primary tabular-nums">
+ {Math.round(m.val)}g
+ <span className="text-tx-muted font-normal"> / {m.target}g</span>
</span>
</div>
<div className="progress-track">
- <div className="progress-bar" style={{ width: `${fatPct}%`, background: '#8b5cf6' }} />
+ <div className="progress-bar" style={{ width: `${m.pct}%`, background: m.color }} />
</div>
</div>
- </div>
+ ))}
</div>
</div>
+ </div>
- {/* Last workout */}
- {lastWorkout ? (
- <div className="card p-5">
- <div className="flex items-center justify-between mb-4">
- <h2 className="section-title">{lastWorkout.name}</h2>
- <span className="badge-dim">{format(lastWorkout.started_at, 'MMM d')}</span>
+ {/* ── Muscle group balance ────────────────────── */}
+ {muscleData.length > 0 && (
+ <div className="card p-4">
+ <div className="flex items-center justify-between mb-1">
+ <div className="flex items-center gap-2">
+ <Dumbbell className="w-4 h-4 text-brand-500" />
+ <h2 className="section-title">Muscle Balance</h2>
</div>
+ <span className="text-xs text-tx-muted">{workouts.length} workouts</span>
+ </div>
- <div className="space-y-0 divide-y divide-surface-border">
- {lastWorkout.exercises?.slice(0, 5).map((ex) => (
- <div key={ex.id} className="flex items-center justify-between py-2.5">
- <div className="flex items-center gap-2.5">
- <CheckCircle2 className="w-3.5 h-3.5 text-tx-muted flex-shrink-0" />
- <span className="text-sm text-tx-secondary">{ex.exercise.name}</span>
- </div>
- <span className="text-xs text-tx-muted">
- {ex.sets.length} sets
- </span>
- </div>
- ))}
+ {topMuscle && (
+ <p className="text-xs text-tx-muted mb-3 italic">
+ {muscleRoast(topMuscle)}
+ </p>
+ )}
+
+ <div className="flex flex-col sm:flex-row items-center gap-4">
+ {/* Donut */}
+ <div className="flex-shrink-0 flex items-center justify-center">
+ <ResponsiveContainer width={160} height={160}>
+ <PieChart>
+ <Pie
+ data={muscleData}
+ cx="50%"
+ cy="50%"
+ innerRadius={44}
+ outerRadius={68}
+ dataKey="value"
+ strokeWidth={0}
+ paddingAngle={2}
+ >
+ {muscleData.map((entry, i) => (
+ <Cell key={i} fill={muscleHex(entry.name)} fillOpacity={0.85} />
+ ))}
+ </Pie>
+ <Tooltip
+ contentStyle={TOOLTIP_STYLE}
+ formatter={(v: number, _: string, props: { payload?: { name: string } }) => [
+ `${v} sets (${Math.round((v / totalMuscSets) * 100)}%)`,
+ props.payload?.name ?? '',
+ ]}
+ />
+ </PieChart>
+ </ResponsiveContainer>
</div>
- <div className="mt-4 pt-3 border-t border-surface-border flex justify-between items-center">
- <span className="text-xs text-tx-muted">
- Duration: <span className="font-semibold">{lastWorkout.duration}s</span>
- </span>
- <a href="/workouts" className="flex items-center gap-1 text-xs font-medium text-brand-500 hover:text-brand-400">
- Full log <ArrowRight className="w-3 h-3" />
- </a>
+ {/* Legend — muscle name + sparkline + set count */}
+ <div className="flex-1 w-full min-w-0 space-y-2">
+ {muscleData.map((d) => {
+ const pct = Math.round((d.value / totalMuscSets) * 100)
+ const isTop = d.name === topMuscle
+ const values = muscleSparklines.get(d.name) ?? []
+ const color = muscleHex(d.name)
+ return (
+ <div key={d.name}>
+ <div className="flex items-center gap-2 mb-0.5">
+ <div className="w-2 h-2 rounded-full flex-shrink-0" style={{ background: color }} />
+ <span className={`text-xs capitalize flex-1 min-w-0 truncate ${isTop ? 'font-semibold text-tx-primary' : 'text-tx-secondary'}`}>
+ {d.name}
+ {isTop && <span className="ml-1 text-[9px] font-normal text-tx-muted uppercase tracking-wide">top</span>}
+ </span>
+ <MuscleSparkline values={values} color={color} isTop={isTop} />
+ <span className="text-xs text-tx-muted tabular-nums w-16 text-right flex-shrink-0">
+ {d.value} · {pct}%
+ </span>
+ </div>
+ <div className="progress-track">
+ <div className="progress-bar transition-all" style={{ width: `${pct}%`, background: color, opacity: isTop ? 1 : 0.6 }} />
+ </div>
+ </div>
+ )
+ })}
</div>
</div>
- ) : (
- <div className="card p-5 flex items-center justify-center min-h-48">
- <div className="text-center">
- <Dumbbell className="w-8 h-8 text-tx-muted mx-auto mb-2 opacity-50" />
- <p className="text-sm text-tx-muted">No workouts logged yet</p>
+ </div>
+ )}
+
+ {/* ── Weight sparkline ───────────────────────── */}
+ {weightLogs.length >= 2 && (
+ <div className="card p-4">
+ <div className="flex items-center justify-between mb-2">
+ <div className="flex items-center gap-2">
+ <Scale className="w-4 h-4 text-brand-500" />
+ <h2 className="section-title">Weight</h2>
+ </div>
+ <div className="text-right">
+ <p className="text-sm font-bold text-tx-primary">{weightLogs[0].weight} lbs</p>
+ {(() => {
+ const delta = weightLogs[0].weight - weightLogs[weightLogs.length - 1].weight
+ return (
+ <p className={`text-xs ${delta <= 0 ? 'text-brand-400' : 'text-tx-muted'}`}>
+ {delta <= 0 ? '↓' : '↑'}{Math.abs(delta).toFixed(1)} lbs
+ </p>
+ )
+ })()}
</div>
</div>
- )}
- </div>
+ <div className="w-full min-w-0">
+ <ResponsiveContainer width="100%" height={56}>
+ <LineChart data={sparkData}>
+ <Line dataKey="weight" dot={false} stroke="#6366f1" strokeWidth={2} type="monotone" />
+ <Tooltip
+ contentStyle={TOOLTIP_STYLE}
+ formatter={(v: number) => [`${v} lbs`, 'Weight']}
+ />
+ </LineChart>
+ </ResponsiveContainer>
+ </div>
+ </div>
+ )}
+
</div>
)
}