-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fce6e6b
commit 42e1ebc
Showing
3 changed files
with
18 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import axios from 'axios'; | ||
|
||
const Statistics = () => { | ||
const Statistics = ({ currentUser }) => { | ||
const [data, setData] = useState([]); | ||
|
||
useEffect(() => { | ||
const url = 'http://localhost:5050/stats'; | ||
|
||
axios.get(url) | ||
.then(response => { | ||
setData(response.data.stats); | ||
const userData = response.data.stats.find(user => user.username === currentUser); | ||
setData(userData ? userData.exercises : []); | ||
}) | ||
.catch(error => { | ||
console.error('There was an error fetching the data!', error); | ||
}); | ||
}, []); | ||
}, [currentUser]); | ||
|
||
return ( | ||
<div> | ||
{data && data.length > 0 ? ( | ||
data.map((item, index) => ( | ||
<div key={index}> | ||
<p>Exercise Type: {item._id}</p> | ||
<p>Total Duration: {item.duration}</p> | ||
<p>Exercise Type: {item.exerciseType}</p> | ||
<p>Total Duration: {item.totalDuration}</p> | ||
</div> | ||
)) | ||
) : ( | ||
<p>No data available</p> | ||
<p>No data available for {currentUser}</p> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Statistics; | ||
export default Statistics; |