import React from 'react' import {connect} from 'react-redux' import LoadingIndicator from 'components/loading-indicator/small' class Indicator extends React.Component { constructor(props) { super(props); this.state = { displayMessages: 0, }; } isLoading(props) { return (props.receivedLoading || props.filteredLoading || props.notExportedLoading); } startTimer() { if (!this.timer) { this.timer = setInterval( () => this.tickMessages(), 1000 ); } } stopTimer() { if (this.timer) { clearInterval(this.timer); } this.timer = null; } componentDidMount() { this.startTimer(); } componentWillUnmount() { this.stopTimer(); } componentDidUpdate(prevProps) { if (this.isLoading(this.props) != this.isLoading(prevProps)) { if (!this.isLoading(this.props)) { // Stop timer this.setState({displayMessages: 0}); this.stopTimer(); } else { this.setState({displayMessages: 0}); this.startTimer(); } } } tickMessages() { this.setState((prevState, props) => ({ displayMessages: prevState.displayMessages + 1 })); } render() { if (!this.isLoading(this.props)) { return null; } return (
> Still loading routes, please be patient.
> This seems to take a while...
} {this.state.displayMessages >= 20 &&> This usually only happens when there are really many routes!
Please stand by a bit longer.
> This is taking really long...
} {this.state.displayMessages >= 40 &&> I heared there will be cake if you keep on waiting just a bit longer!
} {this.state.displayMessages >= 60 &&> I guess the cake was a lie.
}