Skip to content

Commit

Permalink
Merge pull request #34 from csci5117s24/fix_new_user
Browse files Browse the repository at this point in the history
fix: error for new users
  • Loading branch information
May-Wang-666 authored May 6, 2024
2 parents 39a2cfa + ea27efc commit b67ebb4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion app/api/src/biz/water.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ function calStat(waterLogs, keyFunc, targetUnit) {


async function FormatWaterLogs(userId, waterLogs) {
const waterGoal = await FindFromMongo("water_goal", {userId: userId});
let waterGoal = await FindFromMongo("water_goal", {userId: userId});
if (!waterGoal || waterGoal.length == 0) {
waterGoal = [{value: 0, unit: 'ml'}];
}
const goalUnit = waterGoal[0].unit;
return waterLogs.map((log) => {
if (log.unit === goalUnit) {
Expand Down
8 changes: 8 additions & 0 deletions app/src/routes/PageCalorie.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ function PageCalorie() {
}

async function updateGoal() {
if (!goal || goal === 0) {
alert("calorie goal can not be empty or zero!");
return
}
await setCalorieGoal(goal);
const newAchieved = calAchieved(calorieLogs, goal);
setEditGoal(false);
Expand Down Expand Up @@ -151,7 +155,11 @@ function PageCalorie() {
<h1 className='third-title'>Your Workouts
<span className='title-link'><Link className='title-link' to="/exercise/workout"> Manage</Link></span>
</h1>
{workouts.length === 0 ?
<div style={{marginBottom:'2rem'}}>You have no workouts yet. Click <Link to="/exercise/workout">here</Link> to add some. </div> :
<WorkoutList workouts={workouts} addCalorieLog={addCalorieLog}/>
}

<h1 className='third-title'>Your Exercise Logs for Today</h1>
<Link to="/exercise/calendar" style={{color: 'var(--my-blue)'}}> History</Link>
<CaloriesLogList calorieLogs={calorieLogs} deleteLog={removeCalorieLog}/>
Expand Down
6 changes: 4 additions & 2 deletions app/src/routes/PageWeightGoal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ export function PageWeightGoal() {
useEffect(() => {
async function fetchData() {
const curGoal = await getWeightGoal();
setGoal({value: curGoal.value, unit: curGoal.unit});
setDeadline(curGoal.deadline);
if (curGoal) {
setGoal({value: curGoal.value, unit: curGoal.unit});
setDeadline(curGoal.deadline);
}
}
fetchData();
}, []);
Expand Down

0 comments on commit b67ebb4

Please sign in to comment.