import React, { useEffect, useState } from 'react' import cn from 'classnames'; import { connect } from 'react-redux' import { withRouter, RouteComponentProps } from 'react-router-dom'; import { Button, Link } from 'UI' import { session as sessionRoute, withSiteId } from 'App/routes' import stl from './AutoplayTimer.module.css'; import clsOv from './overlay.module.css'; interface IProps extends RouteComponentProps { nextId: number; siteId: string; } function AutoplayTimer({ nextId, siteId, history }: IProps) { let timer: NodeJS.Timer const [cancelled, setCancelled] = useState(false); const [counter, setCounter] = useState(5); useEffect(() => { if(counter > 0) { timer = setTimeout(() => { setCounter(counter - 1) }, 1000) } if (counter === 0) { history.push(withSiteId(sessionRoute(nextId), siteId)) } return () => clearTimeout(timer); }, [counter]) const cancel = () => { clearTimeout(timer) setCancelled(true) } if (cancelled) return null return (