Skip to content

Commit

Permalink
fix max progress value, limit to 100
Browse files Browse the repository at this point in the history
  • Loading branch information
sdevalapurkar committed Oct 20, 2021
1 parent 027a351 commit 04be25d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
16 changes: 14 additions & 2 deletions app/src/components/GoalDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ function GoalDetails() {
);
}

const getProgressValue = () => {
if (!goalDetails.goal_practice_times) {
return 0;
}

if (goalDetails.goal_practice_times >= goalDetails.goal_times) {
return 100;
}

return (goalDetails.goal_practice_times * 100) / goalDetails.goal_times;
};

return (
<>
<Header logoutUser={logoutUser} />
Expand All @@ -119,7 +131,7 @@ function GoalDetails() {
<Typography variant="body1"><b>Progress:</b></Typography>
</Box>
<CircularProgressWithLabel
value={goalDetails.goal_practice_times ? (goalDetails.goal_practice_times * 100) / goalDetails.goal_times : 0}
value={getProgressValue()}
/>
<Box pt={2}>
{goalDetails.goal_practice_times < goalDetails.goal_times && (
Expand All @@ -134,7 +146,7 @@ function GoalDetails() {
</Button>
)}
{goalDetails.goal_practice_times >= goalDetails.goal_times && (
<Typography variant="h6">Congrats! You've completed this goal already.</Typography>
<Typography variant="body1">Congrats! You've completed this goal :)</Typography>
)}
</Box>
</Box>
Expand Down
14 changes: 13 additions & 1 deletion app/src/components/Homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ function Homepage() {
setIsAuthed(isAuthenticated());
};

const getProgressValue = (goalDetails) => {
if (!goalDetails.goal_practice_times) {
return 0;
}

if (goalDetails.goal_practice_times >= goalDetails.goal_times) {
return 100;
}

return (goalDetails.goal_practice_times * 100) / goalDetails.goal_times;
};

const getExistingGoalsTable = () => {
if (!existingGoals.length) {
return (
Expand Down Expand Up @@ -152,7 +164,7 @@ function Homepage() {
<TableCell>{moment(row.goal_end_date).format('MMM D, YYYY')}</TableCell>
<TableCell>
<CircularProgressWithLabel
value={row.goal_practice_times ? (row.goal_practice_times * 100) / row.goal_times : 0}
value={getProgressValue()}
/>
</TableCell>
<TableCell align="right">
Expand Down

0 comments on commit 04be25d

Please sign in to comment.