2022-09-09 17:18:04 +00:00
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import { Box, LinearProgress } from '@mui/material';
|
2022-05-11 11:27:11 +00:00
|
|
|
import { calcTimeDelta } from 'react-countdown';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
expiresAt: string;
|
|
|
|
totalSecsExp: number;
|
|
|
|
};
|
|
|
|
|
2022-09-09 17:18:04 +00:00
|
|
|
const LinearDeterminate = ({ expiresAt, totalSecsExp }: Props): JSX.Element => {
|
2022-05-11 11:27:11 +00:00
|
|
|
const [progress, setProgress] = useState<number>(0);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const timer = setInterval(() => {
|
|
|
|
const left = calcTimeDelta(new Date(expiresAt)).total / 1000;
|
|
|
|
const newProgress = (left / totalSecsExp) * 100;
|
|
|
|
|
|
|
|
setProgress(newProgress);
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
clearInterval(timer);
|
|
|
|
};
|
|
|
|
}, [expiresAt, totalSecsExp]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Box sx={{ width: '100%' }}>
|
2022-09-09 17:18:04 +00:00
|
|
|
<LinearProgress variant='determinate' value={progress} />
|
2022-05-11 11:27:11 +00:00
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default LinearDeterminate;
|