import React from 'react'; import PropTypes from 'prop-types'; import { withStyles } from '@material-ui/core/styles'; import { Fade, Button, CircularProgress, Typography } from '@material-ui/core'; const styles = theme => ({ root: { display: 'flex', flexDirection: 'column', alignItems: 'center', }, button: { margin: theme.spacing(2), }, placeholder: { height: 40, }, }); class ProgressDelay extends React.Component { state = { loading: false, query: 'idle', }; componentWillUnmount() { clearTimeout(this.timer); } timer = null; handleClickLoading = () => { this.setState({ loading: !this.state.loading, }); }; handleClickQuery = () => { clearTimeout(this.timer); if (this.state.query !== 'idle') { this.setState({ query: 'idle', }); return; } this.setState({ query: 'progress', }); this.timer = setTimeout(() => { this.setState({ query: 'success', }); }, 2e3); }; render() { const { classes } = this.props; const { loading, query } = this.state; return (
{query === 'success' ? ( Success! ) : ( )}
); } } ProgressDelay.propTypes = { classes: PropTypes.object.isRequired, }; export default withStyles(styles)(ProgressDelay);