From db90f397e845ef17fcdcde55e5a5c4add129699e Mon Sep 17 00:00:00 2001 From: Lars Date: Fri, 27 Mar 2026 13:09:34 +0100 Subject: [PATCH] feat: auto-assign goal category based on goal type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added intelligent category assignment: - Weight, body_fat, lean_mass → Körper - Strength, flexibility → Training - BP, VO2Max, RHR, HRV → Gesundheit - Sleep goals → Erholung - Nutrition goals → Ernährung - Unknown types → Sonstiges Changes: 1. getCategoryForGoalType() mapping function 2. Auto-set category in handleGoalTypeChange() 3. Auto-set category in handleCreateGoal() User can still manually change category if needed. Fixes: Blood pressure goals wrongly categorized as 'Training' Co-Authored-By: Claude Opus 4.6 --- frontend/src/pages/GoalsPage.jsx | 38 ++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/GoalsPage.jsx b/frontend/src/pages/GoalsPage.jsx index 275fff5..d27cdf8 100644 --- a/frontend/src/pages/GoalsPage.jsx +++ b/frontend/src/pages/GoalsPage.jsx @@ -22,6 +22,39 @@ const PRIORITY_LEVELS = { 3: { label: 'Niedrig', stars: '⭐', color: '#CBD5E1' } } +// Auto-assign category based on goal_type +const getCategoryForGoalType = (goalType) => { + const mapping = { + // Body composition + 'weight': 'body', + 'body_fat': 'body', + 'lean_mass': 'body', + + // Training + 'strength': 'training', + 'flexibility': 'training', + 'training_frequency': 'training', + + // Health/Vitals + 'vo2max': 'health', + 'rhr': 'health', + 'bp': 'health', + 'hrv': 'health', + + // Recovery + 'sleep_quality': 'recovery', + 'sleep_duration': 'recovery', + 'rest_days': 'recovery', + + // Nutrition + 'calories': 'nutrition', + 'protein': 'nutrition', + 'healthy_eating': 'nutrition' + } + + return mapping[goalType] || 'other' +} + export default function GoalsPage() { const [goalMode, setGoalMode] = useState(null) const [focusAreas, setFocusAreas] = useState(null) @@ -141,7 +174,7 @@ export default function GoalsPage() { setFormData({ goal_type: firstType, is_primary: goals.length === 0, // First goal is primary by default - category: 'body', + category: getCategoryForGoalType(firstType), // Auto-assign based on type priority: 2, target_value: '', unit: goalTypesMap[firstType]?.unit || 'kg', @@ -172,7 +205,8 @@ export default function GoalsPage() { setFormData(f => ({ ...f, goal_type: type, - unit: goalTypesMap[type]?.unit || 'unit' + unit: goalTypesMap[type]?.unit || 'unit', + category: getCategoryForGoalType(type) // Auto-assign category })) }