Separated weight tracking

This commit is contained in:
AG
2025-11-29 12:13:12 +02:00
parent 78930f6b80
commit d86abd6b1b
11 changed files with 300 additions and 22 deletions

30
App.tsx
View File

@@ -12,6 +12,7 @@ import { TabView, WorkoutSession, WorkoutSet, WorkoutPlan, User, Language } from
import { getSessions, saveSession, deleteSession, getPlans, getActiveSession, updateActiveSession, deleteActiveSession, updateSetInActiveSession, deleteSetFromActiveSession } from './services/storage';
import { getCurrentUserProfile, getMe } from './services/auth';
import { getSystemLanguage } from './services/i18n';
import { logWeight } from './services/weight';
import { generateId } from './utils/uuid';
function App() {
@@ -114,6 +115,11 @@ function App() {
// Save to database immediately
await saveSession(currentUser.id, newSession);
// If startWeight was provided (meaning user explicitly entered it), log it to weight history
if (startWeight) {
await logWeight(startWeight);
}
};
const handleEndSession = async () => {
@@ -144,23 +150,23 @@ function App() {
const handleRemoveSetFromActive = async (setId: string) => {
if (activeSession && currentUser) {
await deleteSetFromActiveSession(currentUser.id, setId);
const updatedSession = {
...activeSession,
sets: activeSession.sets.filter(s => s.id !== setId)
};
setActiveSession(updatedSession);
await deleteSetFromActiveSession(currentUser.id, setId);
const updatedSession = {
...activeSession,
sets: activeSession.sets.filter(s => s.id !== setId)
};
setActiveSession(updatedSession);
}
};
const handleUpdateSetInActive = async (updatedSet: WorkoutSet) => {
if (activeSession && currentUser) {
const response = await updateSetInActiveSession(currentUser.id, updatedSet.id, updatedSet);
const updatedSession = {
...activeSession,
sets: activeSession.sets.map(s => s.id === updatedSet.id ? response : s)
};
setActiveSession(updatedSession);
const response = await updateSetInActiveSession(currentUser.id, updatedSet.id, updatedSet);
const updatedSession = {
...activeSession,
sets: activeSession.sets.map(s => s.id === updatedSet.id ? response : s)
};
setActiveSession(updatedSession);
}
};