import React, { useEffect, useState } from 'react'; import cn from 'classnames'; import { observer } from 'mobx-react-lite'; import { Button } from 'antd'; import AutoplayToggle from 'Shared/AutoplayToggle'; import { useStore } from 'App/mstore'; import stl from './AutoplayTimer.module.css'; import clsOv from './overlay.module.css'; import { useTranslation } from 'react-i18next'; function AutoplayTimer({ history }: any) { const { t } = useTranslation(); let timer: NodeJS.Timer; const [cancelled, setCancelled] = useState(false); const [counter, setCounter] = useState(5); const { clipStore } = useStore(); useEffect(() => { if (counter > 0) { timer = setTimeout(() => { setCounter(counter - 1); }, 1000); } if (counter === 0) { clipStore.next(); } return () => clearTimeout(timer); }, [counter]); const cancel = () => { clearTimeout(timer); setCancelled(true); }; if (cancelled) return null; return (
{t('Autoplaying next clip in')}  {counter} {t('seconds')}
); } export default observer(AutoplayTimer);