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: exercise notes, personal records, and history chart

Cawlummd818a7b1358a
diff --git a/backend/controllers/exercises.go b/backend/controllers/exercises.go
index d198bfb..c826c66 100644
--- a/backend/controllers/exercises.go
+++ b/backend/controllers/exercises.go
@@ -74,6 +74,87 @@ func GetExercise(c *gin.Context) {
utils.OK(c, e)
}
+func GetExercisePRs(c *gin.Context) {
+ userID := c.GetInt64("user_id")
+ exerciseID, err := strconv.ParseInt(c.Param("id"), 10, 64)
+ if err != nil {
+ utils.BadRequest(c, "invalid exercise id")
+ return
+ }
+
+ row := db.DB.QueryRow(`
+ SELECT s.weight, s.reps, w.started_at, w.id
+ FROM sets s
+ JOIN workout_exercises we ON we.id = s.workout_exercise_id
+ JOIN workouts w ON w.id = we.workout_id
+ WHERE w.user_id = ? AND we.exercise_id = ? AND s.is_warmup = 0 AND s.weight > 0
+ ORDER BY s.weight DESC, s.reps DESC
+ LIMIT 1
+ `, userID, exerciseID)
+
+ var weight float64
+ var reps int
+ var date string
+ var workoutID int64
+ if err := row.Scan(&weight, &reps, &date, &workoutID); err != nil {
+ utils.OK(c, nil)
+ return
+ }
+
+ estimated1RM := weight * (1 + float64(reps)/30.0)
+ utils.OK(c, gin.H{
+ "weight": weight,
+ "reps": reps,
+ "estimated_1rm": estimated1RM,
+ "date": date,
+ "workout_id": workoutID,
+ })
+}
+
+func GetExerciseHistory(c *gin.Context) {
+ userID := c.GetInt64("user_id")
+ exerciseID, err := strconv.ParseInt(c.Param("id"), 10, 64)
+ if err != nil {
+ utils.BadRequest(c, "invalid exercise id")
+ return
+ }
+
+ limit := 20
+ if l, err := strconv.Atoi(c.Query("limit")); err == nil && l > 0 && l <= 100 {
+ limit = l
+ }
+
+ rows, err := db.DB.Query(`
+ SELECT w.started_at, MAX(s.weight), SUM(s.reps * s.weight), COUNT(s.id)
+ FROM sets s
+ JOIN workout_exercises we ON we.id = s.workout_exercise_id
+ JOIN workouts w ON w.id = we.workout_id
+ WHERE w.user_id = ? AND we.exercise_id = ? AND s.is_warmup = 0
+ GROUP BY w.id
+ ORDER BY w.started_at DESC
+ LIMIT ?
+ `, userID, exerciseID, limit)
+ if err != nil {
+ utils.InternalError(c)
+ return
+ }
+ defer rows.Close()
+
+ type point struct {
+ Date string `json:"date"`
+ MaxWeight float64 `json:"max_weight"`
+ TotalVolume float64 `json:"total_volume"`
+ SetsCount int `json:"sets_count"`
+ }
+ history := []point{}
+ for rows.Next() {
+ var p point
+ rows.Scan(&p.Date, &p.MaxWeight, &p.TotalVolume, &p.SetsCount)
+ history = append(history, p)
+ }
+ utils.OK(c, history)
+}
+
// SyncExercises is an admin-only endpoint to re-pull from ExerciseDB.
func SyncExercises(c *gin.Context) {
if err := seed.SyncExercises(db.DB); err != nil {
diff --git a/backend/controllers/exercises_test.go b/backend/controllers/exercises_test.go
new file mode 100644
index 0000000..3adc178
--- /dev/null
+++ b/backend/controllers/exercises_test.go
@@ -0,0 +1,198 @@
+package controllers
+
+import (
+ "fmt"
+ "net/http"
+ "testing"
+
+ "github.com/Cawlumm/lyftr-backend/db"
+)
+
+// seedWorkoutWithSet creates a workout → workout_exercise → set for a given user/exercise.
+func seedWorkoutWithSet(t *testing.T, userID, exID int64, weight float64, reps int, isWarmup int) {
+ t.Helper()
+ var wID int64
+ row := db.DB.QueryRow(
+ `INSERT INTO workouts (user_id, name, duration, started_at) VALUES (?, 'Test Workout', 3600, CURRENT_TIMESTAMP) RETURNING id`,
+ userID,
+ )
+ if err := row.Scan(&wID); err != nil {
+ t.Fatalf("insert workout: %v", err)
+ }
+ var weID int64
+ row = db.DB.QueryRow(
+ `INSERT INTO workout_exercises (workout_id, exercise_id, order_index) VALUES (?, ?, 0) RETURNING id`,
+ wID, exID,
+ )
+ if err := row.Scan(&weID); err != nil {
+ t.Fatalf("insert workout_exercise: %v", err)
+ }
+ _, err := db.DB.Exec(
+ `INSERT INTO sets (workout_exercise_id, set_number, reps, weight, is_warmup) VALUES (?, 1, ?, ?, ?)`,
+ weID, reps, weight, isWarmup,
+ )
+ if err != nil {
+ t.Fatalf("insert set: %v", err)
+ }
+}
+
+func TestGetExercisePRs_noHistory(t *testing.T) {
+ setupTestDB(t)
+ uid := createTestUser(t)
+ exID := createTestExercise(t)
+
+ c, w := newContext(uid, http.MethodGet, fmt.Sprintf("/api/v1/exercises/%d/prs", exID), nil)
+ setParam(c, "id", fmt.Sprintf("%d", exID))
+ GetExercisePRs(c)
+
+ if w.Code != http.StatusOK {
+ t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
+ }
+ resp := decodeResponse(t, w)
+ if resp["data"] != nil {
+ t.Fatalf("expected nil data for exercise with no history, got %v", resp["data"])
+ }
+}
+
+func TestGetExercisePRs_returnsBestSet(t *testing.T) {
+ setupTestDB(t)
+ uid := createTestUser(t)
+ exID := createTestExercise(t)
+
+ seedWorkoutWithSet(t, uid, exID, 100.0, 5, 0)
+ seedWorkoutWithSet(t, uid, exID, 120.0, 3, 0) // heavier — should be PR
+ seedWorkoutWithSet(t, uid, exID, 80.0, 10, 0)
+
+ c, w := newContext(uid, http.MethodGet, fmt.Sprintf("/api/v1/exercises/%d/prs", exID), nil)
+ setParam(c, "id", fmt.Sprintf("%d", exID))
+ GetExercisePRs(c)
+
+ if w.Code != http.StatusOK {
+ t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
+ }
+ resp := decodeResponse(t, w)
+ data, ok := resp["data"].(map[string]any)
+ if !ok {
+ t.Fatalf("expected data object, got %T: %v", resp["data"], resp["data"])
+ }
+ if data["weight"].(float64) != 120.0 {
+ t.Fatalf("expected PR weight 120, got %v", data["weight"])
+ }
+ if data["reps"].(float64) != 3 {
+ t.Fatalf("expected PR reps 3, got %v", data["reps"])
+ }
+ if data["estimated_1rm"] == nil {
+ t.Fatal("expected estimated_1rm in response")
+ }
+}
+
+func TestGetExercisePRs_ignoresWarmup(t *testing.T) {
+ setupTestDB(t)
+ uid := createTestUser(t)
+ exID := createTestExercise(t)
+
+ seedWorkoutWithSet(t, uid, exID, 200.0, 1, 1) // warmup — should be excluded
+ seedWorkoutWithSet(t, uid, exID, 100.0, 5, 0)
+
+ c, w := newContext(uid, http.MethodGet, fmt.Sprintf("/api/v1/exercises/%d/prs", exID), nil)
+ setParam(c, "id", fmt.Sprintf("%d", exID))
+ GetExercisePRs(c)
+
+ if w.Code != http.StatusOK {
+ t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
+ }
+ resp := decodeResponse(t, w)
+ data := resp["data"].(map[string]any)
+ if data["weight"].(float64) != 100.0 {
+ t.Fatalf("expected PR weight 100 (warmup excluded), got %v", data["weight"])
+ }
+}
+
+func TestGetExercisePRs_isolatesUser(t *testing.T) {
+ setupTestDB(t)
+ uid1 := createTestUser(t)
+ uid2, err := db.DB.Exec(`INSERT INTO users (email, password_hash) VALUES ('[email protected]', 'x')`)
+ if err != nil {
+ t.Fatal(err)
+ }
+ other, _ := uid2.LastInsertId()
+ exID := createTestExercise(t)
+
+ seedWorkoutWithSet(t, int64(other), exID, 200.0, 5, 0) // other user's PR
+ seedWorkoutWithSet(t, uid1, exID, 100.0, 5, 0)
+
+ c, w := newContext(uid1, http.MethodGet, fmt.Sprintf("/api/v1/exercises/%d/prs", exID), nil)
+ setParam(c, "id", fmt.Sprintf("%d", exID))
+ GetExercisePRs(c)
+
+ resp := decodeResponse(t, w)
+ data := resp["data"].(map[string]any)
+ if data["weight"].(float64) != 100.0 {
+ t.Fatalf("expected user1 PR 100, got %v (should not see other user data)", data["weight"])
+ }
+}
+
+func TestGetExercisePRs_invalidID(t *testing.T) {
+ setupTestDB(t)
+ uid := createTestUser(t)
+
+ c, w := newContext(uid, http.MethodGet, "/api/v1/exercises/bad/prs", nil)
+ setParam(c, "id", "bad")
+ GetExercisePRs(c)
+
+ if w.Code != http.StatusBadRequest {
+ t.Fatalf("expected 400, got %d", w.Code)
+ }
+}
+
+func TestGetExerciseHistory_empty(t *testing.T) {
+ setupTestDB(t)
+ uid := createTestUser(t)
+ exID := createTestExercise(t)
+
+ c, w := newContext(uid, http.MethodGet, fmt.Sprintf("/api/v1/exercises/%d/history", exID), nil)
+ setParam(c, "id", fmt.Sprintf("%d", exID))
+ GetExerciseHistory(c)
+
+ if w.Code != http.StatusOK {
+ t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
+ }
+ resp := decodeResponse(t, w)
+ data, ok := resp["data"].([]any)
+ if !ok {
+ t.Fatalf("expected data array, got %T", resp["data"])
+ }
+ if len(data) != 0 {
+ t.Fatalf("expected empty history, got %d items", len(data))
+ }
+}
+
+func TestGetExerciseHistory_returnsSessionsGrouped(t *testing.T) {
+ setupTestDB(t)
+ uid := createTestUser(t)
+ exID := createTestExercise(t)
+
+ seedWorkoutWithSet(t, uid, exID, 100.0, 8, 0)
+ seedWorkoutWithSet(t, uid, exID, 110.0, 6, 0)
+ seedWorkoutWithSet(t, uid, exID, 120.0, 4, 0)
+
+ c, w := newContext(uid, http.MethodGet, fmt.Sprintf("/api/v1/exercises/%d/history", exID), nil)
+ setParam(c, "id", fmt.Sprintf("%d", exID))
+ GetExerciseHistory(c)
+
+ if w.Code != http.StatusOK {
+ t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
+ }
+ resp := decodeResponse(t, w)
+ data, ok := resp["data"].([]any)
+ if !ok {
+ t.Fatalf("expected data array, got %T", resp["data"])
+ }
+ if len(data) != 3 {
+ t.Fatalf("expected 3 sessions, got %d", len(data))
+ }
+ first := data[0].(map[string]any)
+ if first["max_weight"] == nil || first["total_volume"] == nil || first["sets_count"] == nil {
+ t.Fatalf("missing fields in history point: %v", first)
+ }
+}
diff --git a/backend/routes/routes.go b/backend/routes/routes.go
index 29c7f27..eb6990a 100644
--- a/backend/routes/routes.go
+++ b/backend/routes/routes.go
@@ -66,6 +66,8 @@ func Setup(r *gin.Engine) {
// Exercises (read-only for users)
protected.GET("exercises", controllers.ListExercises)
protected.GET("exercises/:id", controllers.GetExercise)
+ protected.GET("exercises/:id/prs", controllers.GetExercisePRs)
+ protected.GET("exercises/:id/history", controllers.GetExerciseHistory)
// Active session
protected.GET("active-session", controllers.GetActiveSession)
diff --git a/web/e2e/exercises.spec.ts b/web/e2e/exercises.spec.ts
new file mode 100644
index 0000000..c5c6d77
--- /dev/null
+++ b/web/e2e/exercises.spec.ts
@@ -0,0 +1,94 @@
+import { test, expect } from '@playwright/test'
+
+const API = 'http://localhost:3000/api/v1'
+
+let authToken: string
+let exerciseId: number
+let workoutId: number
+
+test.describe('Exercise Detail', () => {
+ test.beforeAll(async ({ request }) => {
+ const res = await request.post(`${API}/auth/login`, {
+ data: { email: '[email protected]', password: 'password123' }
+ })
+ authToken = (await res.json()).data.token
+
+ // Find a real exercise ID to use
+ const exRes = await request.get(`${API}/exercises?limit=1`, {
+ headers: { Authorization: `Bearer ${authToken}` }
+ })
+ const exBody = await exRes.json()
+ exerciseId = exBody.data[0].id
+
+ // Seed a workout with that exercise so PR/history data exists
+ const w = await request.post(`${API}/workouts`, {
+ headers: { Authorization: `Bearer ${authToken}` },
+ data: {
+ name: 'E2E Exercise History Seed',
+ duration: 1800,
+ started_at: new Date().toISOString(),
+ exercises: [{
+ exercise_id: exerciseId,
+ notes: '',
+ sets: [
+ { set_number: 1, reps: 5, weight: 100 },
+ { set_number: 2, reps: 5, weight: 100 },
+ ]
+ }]
+ }
+ })
+ workoutId = (await w.json()).data.id
+ })
+
+ test.afterAll(async ({ request }) => {
+ if (workoutId) {
+ await request.delete(`${API}/workouts/${workoutId}`, {
+ headers: { Authorization: `Bearer ${authToken}` }
+ })
+ }
+ })
+
+ test('exercise detail page loads', async ({ page }) => {
+ await page.goto(`/exercises/${exerciseId}`)
+ await expect(page.getByRole('heading')).toBeVisible()
+ })
+
+ test('PR API returns data after seeded workout', async ({ request }) => {
+ const res = await request.get(`${API}/exercises/${exerciseId}/prs`, {
+ headers: { Authorization: `Bearer ${authToken}` }
+ })
+ expect(res.status()).toBe(200)
+ const body = await res.json()
+ expect(body.data).not.toBeNull()
+ expect(body.data.weight).toBeGreaterThan(0)
+ expect(body.data.estimated_1rm).toBeGreaterThan(0)
+ })
+
+ test('history API returns sessions', async ({ request }) => {
+ const res = await request.get(`${API}/exercises/${exerciseId}/history`, {
+ headers: { Authorization: `Bearer ${authToken}` }
+ })
+ expect(res.status()).toBe(200)
+ const body = await res.json()
+ expect(Array.isArray(body.data)).toBe(true)
+ expect(body.data.length).toBeGreaterThan(0)
+ const point = body.data[0]
+ expect(point.max_weight).toBeGreaterThan(0)
+ expect(point.sets_count).toBeGreaterThan(0)
+ })
+
+ test('exercise detail shows PR card when history exists', async ({ page }) => {
+ await page.goto(`/exercises/${exerciseId}`)
+ await expect(page.getByText('Your Best')).toBeVisible({ timeout: 5000 })
+ })
+
+ test('exercise detail shows progression chart when history exists', async ({ page }) => {
+ await page.goto(`/exercises/${exerciseId}`)
+ await expect(page.getByText('Weight Progression')).toBeVisible({ timeout: 5000 })
+ })
+
+ test('muscle diagram renders', async ({ page }) => {
+ await page.goto(`/exercises/${exerciseId}`)
+ await expect(page.getByText('Muscles Worked')).toBeVisible()
+ })
+})
diff --git a/web/src/pages/ActiveWorkout.tsx b/web/src/pages/ActiveWorkout.tsx
index f7eed59..8b4257d 100644
--- a/web/src/pages/ActiveWorkout.tsx
+++ b/web/src/pages/ActiveWorkout.tsx
@@ -11,6 +11,41 @@ import { workoutAPI } from '../services/api'
import * as types from '../types'
import { muscleColor } from '../utils/exerciseUtils'
+function ExerciseNotes({ exIdx, notes, onSave }: { exIdx: number; notes: string; onSave: (i: number, v: string) => void }) {
+ const [editing, setEditing] = useState(false)
+ const [val, setVal] = useState(notes)
+
+ const commit = () => { onSave(exIdx, val); setEditing(false) }
+
+ if (editing) {
+ return (
+ <div className="px-4 pb-2">
+ <input
+ autoFocus
+ type="text"
+ value={val}
+ onChange={e => setVal(e.target.value)}
+ onBlur={commit}
+ onKeyDown={e => { if (e.key === 'Enter') commit(); if (e.key === 'Escape') { setVal(notes); setEditing(false) } }}
+ placeholder="Add a note…"
+ className="input text-sm w-full"
+ />
+ </div>
+ )
+ }
+
+ return (
+ <div className="px-4 pb-2">
+ <button
+ onClick={() => { setVal(notes); setEditing(true) }}
+ className="text-xs text-tx-muted hover:text-tx-secondary transition-colors"
+ >
+ {notes ? <span className="italic">{notes}</span> : <span className="opacity-50">+ Add note</span>}
+ </button>
+ </div>
+ )
+}
+
function formatElapsed(seconds: number) {
const h = Math.floor(seconds / 3600)
const m = Math.floor((seconds % 3600) / 60)
@@ -21,7 +56,7 @@ function formatElapsed(seconds: number) {
export default function ActiveWorkout() {
const navigate = useNavigate()
- const { session, updateSet, completeSet, addSet, removeSet, removeExercise, buildPayload, cancelSession } =
+ const { session, updateSet, updateExerciseNotes, completeSet, addSet, removeSet, removeExercise, buildPayload, cancelSession } =
useWorkoutSession()
const { settings } = useSettingsStore()
const wUnit = weightShort(settings.weight_unit)
@@ -259,6 +294,9 @@ export default function ActiveWorkout() {
)}
</div>
+ {/* Notes */}
+ <ExerciseNotes exIdx={exIdx} notes={ex.notes} onSave={updateExerciseNotes} />
+
{/* Sets */}
<div className="px-3 pb-3 space-y-2">
{/* Column labels */}
diff --git a/web/src/pages/ExerciseDetail.tsx b/web/src/pages/ExerciseDetail.tsx
index f6e522a..6f591f4 100644
--- a/web/src/pages/ExerciseDetail.tsx
+++ b/web/src/pages/ExerciseDetail.tsx
@@ -1,9 +1,12 @@
import { useState, useEffect } from 'react'
import { useNavigate, useParams } from 'react-router-dom'
-import { ArrowLeft, Dumbbell } from 'lucide-react'
+import { ArrowLeft, Dumbbell, Trophy } from 'lucide-react'
+import { format } from 'date-fns'
+import { LineChart, Line, XAxis, YAxis, Tooltip, ResponsiveContainer } from 'recharts'
import Model, { IExerciseData } from 'react-body-highlighter'
import { exerciseAPI } from '../services/api'
import { useWorkoutSession } from '../stores/workoutSession'
+import { useSettingsStore, weightShort } from '../stores/settings'
import { useTheme } from '../hooks/useTheme'
import * as types from '../types'
import { muscleColor, muscleColorBordered, EQUIPMENT_LABEL, muscleToBodySlugs } from '../utils/exerciseUtils'
@@ -29,7 +32,11 @@ export default function ExerciseDetail() {
const navigate = useNavigate()
const { session } = useWorkoutSession()
const { isDark } = useTheme()
+ const { settings } = useSettingsStore()
+ const wUnit = weightShort(settings.weight_unit)
const [exercise, setExercise] = useState<types.Exercise | null>(null)
+ const [pr, setPR] = useState<types.PersonalRecord | null>(null)
+ const [history, setHistory] = useState<types.ExerciseHistoryPoint[]>([])
const [imgFailed, setImgFailed] = useState(false)
const [loading, setLoading] = useState(true)
@@ -37,17 +44,22 @@ export default function ExerciseDetail() {
const id = Number(exerciseId)
if (!id) { navigate(-1); return }
- // Find in session first (no API call needed)
const fromSession = session?.exercises.find(e => e.exercise_id === id)?.exercise
- if (fromSession) {
- setExercise(fromSession)
- setLoading(false)
- return
- }
-
- // Fall back to API
- exerciseAPI.get(id)
- .then(ex => setExercise(ex))
+
+ const exercisePromise = fromSession
+ ? Promise.resolve(fromSession)
+ : exerciseAPI.get(id)
+
+ Promise.all([
+ exercisePromise,
+ exerciseAPI.getPRs(id).catch(() => null),
+ exerciseAPI.getHistory(id, 15).catch(() => []),
+ ])
+ .then(([ex, prData, histData]) => {
+ setExercise(ex)
+ setPR(prData)
+ setHistory(histData || [])
+ })
.catch(() => navigate(-1))
.finally(() => setLoading(false))
}, [exerciseId])
@@ -166,6 +178,66 @@ export default function ExerciseDetail() {
</div>
)}
+ {/* Personal Record */}
+ {pr && pr.weight > 0 && (
+ <div className="card p-4">
+ <div className="flex items-center gap-2 mb-3">
+ <Trophy className="w-4 h-4 text-warning-400" />
+ <p className="text-xs font-semibold text-tx-muted uppercase tracking-wider">Your Best</p>
+ </div>
+ <div className="flex items-end gap-2">
+ <span className="text-2xl font-bold text-tx-primary tabular-nums">{pr.weight}</span>
+ <span className="text-sm text-tx-muted mb-0.5">{wUnit} × {pr.reps} reps</span>
+ </div>
+ <p className="text-xs text-tx-muted mt-1">
+ Est. 1RM: {Math.round(pr.estimated_1rm)} {wUnit} · {format(new Date(pr.date), 'MMM d, yyyy')}
+ </p>
+ </div>
+ )}
+
+ {/* History chart */}
+ {history.length >= 2 && (() => {
+ const chartData = [...history].reverse().map(h => ({
+ date: format(new Date(h.date), 'M/d'),
+ weight: Math.round(h.max_weight * 10) / 10,
+ }))
+ return (
+ <div className="card p-4">
+ <p className="text-xs font-semibold text-tx-muted uppercase tracking-wider mb-3">
+ Weight Progression
+ </p>
+ <ResponsiveContainer width="100%" height={110}>
+ <LineChart data={chartData}>
+ <XAxis
+ dataKey="date"
+ tick={{ fontSize: 10, fill: 'var(--color-tx-muted)' }}
+ axisLine={false}
+ tickLine={false}
+ />
+ <YAxis hide domain={['auto', 'auto']} />
+ <Tooltip
+ contentStyle={{
+ background: 'var(--color-surface-raised)',
+ border: '1px solid var(--color-surface-border)',
+ borderRadius: 8,
+ fontSize: 11,
+ }}
+ formatter={(v: number) => [`${v} ${wUnit}`, 'Max weight']}
+ />
+ <Line
+ type="monotone"
+ dataKey="weight"
+ stroke="#0891b2"
+ strokeWidth={2}
+ dot={{ r: 3, fill: '#0891b2' }}
+ activeDot={{ r: 4 }}
+ />
+ </LineChart>
+ </ResponsiveContainer>
+ </div>
+ )
+ })()}
+
{/* Instructions */}
{descLines.length > 0 && (
<div className="card p-4">
diff --git a/web/src/services/api.ts b/web/src/services/api.ts
index d03b23c..8e7a346 100644
--- a/web/src/services/api.ts
+++ b/web/src/services/api.ts
@@ -88,6 +88,8 @@ export const exerciseAPI = {
return _exerciseCachePromise
},
get: (id: number) => api.get<{ data: types.Exercise }>(`/exercises/${id}`).then(res => unwrap(res)),
+ getPRs: (id: number) => api.get<{ data: types.PersonalRecord }>(`/exercises/${id}/prs`).then(res => unwrap(res)),
+ getHistory: (id: number, limit = 20) => api.get<{ data: types.ExerciseHistoryPoint[] }>(`/exercises/${id}/history`, { params: { limit } }).then(res => unwrap(res)),
clearCache: () => { _exerciseCache = null; _exerciseCachePromise = null },
seedStatus: () => api.get<{ data: { count: number; in_progress: boolean } }>('/admin/seed-status').then(res => unwrap(res)),
sync: () => api.post<{ data: { synced: boolean; total: number } }>('/admin/sync-exercises').then(res => unwrap(res)),
diff --git a/web/src/stores/workoutSession.ts b/web/src/stores/workoutSession.ts
index 2c1b6c0..8983576 100644
--- a/web/src/stores/workoutSession.ts
+++ b/web/src/stores/workoutSession.ts
@@ -25,6 +25,7 @@ interface WorkoutSessionStore {
startSession: (name: string, exercises: types.ActiveSessionExercise[], programId?: number) => void
updateSet: (exIdx: number, setIdx: number, field: 'actual_reps' | 'actual_weight', val: number) => void
completeSet: (exIdx: number, setIdx: number) => void
+ updateExerciseNotes: (exIdx: number, notes: string) => void
addSet: (exIdx: number) => void
removeSet: (exIdx: number, setIdx: number) => void
addExercise: (ex: types.ActiveSessionExercise) => void
@@ -75,6 +76,15 @@ export const useWorkoutSession = create<WorkoutSessionStore>((set, get) => ({
set({ session: updated })
},
+ updateExerciseNotes: (exIdx, notes) => {
+ const session = get().session
+ if (!session) return
+ const exercises = session.exercises.map((ex, i) => i !== exIdx ? ex : { ...ex, notes })
+ const updated = { ...session, exercises }
+ saveLocal(updated)
+ set({ session: updated })
+ },
+
addSet: (exIdx) => {
const session = get().session
if (!session) return
diff --git a/web/src/types.ts b/web/src/types.ts
index 40c0324..ab64305 100644
--- a/web/src/types.ts
+++ b/web/src/types.ts
@@ -152,6 +152,21 @@ export interface AuthResponse {
user: User
}
+export interface PersonalRecord {
+ weight: number
+ reps: number
+ estimated_1rm: number
+ date: string
+ workout_id: number
+}
+
+export interface ExerciseHistoryPoint {
+ date: string
+ max_weight: number
+ total_volume: number
+ sets_count: number
+}
+
export interface LoginRequest {
email: string
password: string