Minor History fix

This commit is contained in:
AG
2025-11-20 23:57:00 +02:00
parent e6a3a5b0ff
commit ada10d52e8
3 changed files with 312 additions and 305 deletions

10
App.tsx
View File

@@ -94,13 +94,19 @@ function App() {
setCurrentTab('TRACK'); setCurrentTab('TRACK');
}; };
const handleEndSession = () => { const handleEndSession = async () => {
if (activeSession && currentUser) { if (activeSession && currentUser) {
const finishedSession = { ...activeSession, endTime: Date.now() }; const finishedSession = { ...activeSession, endTime: Date.now() };
saveSession(currentUser.id, finishedSession); await saveSession(currentUser.id, finishedSession);
setSessions(prev => [finishedSession, ...prev]); setSessions(prev => [finishedSession, ...prev]);
setActiveSession(null); setActiveSession(null);
setActivePlan(null); setActivePlan(null);
// Refetch user to get updated weight
const res = await getMe();
if (res.success && res.user) {
setCurrentUser(res.user);
}
} }
}; };

View File

@@ -135,7 +135,7 @@ const History: React.FC<HistoryProps> = ({ sessions, onUpdateSession, onDeleteSe
else if (bestSet.type === ExerciseType.STRENGTH) detail = `${t('upto', lang)} ${Math.max(...sets.map(s => s.weight || 0))}kg`; else if (bestSet.type === ExerciseType.STRENGTH) detail = `${t('upto', lang)} ${Math.max(...sets.map(s => s.weight || 0))}kg`;
return ( return (
<div key={exName} className="flex justify-between text-sm items-center"> <div key={`${session.id}-${exName}`} className="flex justify-between text-sm items-center">
<span className="text-on-surface">{exName}</span> <span className="text-on-surface">{exName}</span>
<span className="text-on-surface-variant flex gap-2 items-center"> <span className="text-on-surface-variant flex gap-2 items-center">
{detail && <span className="text-[10px] bg-surface-container-high px-2 py-0.5 rounded text-on-surface-variant">{detail}</span>} {detail && <span className="text-[10px] bg-surface-container-high px-2 py-0.5 rounded text-on-surface-variant">{detail}</span>}
@@ -167,7 +167,8 @@ const History: React.FC<HistoryProps> = ({ sessions, onUpdateSession, onDeleteSe
</div> </div>
</div> </div>
</div> </div>
)})} )
})}
</div> </div>
{/* DELETE CONFIRMATION DIALOG (MD3) */} {/* DELETE CONFIRMATION DIALOG (MD3) */}

View File

@@ -18,6 +18,24 @@ interface TrackerProps {
lang: Language; lang: Language;
} }
const FilledInput = ({ label, value, onChange, type = "number", icon, autoFocus, step }: any) => (
<div className="relative group bg-surface-container-high rounded-t-lg border-b border-outline-variant hover:bg-white/5 focus-within:border-primary transition-colors">
<label className="absolute top-2 left-4 text-[10px] font-medium text-on-surface-variant flex items-center gap-1">
{icon} {label}
</label>
<input
type={type}
step={step}
inputMode="decimal"
autoFocus={autoFocus}
className="w-full pt-6 pb-2 px-4 bg-transparent text-2xl text-on-surface focus:outline-none placeholder-transparent"
placeholder="0"
value={value}
onChange={onChange}
/>
</div>
);
const Tracker: React.FC<TrackerProps> = ({ userId, userWeight, activeSession, activePlan, onSessionStart, onSessionEnd, onSetAdded, onRemoveSet, lang }) => { const Tracker: React.FC<TrackerProps> = ({ userId, userWeight, activeSession, activePlan, onSessionStart, onSessionEnd, onSetAdded, onRemoveSet, lang }) => {
const [exercises, setExercises] = useState<ExerciseDef[]>([]); const [exercises, setExercises] = useState<ExerciseDef[]>([]);
const [plans, setPlans] = useState<WorkoutPlan[]>([]); const [plans, setPlans] = useState<WorkoutPlan[]>([]);
@@ -107,11 +125,11 @@ const Tracker: React.FC<TrackerProps> = ({ userId, userWeight, activeSession, ac
setLastSet(set); setLastSet(set);
if (set) { if (set) {
if (set.weight !== undefined) setWeight(set.weight.toString()); if (set.weight != null) setWeight(set.weight.toString());
if (set.reps !== undefined) setReps(set.reps.toString()); if (set.reps != null) setReps(set.reps.toString());
if (set.durationSeconds !== undefined) setDuration(set.durationSeconds.toString()); if (set.durationSeconds != null) setDuration(set.durationSeconds.toString());
if (set.distanceMeters !== undefined) setDistance(set.distanceMeters.toString()); if (set.distanceMeters != null) setDistance(set.distanceMeters.toString());
if (set.height !== undefined) setHeight(set.height.toString()); if (set.height != null) setHeight(set.height.toString());
} else { } else {
setWeight(''); setReps(''); setDuration(''); setDistance(''); setHeight(''); setWeight(''); setReps(''); setDuration(''); setDistance(''); setHeight('');
} }
@@ -189,24 +207,6 @@ const Tracker: React.FC<TrackerProps> = ({ userId, userWeight, activeSession, ac
const isPlanFinished = activePlan && currentStepIndex >= activePlan.steps.length; const isPlanFinished = activePlan && currentStepIndex >= activePlan.steps.length;
const FilledInput = ({ label, value, onChange, type = "number", icon, autoFocus, step }: any) => (
<div className="relative group bg-surface-container-high rounded-t-lg border-b border-outline-variant hover:bg-white/5 focus-within:border-primary transition-colors">
<label className="absolute top-2 left-4 text-[10px] font-medium text-on-surface-variant flex items-center gap-1">
{icon} {label}
</label>
<input
type={type}
step={step}
inputMode="decimal"
autoFocus={autoFocus}
className="w-full pt-6 pb-2 px-4 bg-transparent text-2xl text-on-surface focus:outline-none placeholder-transparent"
placeholder="0"
value={value}
onChange={onChange}
/>
</div>
);
const exerciseTypeLabels: Record<ExerciseType, string> = { const exerciseTypeLabels: Record<ExerciseType, string> = {
[ExerciseType.STRENGTH]: t('type_strength', lang), [ExerciseType.STRENGTH]: t('type_strength', lang),
[ExerciseType.BODYWEIGHT]: t('type_bodyweight', lang), [ExerciseType.BODYWEIGHT]: t('type_bodyweight', lang),