import { useState } from 'react'; import { formatPace } from '../utils/weekUtils'; import './RunLog.css'; const INJURY_LOCS = [ { key: 'left_knee', label: 'L Knee' }, { key: 'right_knee', label: 'R Knee' }, ]; function RunLog({ runs, onEditRun, onDeleteRun }) { const [editingId, setEditingId] = useState(null); const [editForm, setEditForm] = useState({}); if (!runs || runs.length === 0) { return (
No runs logged yet. Add your first run above.
| Date | Distance | Time | Pace | RPE | Load | Pain (D/A) | Notes | |
|---|---|---|---|---|---|---|---|---|
| setEditForm({ ...editForm, date: e.target.value })} onKeyDown={handleKeyDown} /> | setEditForm({ ...editForm, distance_km: e.target.value })} onKeyDown={handleKeyDown} /> | setEditForm({ ...editForm, time_minutes: e.target.value })} onKeyDown={handleKeyDown} /> | {formatPace(parseFloat(editForm.time_minutes), parseFloat(editForm.distance_km))}/km | setEditForm({ ...editForm, rpe: e.target.value })} onKeyDown={handleKeyDown} /> | {(parseFloat(editForm.distance_km || 0) * parseInt(editForm.rpe || 0, 10)).toFixed(0)} |
{INJURY_LOCS.map((loc) => {
const injury = editForm.injuries?.[loc.key];
const enabled = !!injury?.enabled;
return (
{enabled && (
);
})}
updateEditInjury(loc.key, 'during', e.target.value)}
onKeyDown={handleKeyDown}
placeholder="D"
className="pain-input"
/>
/
updateEditInjury(loc.key, 'after', e.target.value)}
onKeyDown={handleKeyDown}
placeholder="A"
className="pain-input"
/>
)}
|
setEditForm({ ...editForm, notes: e.target.value })} onKeyDown={handleKeyDown} placeholder="Notes..." /> | |
| {formatDate(run.date)} | {run.distance_km.toFixed(1)} km | {run.time_minutes} min | {formatPace(run.time_minutes, run.distance_km)}/km | {run.rpe}/10 | {(run.distance_km * run.rpe).toFixed(0)} |
{(() => {
const entries = INJURY_LOCS.filter((loc) => {
// Support new per-location fields and legacy single-location format
const hasNew = run[`${loc.key}_during`] != null || run[`${loc.key}_after`] != null;
const hasLegacy = run.injury_location === loc.key;
return hasNew || hasLegacy;
});
if (entries.length === 0) return '–';
return entries.map((loc) => {
const d = run[`${loc.key}_during`] ?? (run.injury_location === loc.key ? run.pain_during : null);
const a = run[`${loc.key}_after`] ?? (run.injury_location === loc.key ? run.pain_after : null);
return {loc.label}: {d ?? '–'}/{a ?? '–'} ;
});
})()}
|
{run.notes || ''} |