Ongoing workout session data is persistent now

This commit is contained in:
AG
2025-11-28 19:00:56 +02:00
parent 4c632e164e
commit d07431e4ff
10 changed files with 375 additions and 48 deletions

View File

@@ -24,6 +24,37 @@ export const saveSession = async (userId: string, session: WorkoutSession): Prom
await api.post('/sessions', session);
};
export const getActiveSession = async (userId: string): Promise<WorkoutSession | null> => {
try {
const response = await api.get('/sessions/active');
if (!response.success || !response.session) {
return null;
}
const session = response.session;
// Convert ISO date strings to timestamps
return {
...session,
startTime: new Date(session.startTime).getTime(),
endTime: session.endTime ? new Date(session.endTime).getTime() : undefined,
sets: session.sets.map((set: any) => ({
...set,
exerciseName: set.exercise?.name || 'Unknown',
type: set.exercise?.type || 'STRENGTH'
}))
};
} catch {
return null;
}
};
export const updateActiveSession = async (userId: string, session: WorkoutSession): Promise<void> => {
await api.put('/sessions/active', session);
};
export const deleteActiveSession = async (userId: string): Promise<void> => {
await api.delete('/sessions/active');
};
export const deleteSession = async (userId: string, id: string): Promise<void> => {
await api.delete(`/sessions/${id}`);
};