From 701d217c8969626b7e3509984a4ca523b79856ff Mon Sep 17 00:00:00 2001 From: AG Date: Tue, 25 Nov 2025 23:32:47 +0200 Subject: [PATCH] Exercise archivation fixed --- components/Profile.tsx | 12 ++++++++---- components/Tracker.tsx | 6 ++---- server/prisma/dev.db | Bin 61440 -> 61440 bytes server/src/routes/exercises.ts | 16 +++++++++++----- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/components/Profile.tsx b/components/Profile.tsx index fef3bb4..a034e56 100644 --- a/components/Profile.tsx +++ b/components/Profile.tsx @@ -72,7 +72,9 @@ const Profile: React.FC = ({ user, onLogout, lang, onLanguageChang }; const refreshExercises = async () => { - setExercises(await getExercises(user.id)); + const exercises = await getExercises(user.id); + console.log('Refreshed exercises:', exercises); + setExercises(exercises); }; // Snackbar State @@ -160,10 +162,12 @@ const Profile: React.FC = ({ user, onLogout, lang, onLanguageChang }; // Exercise Management Handlers - const handleArchiveExercise = (ex: ExerciseDef, archive: boolean) => { + const handleArchiveExercise = async (ex: ExerciseDef, archive: boolean) => { const updated = { ...ex, isArchived: archive }; - saveExercise(user.id, updated); - refreshExercises(); + console.log('Archiving exercise:', updated); + await saveExercise(user.id, updated); + console.log('Archive complete, refreshing...'); + await refreshExercises(); }; const handleSaveExerciseEdit = () => { diff --git a/components/Tracker.tsx b/components/Tracker.tsx index d3d47d8..b1785d7 100644 --- a/components/Tracker.tsx +++ b/components/Tracker.tsx @@ -108,14 +108,12 @@ const Tracker: React.FC = ({ userId, userWeight, activeSession, ac if (step) { const exDef = exercises.find(e => e.id === step.exerciseId); if (exDef) { - if (!selectedExercise || selectedExercise.id !== exDef.id) { - setSelectedExercise(exDef); - } + setSelectedExercise(exDef); } } } } - }, [activeSession, activePlan, currentStepIndex, exercises, selectedExercise]); + }, [currentStepIndex, activePlan, exercises]); useEffect(() => { const updateSelection = async () => { diff --git a/server/prisma/dev.db b/server/prisma/dev.db index 90f280a7f2f407107f4cb7a4a5426d798fdc7887..12485f6b9171e2a9048d6ca2e3b97bd54e601f1d 100644 GIT binary patch delta 28 kcmZp8z})bFd4e=!?nD`9#@vkwj`5Rk=c{f$7H>5H0HJgXlK=n! delta 30 mcmZp8z})bFd4e=!) { const token = req.headers.authorization?.split(' ')[1]; @@ -31,10 +32,10 @@ router.get('/', async (req: any, res) => { OR: [ { userId: null }, // System default { userId } // User custom - ], - isArchived: false + ] } }); + console.log('GET /exercises - Returning:', exercises.map(e => ({ id: e.id, name: e.name, isArchived: e.isArchived }))); res.json(exercises); } catch (error) { res.status(500).json({ error: 'Server error' }); @@ -45,7 +46,9 @@ router.get('/', async (req: any, res) => { router.post('/', async (req: any, res) => { try { const userId = req.user.userId; - const { id, name, type, bodyWeightPercentage } = req.body; + const { id, name, type, bodyWeightPercentage, isArchived } = req.body; + + console.log('POST /exercises - Received:', { id, name, type, bodyWeightPercentage, isArchived }); // If id exists and belongs to user, update. Else create. // Note: We can't update system exercises directly. If user edits a system exercise, @@ -56,10 +59,12 @@ router.post('/', async (req: any, res) => { // Check if it exists and belongs to user const existing = await prisma.exercise.findUnique({ where: { id } }); if (existing && existing.userId === userId) { + console.log('Updating existing exercise with:', { name, type, bodyWeightPercentage, isArchived }); const updated = await prisma.exercise.update({ where: { id }, - data: { name, type, bodyWeightPercentage } + data: { name, type, bodyWeightPercentage, isArchived } }); + console.log('Updated exercise:', updated); return res.json(updated); } } @@ -70,7 +75,8 @@ router.post('/', async (req: any, res) => { userId, name, type, - bodyWeightPercentage + bodyWeightPercentage, + isArchived: isArchived || false } }); res.json(newExercise);