Add initial time fraction left on time progress

This commit is contained in:
Reckless_Satoshi 2022-11-29 02:00:56 -08:00
parent 56f9c35b50
commit cc87054246
No known key found for this signature in database
GPG Key ID: 9C4585B561315571

View File

@ -8,16 +8,21 @@ interface Props {
}
const LinearDeterminate = ({ expiresAt, totalSecsExp }: Props): JSX.Element => {
const [progress, setProgress] = useState<number>(100);
const timePercentLeft = function(){
if (expiresAt && totalSecsExp){
const lapseTime = calcTimeDelta(new Date(expiresAt)).total / 1000;
return (lapseTime / totalSecsExp) * 100;
} else {
return 100;
}
}
const [progress, setProgress] = useState<number>(timePercentLeft);
useEffect(() => {
const timer = setInterval(() => {
const left = calcTimeDelta(new Date(expiresAt)).total / 1000;
const newProgress = (left / totalSecsExp) * 100;
setProgress(newProgress);
setProgress(timePercentLeft);
}, 1000);
return () => {
clearInterval(timer);
};