From 2f51b26418cbb61e95600b07213779361b1a4726 Mon Sep 17 00:00:00 2001 From: Lars Date: Fri, 27 Mar 2026 12:20:01 +0100 Subject: [PATCH] fix: focus areas slider NaN values and validation Fixed multiple issues with relative weight sliders: 1. Sanitize focusData on load (ensure all 6 fields are numeric) 2. Sync focusTemp when clicking "Anpassen" button 3. Robust sum calculation filtering only *_pct fields 4. Convert NaN/undefined to 0 in all calculations 5. Safe Number() coercion before normalization Fixes errors: - "Gewichtung gesamt: NaN" - "Input should be a valid integer, input: null" - Prozent always showing 0% Co-Authored-By: Claude Opus 4.6 --- frontend/src/pages/GoalsPage.jsx | 59 ++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/frontend/src/pages/GoalsPage.jsx b/frontend/src/pages/GoalsPage.jsx index 9293783..d65925c 100644 --- a/frontend/src/pages/GoalsPage.jsx +++ b/frontend/src/pages/GoalsPage.jsx @@ -92,8 +92,21 @@ export default function GoalsPage() { ]) setGoalMode(modeData.goal_mode) setGoals(goalsData) - setFocusAreas(focusData) - setFocusTemp(focusData) // Initialize temp state + + // Ensure all focus fields are present and numeric + const sanitizedFocus = { + weight_loss_pct: focusData?.weight_loss_pct ?? 0, + muscle_gain_pct: focusData?.muscle_gain_pct ?? 0, + strength_pct: focusData?.strength_pct ?? 0, + endurance_pct: focusData?.endurance_pct ?? 0, + flexibility_pct: focusData?.flexibility_pct ?? 0, + health_pct: focusData?.health_pct ?? 0, + custom: focusData?.custom, + updated_at: focusData?.updated_at + } + + setFocusAreas(sanitizedFocus) + setFocusTemp(sanitizedFocus) // Convert types array to map for quick lookup const typesMap = {} @@ -278,7 +291,10 @@ export default function GoalsPage() { {!focusEditing && focusAreas && (