Spaces:
Running
Running
ReportRaahat CI commited on
Commit ·
61b86c9
1
Parent(s): fc2e6dd
Deploy from GitHub: f9ebc7527fa2ecf3a393d49aea5d1151b76daa66
Browse files
frontend/app/exercise/page.tsx
CHANGED
|
@@ -71,15 +71,33 @@ export default function ExercisePage() {
|
|
| 71 |
const severity = latestReport?.severity_level ?? "MILD_CONCERN";
|
| 72 |
|
| 73 |
useEffect(() => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
const fetchPlan = async () => {
|
| 75 |
try {
|
| 76 |
setLoading(true);
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
| 80 |
if (!res.ok) throw new Error();
|
| 81 |
-
const json
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
setSelectedDay("Monday");
|
| 84 |
} catch {
|
| 85 |
setData(FALLBACK_PLAN);
|
|
|
|
| 71 |
const severity = latestReport?.severity_level ?? "MILD_CONCERN";
|
| 72 |
|
| 73 |
useEffect(() => {
|
| 74 |
+
const TIER_MAP: Record<string, string> = {
|
| 75 |
+
Beginner: "LIGHT_WALKING_ONLY",
|
| 76 |
+
Intermediate: "NORMAL_ACTIVITY",
|
| 77 |
+
Advanced: "ACTIVE_ENCOURAGED",
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
const fetchPlan = async () => {
|
| 81 |
try {
|
| 82 |
setLoading(true);
|
| 83 |
+
// Backend expects POST /exercise/ with empty body (stub)
|
| 84 |
+
const res = await fetch(`${API_BASE}/exercise/`, {
|
| 85 |
+
method: "POST",
|
| 86 |
+
headers: { "Content-Type": "application/json" },
|
| 87 |
+
body: JSON.stringify({}),
|
| 88 |
+
});
|
| 89 |
if (!res.ok) throw new Error();
|
| 90 |
+
const json = await res.json();
|
| 91 |
+
|
| 92 |
+
// Transform backend ExerciseResponse → frontend ExerciseResponse
|
| 93 |
+
const transformed: ExerciseResponse = {
|
| 94 |
+
tier: TIER_MAP[json.tier] ?? json.tier ?? "NORMAL_ACTIVITY",
|
| 95 |
+
tier_description: json.tier_reason ?? json.tier_description ?? "",
|
| 96 |
+
weekly_plan: json.weekly_plan ?? [],
|
| 97 |
+
general_advice: json.encouragement ?? json.general_advice ?? "",
|
| 98 |
+
avoid: json.restrictions ?? json.avoid ?? [],
|
| 99 |
+
};
|
| 100 |
+
setData(transformed);
|
| 101 |
setSelectedDay("Monday");
|
| 102 |
} catch {
|
| 103 |
setData(FALLBACK_PLAN);
|
frontend/app/nutrition/page.tsx
CHANGED
|
@@ -94,18 +94,67 @@ export default function NutritionPage() {
|
|
| 94 |
try {
|
| 95 |
setLoading(true);
|
| 96 |
setError(false);
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
if (!res.ok) throw new Error("API error");
|
| 101 |
-
const json
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
} catch {
|
| 104 |
try {
|
| 105 |
const res = await fetch(`${API_BASE}/nutrition/fallback`);
|
| 106 |
if (!res.ok) throw new Error();
|
| 107 |
-
const json
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
} catch {
|
| 110 |
setError(true);
|
| 111 |
}
|
|
@@ -114,7 +163,7 @@ export default function NutritionPage() {
|
|
| 114 |
}
|
| 115 |
};
|
| 116 |
fetchNutrition();
|
| 117 |
-
}, [flags, API_BASE, profile.language]);
|
| 118 |
|
| 119 |
const handleAddToToday = (food: FoodItem) => {
|
| 120 |
logFood(food.name_english);
|
|
|
|
| 94 |
try {
|
| 95 |
setLoading(true);
|
| 96 |
setError(false);
|
| 97 |
+
|
| 98 |
+
// Backend expects POST /nutrition/ with NutritionRequest JSON body
|
| 99 |
+
const res = await fetch(`${API_BASE}/nutrition/`, {
|
| 100 |
+
method: "POST",
|
| 101 |
+
headers: { "Content-Type": "application/json" },
|
| 102 |
+
body: JSON.stringify({
|
| 103 |
+
dietary_flags: nutritionProfile.deficiencies.length > 0
|
| 104 |
+
? nutritionProfile.deficiencies
|
| 105 |
+
: ["INCREASE_IRON"],
|
| 106 |
+
allergy_flags: [],
|
| 107 |
+
vegetarian: true,
|
| 108 |
+
}),
|
| 109 |
+
});
|
| 110 |
if (!res.ok) throw new Error("API error");
|
| 111 |
+
const json = await res.json();
|
| 112 |
+
|
| 113 |
+
// Transform backend FoodItem → frontend FoodItem shape
|
| 114 |
+
const transformed: NutritionResponse = {
|
| 115 |
+
recommended_foods: (json.recommended_foods ?? []).map((f: Record<string, unknown>) => ({
|
| 116 |
+
name_english: f.food_name ?? "",
|
| 117 |
+
name_hindi: f.food_name_hindi ?? "",
|
| 118 |
+
food_group: f.food_group ?? "",
|
| 119 |
+
serving_suggestion: f.serving_suggestion ?? "",
|
| 120 |
+
nutrient_highlights: {
|
| 121 |
+
protein_g: (f.protein_g as number) ?? 0,
|
| 122 |
+
iron_mg: (f.iron_mg as number) ?? 0,
|
| 123 |
+
calcium_mg: (f.calcium_mg as number) ?? 0,
|
| 124 |
+
vitaminD_iu: (f.vitamin_d_mcg as number) ?? 0,
|
| 125 |
+
fiber_g: (f.fibre_g as number) ?? 0,
|
| 126 |
+
calories_kcal: (f.energy_kcal as number) ?? 0,
|
| 127 |
+
},
|
| 128 |
+
})),
|
| 129 |
+
daily_targets: json.daily_targets ?? {},
|
| 130 |
+
deficiency_summary: (json.deficiencies ?? []).join(" · "),
|
| 131 |
+
};
|
| 132 |
+
setData(transformed);
|
| 133 |
} catch {
|
| 134 |
try {
|
| 135 |
const res = await fetch(`${API_BASE}/nutrition/fallback`);
|
| 136 |
if (!res.ok) throw new Error();
|
| 137 |
+
const json = await res.json();
|
| 138 |
+
|
| 139 |
+
const transformed: NutritionResponse = {
|
| 140 |
+
recommended_foods: (json.recommended_foods ?? []).map((f: Record<string, unknown>) => ({
|
| 141 |
+
name_english: f.food_name ?? "",
|
| 142 |
+
name_hindi: f.food_name_hindi ?? "",
|
| 143 |
+
food_group: f.food_group ?? "",
|
| 144 |
+
serving_suggestion: f.serving_suggestion ?? "",
|
| 145 |
+
nutrient_highlights: {
|
| 146 |
+
protein_g: (f.protein_g as number) ?? 0,
|
| 147 |
+
iron_mg: (f.iron_mg as number) ?? 0,
|
| 148 |
+
calcium_mg: (f.calcium_mg as number) ?? 0,
|
| 149 |
+
vitaminD_iu: (f.vitamin_d_mcg as number) ?? 0,
|
| 150 |
+
fiber_g: (f.fibre_g as number) ?? 0,
|
| 151 |
+
calories_kcal: (f.energy_kcal as number) ?? 0,
|
| 152 |
+
},
|
| 153 |
+
})),
|
| 154 |
+
daily_targets: json.daily_targets ?? {},
|
| 155 |
+
deficiency_summary: (json.deficiencies ?? []).join(" · "),
|
| 156 |
+
};
|
| 157 |
+
setData(transformed);
|
| 158 |
} catch {
|
| 159 |
setError(true);
|
| 160 |
}
|
|
|
|
| 163 |
}
|
| 164 |
};
|
| 165 |
fetchNutrition();
|
| 166 |
+
}, [flags, API_BASE, profile.language, nutritionProfile.deficiencies]);
|
| 167 |
|
| 168 |
const handleAddToToday = (food: FoodItem) => {
|
| 169 |
logFood(food.name_english);
|