diff --git a/fittrackee_client/src/components/Common/Stats/index.jsx b/fittrackee_client/src/components/Common/Stats/index.jsx
index 566fc4ee..fc67ef6e 100644
--- a/fittrackee_client/src/components/Common/Stats/index.jsx
+++ b/fittrackee_client/src/components/Common/Stats/index.jsx
@@ -9,14 +9,19 @@ import StatsChart from './StatsChart'
class Statistics extends React.PureComponent {
componentDidMount() {
- this.props.loadActivities(
- this.props.user.id,
- this.props.statsParams,
- )
+ this.updateData()
}
componentDidUpdate(prevProps) {
- if (this.props.statsParams !== prevProps.statsParams) {
+ if ((this.props.user.id && (this.props.user.id !== prevProps.user.id)) ||
+ this.props.statsParams !== prevProps.statsParams
+ ) {
+ this.updateData()
+ }
+ }
+
+ updateData() {
+ if (this.props.user.id) {
this.props.loadActivities(
this.props.user.id,
this.props.statsParams,
@@ -26,19 +31,11 @@ class Statistics extends React.PureComponent {
render() {
const { displayedSports, sports, statistics, statsParams } = this.props
+ if (Object.keys(statistics).length === 0) {
+ return 'No workouts'
+ }
const stats = formatStats(statistics, sports, statsParams, displayedSports)
- return (
- <>
- {Object.keys(statistics).length === 0 ? (
- 'No workouts'
- ) : (
-
- )}
- >
- )
+ return ()
}
}
diff --git a/fittrackee_client/src/components/Statistics/index.jsx b/fittrackee_client/src/components/Statistics/index.jsx
index 6406f0e8..2766c13f 100644
--- a/fittrackee_client/src/components/Statistics/index.jsx
+++ b/fittrackee_client/src/components/Statistics/index.jsx
@@ -30,6 +30,17 @@ class Statistics extends React.Component {
}
}
+ componentDidUpdate(prevProps) {
+ if (this.props.sports !== prevProps.sports) {
+ this.updateDisplayedSports()
+ }
+ }
+
+ updateDisplayedSports() {
+ const { sports } = this.props
+ this.setState({ displayedSports: sports.map(sport => sport.id) })
+ }
+
handleOnChangeDuration(e) {
const duration = e.target.value
const date = new Date()