Skip to content

Commit

Permalink
hotfix : mart trouble shooting (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Woo committed Apr 7, 2023
1 parent db124ca commit f16b444
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 99 deletions.
14 changes: 7 additions & 7 deletions frontend/src/components/Camera/Camera.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export default function Camera() {
.then((res) => {
setEngFoodName(res.data)
}).catch((err) => {
console.log(err)

})
setStatus(status+1);
}
}
const handleYes = useCallback ((name) => {
console.log(name)

axios.get(`${process.env.REACT_APP_API_URL}/food/check?name=${name}`)
.then((res) => {
if (res.data.checkFlag === -1) {
Expand All @@ -56,9 +56,9 @@ export default function Camera() {
setStatus(0);
navigate(`/ingredient/${res.data.id}`);
}
console.log(res);

}).catch((err) => {
console.log(err)

})
}, [navigate]);

Expand Down Expand Up @@ -93,7 +93,7 @@ export default function Camera() {
});
handleStream(stream);
} catch (err) {
console.log(err);

}
};
}
Expand All @@ -116,7 +116,7 @@ export default function Camera() {
const context = canvas.getContext('2d');
context.drawImage(video, 0, 0, canvas.width, canvas.height);
const dataUrl = canvas.toDataURL('image/png')
// console.log(dataUrl)

imageMaker(dataUrl);
}
}, []);
Expand Down Expand Up @@ -153,7 +153,7 @@ export default function Camera() {
.then((res) => {
setEngFoodName(res.data)
}).catch((err) => {
console.log(err)

})
setStatus(1);
}
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/Cart/Cart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ export default function Cart() {
.then((res) => {
setCartItems(res.data)
}).catch((err) => {
console.log(err)

})

// fetchCartItems();
// Initialize the Kakao SDK with your app's JavaScript key

// Check if the SDK is initialized
if (Kakao.isInitialized()) {
console.log('Kakao SDK initialized.');

} else {
console.error('Failed to initialize Kakao SDK.');

}
}, []);

Expand Down Expand Up @@ -90,7 +90,7 @@ export default function Cart() {

return response.data.data.url;
} catch (error) {
console.error('Error uploading image to server:', error);

return null;
}
}
Expand All @@ -104,7 +104,7 @@ export default function Cart() {

// Upload the captured image to the Spring server
const imageUrl = await uploadImageToImgbb(imageBlob);
console.log(imageUrl)


if (imageUrl) {
Kakao.Link.sendDefault({
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Cart/CartUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export const toggleExpandUtil = (prevExpanded, ingredient) => ({
};

export const selectItemUtil = (prevSelectedItems, item, index) => {
console.log(prevSelectedItems)

if (prevSelectedItems[index].some((selectedItem) => selectedItem.ingredientName === item.ingredientName)) {
console.log('Item already added.');

return prevSelectedItems;
}
const newSelectedItems = [...prevSelectedItems];
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/Categories/Category.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ export default function Category({ categoryList, isChosen, setIsChosen, setPart,
});
setPart(ingreAxios.data)
} catch(error) {
console.error('Error cheapIngre data: ', error);

}

} catch (error) {
console.error('Error cheap data: ', error);

}
} else if (chosen === 'Vegetable' || chosen === 'Meat' || chosen === 'Popular') {
try {
const ingreAxios = await axios.get(`${process.env.REACT_APP_API_URL}/ingredient/${chosen}`, {params});
setPart(ingreAxios.data)
} catch (error) {
console.error('Error VegiMeatPop data: ', error);

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Dish.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function useRecipeAPI() {
setOriginData(response.data);
})
.catch(() => {
console.log('There are no nutrient data.');

});
}
}, [data]);
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/Ingredient.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ function useIngredientPrice() {
useEffect(() => {
axios.get(`${process.env.REACT_APP_API_URL}/deal/detail`, { params })
.then(function (response) {
console.log(response.data)

setData(response.data);
})
.catch(function (err) {
console.log(err);

});
}, []);
return data;
Expand All @@ -46,7 +46,7 @@ function useRelatedFoodAPI(cardData) {
setData(response.data.slice(0, 3));
})
.catch(function (err) {
console.log(err);

});
}
}, [cardData]);
Expand Down Expand Up @@ -81,7 +81,7 @@ function useNutrition() {
setData(nutrientData);
})
.catch(() => {
console.log('There is no nutrient data');

});
}, []);
return data;
Expand All @@ -107,7 +107,7 @@ const useCardData = () => {
setData(response.data);
})
.catch(function (err) {
console.log(err);

});
}, []);
return data;
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function Main() {
const dishAxios = await axios.get(`${process.env.REACT_APP_API_URL}/recipe/Popular`, {params});
setDish(dishAxios.data)
const ingreAxios = await axios.get(`${process.env.REACT_APP_API_URL}/ingredient/Popular`, {params});
console.log(ingreAxios.data)

setIngredients(ingreAxios.data)
setIngreName(ingreAxios.data[0].name)
const priceChangeAxios = await axios.get(`${process.env.REACT_APP_API_URL}/deal/change`, {params});
Expand All @@ -68,11 +68,11 @@ function Main() {
setIngreDish(ingreDishAxios.data.slice(0, 4))

} catch (error) {
console.error('Error fetching data: ', error);

}
}
catch (error) {
console.error('Error fetching data: ', error);

}
};
const groupDataBySmall = (data) => {
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/acoounts/SignUp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ export default function SignUp() {

if (response.status === 201) {
// 회원가입 성공 시 할 일
console.log('회원가입 성공', response.data);

navigate('/login');
} else {
// 회원가입 실패 시 할 일
console.log('회원가입 실패', response.data);

}
} catch (error) {
console.error('회원가입 오류 : ', error);

}

// console.log('회원가입 정보: ', { email, password, name, gender })

}
return (
<div className="signup-container">
Expand Down
71 changes: 3 additions & 68 deletions frontend/src/components/profile/Profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ export default function Profile() {
try {
const response = await axios.get(`${process.env.REACT_APP_API_URL}/record/get`, { headers: headers });
const responseData = response.data;
console.log(response.data)
const today = getToday();
console.log(today)
const todaysData = responseData.filter((entry) => new Date(entry.eatDate) >= today);
console.log(todaysData)

const todaysData = responseData.filter((entry) => new Date(entry.eatDate) >= today);
const totalCalories = todaysData.reduce((total, entry) => total + entry.kcal, 0);
console.log(totalCalories)

const nutrition = {
carbs: todaysData.reduce((total, entry) => total + entry.carb, 0),
fat: todaysData.reduce((total, entry) => total + entry.fat, 0),
Expand All @@ -44,18 +40,15 @@ export default function Profile() {
'sugar (g)': todaysData.reduce((total, entry) => total + entry.sugar, 0),
'salt (mg)': todaysData.reduce((total, entry) => total + entry.salt, 0),
};
console.log(other)

const lastWeeksData = responseData
.filter((entry) => isWithinLastWeek(new Date(entry.eatDate)))
.sort((a, b) => new Date(b.eatDate) - new Date(a.eatDate)); // 최신 날짜가 먼저 오도록 정렬
console.log(lastWeeksData)
const ingestedFood = lastWeeksData.map((entry) => {
const kcalPer100g = entry.kcal / (entry.servingSize / 100);
const foodName = entry.foodName;
return [foodName, kcalPer100g];
});
console.log(ingestedFood)
setProfile({
name: responseData[0].user.name,
totalCalories,
Expand All @@ -64,7 +57,7 @@ export default function Profile() {
ingestedFood,
})
} catch (error) {
console.log('err');

}
};
fetchData();
Expand All @@ -80,71 +73,13 @@ const logOut = () => {
localStorage.removeItem('hancook-token');
navigate('/login')
}

// function useFetchProfile() {
// const headers = {
// 'Authorization': `Bearer ${localStorage.getItem('hancook-token')}`,
// 'Content-Type': 'application/json',
// };

// useEffect(() => {
// axios.get(`${process.env.REACT_APP_API_URL}/record/get`, { headers: headers })
// .then(res=>createProfile(res.data))
// .catch (() => {
// console.log('err');
// })
// })
// }

const isWithinLastWeek = (date) => {
const today = getToday();
const oneWeekAgo = new Date(today - 7 * 24 * 60 * 60 * 1000);
return date >= oneWeekAgo && date < new Date(today.valueOf() + 24 * 60 * 60 * 1000);
};

// const createProfile = (responseData) => {
// const today = getToday();
// const todaysData = responseData.filter((entry) => new Date(entry.eatDate) >= today);
// console.log(todaysData)

// const totalCalories = todaysData.reduce((total, entry) => total + entry.kcal, 0);
// const nutrition = {
// carbs: todaysData.reduce((total, entry) => total + entry.carb, 0),
// fat: todaysData.reduce((total, entry) => total + entry.fat, 0),
// protein: todaysData.reduce((total, entry) => total + entry.protein, 0),
// };
// const other = {
// 'cholesterol (mg)': todaysData.reduce((total, entry) => total + entry.cholesterol, 0),
// 'sugar (g)': todaysData.reduce((total, entry) => total + entry.sugar, 0),
// 'salt (mg)': todaysData.reduce((total, entry) => total + entry.salt, 0),
// };

// const lastWeeksData = responseData
// .filter((entry) => isWithinLastWeek(new Date(entry.eatDate)))
// .sort((a, b) => new Date(b.eatDate) - new Date(a.eatDate)); // 최신 날짜가 먼저 오도록 정렬

// const ingestedFood = lastWeeksData.map((entry) => {
// const kcalPer100g = entry.kcal / (entry.servingSize / 100);
// const foodName = entry.foodName;
// return [foodName, kcalPer100g];
// });

// console.log({
// name: responseData[0].user.name,
// totalCalories,
// nutrition,
// other,
// ingestedFood,
// })

// return {
// name: responseData[0].user.name,
// totalCalories,
// nutrition,
// other,
// ingestedFood,
// };
// };


return (
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/search/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default function Search() {
setResult(response.data)
setLoading(false)
}).catch(err => {
console.log(err)
setLoading(false)
})
}
Expand Down

0 comments on commit f16b444

Please sign in to comment.