Skip to content

Commit

Permalink
Feature/workout history (#88)
Browse files Browse the repository at this point in the history
* refactor: score to reflect volume by name and calculation.

* bugFix: empty exercise list is handled and a tooltip is added to aid users with adding new exercises.

* feat: basic setup for new workout history tab

* bugFix: fetching associated exercises for a given workout and adding fresh exercises to log workout.

* feat: fetching from backend configured and stored.

* feat: added muiMaterial icons to dependencies + developing front-end for workout history.

* refactor: reduced nesting in mui components. Split UI into display table + content (rows)

* refactor: changed accordion format for better usability.

* feat: CSS coloring applied for the MUI components.

* refactor: adjusted font size

* refactor: to also show time.

* comments
  • Loading branch information
vonner04 authored Oct 4, 2024
1 parent ba72c5b commit d272fb4
Show file tree
Hide file tree
Showing 11 changed files with 673 additions and 318 deletions.
154 changes: 31 additions & 123 deletions fitness_tracker/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions fitness_tracker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@emotion/styled": "^11.13.0",
"@material/tab": "^14.0.0",
"@material/tabs": "^2.3.0",
"@mui/icons-material": "^6.1.2",
"@mui/material": "^5.16.7",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
Expand Down
135 changes: 89 additions & 46 deletions fitness_tracker/src/components/ExerciseAdder.jsx
Original file line number Diff line number Diff line change
@@ -1,69 +1,112 @@
import React, { useState } from 'react';
import buttons from '../module_CSS/buttons.module.css'
import styles from '../module_CSS/ExerciseLogger.module.css'
import { MenuItem, Select } from '@mui/material';
import buttons from '../module_CSS/buttons.module.css';
import styles from '../module_CSS/ExerciseLogger.module.css';
import { MenuItem, Select, Tooltip } from '@mui/material';

const ExerciseAdder = ({exerciseList, addExercise, cancelAddExercise }) => {
const [selectedExercise, setSelectedExercise] = useState(exerciseList[0])
const ExerciseAdder = ({ exerciseList, addExercise, cancelAddExercise }) => {
const [selectedExercise, setSelectedExercise] = useState(exerciseList.length > 0 ? exerciseList[0] : { name: "No exercises added" });


return (
<tr>
<td>
<Select
value={selectedExercise.name}
sx={{
width: "100%",
color: "white",
border: "1px solid white",
'& .MuiOutlinedInput-notchedOutline': {
borderColor: 'white',
},
'&:hover .MuiOutlinedInput-notchedOutline': {
borderColor: 'white',
},
'& .MuiSvgIcon-root': {
color: 'white',
}
}}
onChange={e => {
setSelectedExercise(exerciseList.find(exercise => exercise.name === e.target.value))
}}
>
{exerciseList.map((exercise) => (
<MenuItem
key={exercise.id}
value={exercise.name}
{exerciseList.length === 0 ? (
// Show Tooltip when no exercises are listed
<Tooltip title="No exercises recorded. Add an exercise by creating and submitting a routine." arrow>
<Select
value="No exercises added" // Default value
sx={{
color: "black",
backgroundColor: "white",
'&:hover': {
backgroundColor: "#f0f0f0",
width: "100%",
color: "white",
border: "1px solid white",
'& .MuiOutlinedInput-notchedOutline': {
borderColor: 'white',
},
'&:hover .MuiOutlinedInput-notchedOutline': {
borderColor: 'white',
},
'& .MuiSvgIcon-root': {
color: 'white',
}
}}
}}
readOnly // Disable dropdown functionality when no exercises
>
{exercise.name}
</MenuItem>
))}
</Select>
<MenuItem value="No exercises added">
No Exercises Recorded
</MenuItem>
</Select>
</Tooltip>
) : (
<Select
value={selectedExercise.name} // Selected exercise name
displayEmpty // Placeholder for exercises
sx={{
width: "100%",
color: "white",
border: "1px solid white",
'& .MuiOutlinedInput-notchedOutline': {
borderColor: 'white',
},
'&:hover .MuiOutlinedInput-notchedOutline': {
borderColor: 'white',
},
'& .MuiSvgIcon-root': {
color: 'white',
}
}}
onChange={e => {
setSelectedExercise(exerciseList.find(exercise => exercise.name === e.target.value));
}}
>
{exerciseList.map((exercise) => (
<MenuItem
key={exercise.id}
value={exercise.name}
sx={{
color: "black", // Set text color to black for exercises
backgroundColor: "white",
'&:hover': {
backgroundColor: "#f0f0f0",
}
}}
>
{exercise.name}
</MenuItem>
))}
</Select>
)}
</td>
<td>
{selectedExercise.weight}
{selectedExercise.weight || 0}
</td>
<td>
{selectedExercise.reps}
{selectedExercise.reps || 0}
</td>
<td>
{selectedExercise.setsGoal}
{selectedExercise.setsGoal || 0}
</td>
<td>
0
</td>

<td><button className={`${buttons.button} ${buttons.editButton}`} onClick={cancelAddExercise}>Remove</button></td>
<td><button className={`${buttons.button} ${styles.addButton}`} onClick={() => addExercise(selectedExercise)}>Add</button></td>
<td>
<button
className={`${buttons.button} ${buttons.editButton}`}
onClick={cancelAddExercise}
>
Remove
</button>
</td>
<td>
<button
className={`${buttons.button} ${styles.addButton}`}
onClick={() => addExercise(selectedExercise)}
disabled={exerciseList.length === 0 || selectedExercise.name === "No exercises added"}
>
Add
</button>
</td>
</tr>
)
}
);
};

export default ExerciseAdder;
8 changes: 4 additions & 4 deletions fitness_tracker/src/components/ExercisesDisplay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ const ExercisesDisplay = ({ exercises, setExercises }) => {

const logWorkout = () => {
// Calculate the score of the workout
let score = 0
let volumeScore = 0
exercises.forEach((exercise, index )=> {

score += (( Number(setsLogged[index]) / Number(exercise.setsGoal)) * Number(exercise.weight))
volumeScore += (( Number(setsLogged[index]) / Number(exercise.setsGoal)) * Number(exercise.weight) * Number(exercise.reps))
})

score = Math.round(score)
volumeScore = Math.round(volumeScore)

// Create workout in the database with only score and date
axios.post("http://localhost:4001/workout", { score: score, date: new Date() }, { withCredentials: true })
axios.post("http://localhost:4001/workout", { score: volumeScore, date: new Date() }, { withCredentials: true })
.then((response) => {
console.log("Workout created", response.data)

Expand Down
Loading

0 comments on commit d272fb4

Please sign in to comment.