Workout finishing fixed
This commit is contained in:
6
App.tsx
6
App.tsx
@@ -73,12 +73,13 @@ function App() {
|
|||||||
setCurrentUser(updatedUser);
|
setCurrentUser(updatedUser);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleStartSession = (plan?: WorkoutPlan) => {
|
const handleStartSession = (plan?: WorkoutPlan, startWeight?: number) => {
|
||||||
if (!currentUser) return;
|
if (!currentUser) return;
|
||||||
|
|
||||||
// Get latest weight from profile or default
|
// Get latest weight from profile or default
|
||||||
const profile = getCurrentUserProfile(currentUser.id);
|
const profile = getCurrentUserProfile(currentUser.id);
|
||||||
const currentWeight = profile?.weight || 70;
|
// Use provided startWeight, or profile weight, or default 70
|
||||||
|
const currentWeight = startWeight || profile?.weight || 70;
|
||||||
|
|
||||||
const newSession: WorkoutSession = {
|
const newSession: WorkoutSession = {
|
||||||
id: crypto.randomUUID(),
|
id: crypto.randomUUID(),
|
||||||
@@ -155,6 +156,7 @@ function App() {
|
|||||||
{currentTab === 'TRACK' && (
|
{currentTab === 'TRACK' && (
|
||||||
<Tracker
|
<Tracker
|
||||||
userId={currentUser.id}
|
userId={currentUser.id}
|
||||||
|
userWeight={currentUser.profile?.weight}
|
||||||
activeSession={activeSession}
|
activeSession={activeSession}
|
||||||
activePlan={activePlan}
|
activePlan={activePlan}
|
||||||
onSessionStart={handleStartSession}
|
onSessionStart={handleStartSession}
|
||||||
|
|||||||
@@ -8,16 +8,17 @@ import { t } from '../services/i18n';
|
|||||||
|
|
||||||
interface TrackerProps {
|
interface TrackerProps {
|
||||||
userId: string;
|
userId: string;
|
||||||
|
userWeight?: number;
|
||||||
activeSession: WorkoutSession | null;
|
activeSession: WorkoutSession | null;
|
||||||
activePlan: WorkoutPlan | null;
|
activePlan: WorkoutPlan | null;
|
||||||
onSessionStart: (plan?: WorkoutPlan) => void;
|
onSessionStart: (plan?: WorkoutPlan, startWeight?: number) => void;
|
||||||
onSessionEnd: () => void;
|
onSessionEnd: () => void;
|
||||||
onSetAdded: (set: WorkoutSet) => void;
|
onSetAdded: (set: WorkoutSet) => void;
|
||||||
onRemoveSet: (setId: string) => void;
|
onRemoveSet: (setId: string) => void;
|
||||||
lang: Language;
|
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 [exercises, setExercises] = useState<ExerciseDef[]>([]);
|
||||||
const [plans, setPlans] = useState<WorkoutPlan[]>([]);
|
const [plans, setPlans] = useState<WorkoutPlan[]>([]);
|
||||||
const [selectedExercise, setSelectedExercise] = useState<ExerciseDef | null>(null);
|
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');
|
const [bwPercentage, setBwPercentage] = useState<string>('100');
|
||||||
|
|
||||||
// User Weight State
|
// User Weight State
|
||||||
const [userBodyWeight, setUserBodyWeight] = useState<string>('70');
|
const [userBodyWeight, setUserBodyWeight] = useState<string>(userWeight ? userWeight.toString() : '70');
|
||||||
|
|
||||||
// Create Exercise State
|
// Create Exercise State
|
||||||
const [isCreating, setIsCreating] = useState(false);
|
const [isCreating, setIsCreating] = useState(false);
|
||||||
@@ -57,17 +58,12 @@ const Tracker: React.FC<TrackerProps> = ({ userId, activeSession, activePlan, on
|
|||||||
|
|
||||||
if (activeSession?.userBodyWeight) {
|
if (activeSession?.userBodyWeight) {
|
||||||
setUserBodyWeight(activeSession.userBodyWeight.toString());
|
setUserBodyWeight(activeSession.userBodyWeight.toString());
|
||||||
} else {
|
} else if (userWeight) {
|
||||||
// Profile fetch needs to be async too if we updated it,
|
setUserBodyWeight(userWeight.toString());
|
||||||
// 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');
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
loadData();
|
loadData();
|
||||||
}, [activeSession, userId]);
|
}, [activeSession, userId, userWeight]);
|
||||||
|
|
||||||
// Timer Logic
|
// Timer Logic
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -128,7 +124,7 @@ const Tracker: React.FC<TrackerProps> = ({ userId, activeSession, activePlan, on
|
|||||||
if (plan && plan.description) {
|
if (plan && plan.description) {
|
||||||
setShowPlanPrep(plan);
|
setShowPlanPrep(plan);
|
||||||
} else {
|
} else {
|
||||||
onSessionStart(plan);
|
onSessionStart(plan, parseFloat(userBodyWeight));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -42,6 +42,11 @@ router.post('/', async (req: any, res) => {
|
|||||||
const userId = req.user.userId;
|
const userId = req.user.userId;
|
||||||
const { id, startTime, endTime, userBodyWeight, note, sets } = req.body;
|
const { id, startTime, endTime, userBodyWeight, note, sets } = req.body;
|
||||||
|
|
||||||
|
// Convert timestamps to Date objects if they are numbers
|
||||||
|
const start = new Date(startTime);
|
||||||
|
const end = endTime ? new Date(endTime) : null;
|
||||||
|
const weight = userBodyWeight ? parseFloat(userBodyWeight) : null;
|
||||||
|
|
||||||
// Check if session exists
|
// Check if session exists
|
||||||
const existing = await prisma.workoutSession.findUnique({ where: { id } });
|
const existing = await prisma.workoutSession.findUnique({ where: { id } });
|
||||||
|
|
||||||
@@ -53,9 +58,9 @@ router.post('/', async (req: any, res) => {
|
|||||||
const updated = await prisma.workoutSession.update({
|
const updated = await prisma.workoutSession.update({
|
||||||
where: { id },
|
where: { id },
|
||||||
data: {
|
data: {
|
||||||
startTime,
|
startTime: start,
|
||||||
endTime,
|
endTime: end,
|
||||||
userBodyWeight,
|
userBodyWeight: weight,
|
||||||
note,
|
note,
|
||||||
sets: {
|
sets: {
|
||||||
create: sets.map((s: any, idx: number) => ({
|
create: sets.map((s: any, idx: number) => ({
|
||||||
@@ -65,7 +70,7 @@ router.post('/', async (req: any, res) => {
|
|||||||
reps: s.reps,
|
reps: s.reps,
|
||||||
distanceMeters: s.distanceMeters,
|
distanceMeters: s.distanceMeters,
|
||||||
durationSeconds: s.durationSeconds,
|
durationSeconds: s.durationSeconds,
|
||||||
completed: s.completed
|
completed: s.completed !== undefined ? s.completed : true
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -78,9 +83,9 @@ router.post('/', async (req: any, res) => {
|
|||||||
data: {
|
data: {
|
||||||
id, // Use provided ID or let DB gen? Frontend usually generates UUIDs.
|
id, // Use provided ID or let DB gen? Frontend usually generates UUIDs.
|
||||||
userId,
|
userId,
|
||||||
startTime,
|
startTime: start,
|
||||||
endTime,
|
endTime: end,
|
||||||
userBodyWeight,
|
userBodyWeight: weight,
|
||||||
note,
|
note,
|
||||||
sets: {
|
sets: {
|
||||||
create: sets.map((s: any, idx: number) => ({
|
create: sets.map((s: any, idx: number) => ({
|
||||||
@@ -90,7 +95,7 @@ router.post('/', async (req: any, res) => {
|
|||||||
reps: s.reps,
|
reps: s.reps,
|
||||||
distanceMeters: s.distanceMeters,
|
distanceMeters: s.distanceMeters,
|
||||||
durationSeconds: s.durationSeconds,
|
durationSeconds: s.durationSeconds,
|
||||||
completed: s.completed
|
completed: s.completed !== undefined ? s.completed : true
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user