fix stats graph on refresh
This commit is contained in:
		@@ -9,14 +9,19 @@ import StatsChart from './StatsChart'
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class Statistics extends React.PureComponent {
 | 
					class Statistics extends React.PureComponent {
 | 
				
			||||||
  componentDidMount() {
 | 
					  componentDidMount() {
 | 
				
			||||||
    this.props.loadActivities(
 | 
					    this.updateData()
 | 
				
			||||||
      this.props.user.id,
 | 
					 | 
				
			||||||
      this.props.statsParams,
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  componentDidUpdate(prevProps) {
 | 
					  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.loadActivities(
 | 
				
			||||||
        this.props.user.id,
 | 
					        this.props.user.id,
 | 
				
			||||||
        this.props.statsParams,
 | 
					        this.props.statsParams,
 | 
				
			||||||
@@ -26,19 +31,11 @@ class Statistics extends React.PureComponent {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  render() {
 | 
					  render() {
 | 
				
			||||||
    const { displayedSports, sports, statistics, statsParams } = this.props
 | 
					    const { displayedSports, sports, statistics, statsParams } = this.props
 | 
				
			||||||
 | 
					    if (Object.keys(statistics).length === 0) {
 | 
				
			||||||
 | 
					      return 'No workouts'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    const stats = formatStats(statistics, sports, statsParams, displayedSports)
 | 
					    const stats = formatStats(statistics, sports, statsParams, displayedSports)
 | 
				
			||||||
    return (
 | 
					    return (<StatsChart sports={sports} stats={stats} />)
 | 
				
			||||||
      <>
 | 
					 | 
				
			||||||
        {Object.keys(statistics).length === 0 ? (
 | 
					 | 
				
			||||||
          'No workouts'
 | 
					 | 
				
			||||||
        ) : (
 | 
					 | 
				
			||||||
          <StatsChart
 | 
					 | 
				
			||||||
            sports={sports}
 | 
					 | 
				
			||||||
            stats={stats}
 | 
					 | 
				
			||||||
          />
 | 
					 | 
				
			||||||
          )}
 | 
					 | 
				
			||||||
      </>
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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) {
 | 
					  handleOnChangeDuration(e) {
 | 
				
			||||||
    const duration = e.target.value
 | 
					    const duration = e.target.value
 | 
				
			||||||
    const date = new Date()
 | 
					    const date = new Date()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user