Skip to content

Commit 01cefe5

Browse files
exercise calories burned issue manual refresh solved
1 parent 8246287 commit 01cefe5

1 file changed

Lines changed: 9 additions & 19 deletions

File tree

frontend/src/pages/Dashboard.tsx

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ export default function Dashboard() {
145145
const handleAISubmit = async (input: string) => {
146146
setIsLoading(true);
147147
try {
148-
const previousCalories = summary?.calories_consumed || 0;
149148
const response = await loggingApi.log(input);
150149
const result = response.data as DailyNutrition;
151150

@@ -158,24 +157,15 @@ export default function Dashboard() {
158157
fat: result.consumed_fat,
159158
});
160159

161-
// Parse input to get item name for display
162-
const itemName = input.split(' ').slice(0, 5).join(' ');
163-
const now = new Date();
164-
const timeStr = now.toLocaleTimeString("en-US", { hour: "numeric", minute: "2-digit", hour12: true });
165-
166-
// Calculate calories added (difference from previous)
167-
const caloriesAdded = Math.round(result.consumed_calories - previousCalories);
168-
169-
// Create a display log entry
170-
const newLog: FoodLog = {
171-
id: `${Date.now()}`,
172-
name: itemName,
173-
calories: caloriesAdded,
174-
time: timeStr,
175-
type: "food",
176-
};
177-
178-
setLogs(prev => [newLog, ...prev]);
160+
// Fetch updated logs from backend to get the newly added item
161+
try {
162+
const logsRes = await loggingApi.logs();
163+
if (logsRes.data && Array.isArray(logsRes.data)) {
164+
setLogs(logsRes.data);
165+
}
166+
} catch (logsError) {
167+
console.log("Could not fetch updated logs");
168+
}
179169

180170
toast({
181171
title: "Logged successfully!",

0 commit comments

Comments
 (0)