Workout finishing fixed

This commit is contained in:
AG
2025-11-20 23:24:51 +02:00
parent 84417847fd
commit 12a79ae642
4 changed files with 31 additions and 28 deletions

View File

@@ -8,16 +8,17 @@ import { t } from '../services/i18n';
interface TrackerProps {
userId: string;
userWeight?: number;
activeSession: WorkoutSession | null;
activePlan: WorkoutPlan | null;
onSessionStart: (plan?: WorkoutPlan) => void;
onSessionStart: (plan?: WorkoutPlan, startWeight?: number) => void;
onSessionEnd: () => void;
onSetAdded: (set: WorkoutSet) => void;
onRemoveSet: (setId: string) => void;
lang: Language;
}
const Tracker: React.FC<TrackerProps> = ({ userId, 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 [plans, setPlans] = useState<WorkoutPlan[]>([]);
const [selectedExercise, setSelectedExercise] = useState<ExerciseDef | null>(null);
@@ -35,7 +36,7 @@ const Tracker: React.FC<TrackerProps> = ({ userId, activeSession, activePlan, on
const [bwPercentage, setBwPercentage] = useState<string>('100');
// User Weight State
const [userBodyWeight, setUserBodyWeight] = useState<string>('70');
const [userBodyWeight, setUserBodyWeight] = useState<string>(userWeight ? userWeight.toString() : '70');
// Create Exercise State
const [isCreating, setIsCreating] = useState(false);
@@ -57,17 +58,12 @@ const Tracker: React.FC<TrackerProps> = ({ userId, activeSession, activePlan, on
if (activeSession?.userBodyWeight) {
setUserBodyWeight(activeSession.userBodyWeight.toString());
} else {
// Profile fetch needs to be async too if we updated it,
// but for now let's assume we can get it or it's passed.
// Actually getCurrentUserProfile returns undefined now.
// We should probably fetch it properly.
// For now, default to 70.
setUserBodyWeight('70');
} else if (userWeight) {
setUserBodyWeight(userWeight.toString());
}
};
loadData();
}, [activeSession, userId]);
}, [activeSession, userId, userWeight]);
// Timer Logic
useEffect(() => {
@@ -128,7 +124,7 @@ const Tracker: React.FC<TrackerProps> = ({ userId, activeSession, activePlan, on
if (plan && plan.description) {
setShowPlanPrep(plan);
} else {
onSessionStart(plan);
onSessionStart(plan, parseFloat(userBodyWeight));
}
};
@@ -358,10 +354,10 @@ const Tracker: React.FC<TrackerProps> = ({ userId, activeSession, activePlan, on
key={step.id}
onClick={() => jumpToStep(idx)}
className={`w-full text-left px-4 py-3 rounded-full text-sm flex items-center justify-between transition-colors ${idx === currentStepIndex
? 'bg-primary-container text-on-primary-container font-medium'
: idx < currentStepIndex
? 'text-on-surface-variant opacity-50'
: 'text-on-surface hover:bg-white/5'
? 'bg-primary-container text-on-primary-container font-medium'
: idx < currentStepIndex
? 'text-on-surface-variant opacity-50'
: 'text-on-surface hover:bg-white/5'
}`}
>
<span>{idx + 1}. {step.exerciseName}</span>
@@ -556,8 +552,8 @@ const Tracker: React.FC<TrackerProps> = ({ userId, activeSession, activePlan, on
key={type.id}
onClick={() => setNewType(type.id)}
className={`px-4 py-2 rounded-lg flex items-center gap-2 text-xs font-medium border transition-all ${newType === type.id
? 'bg-secondary-container text-on-secondary-container border-transparent'
: 'bg-transparent text-on-surface-variant border-outline hover:border-on-surface-variant'
? 'bg-secondary-container text-on-secondary-container border-transparent'
: 'bg-transparent text-on-surface-variant border-outline hover:border-on-surface-variant'
}`}
>
<type.icon size={14} /> {type.label}