mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 22:16:54 +00:00
Prettified Code!
This commit is contained in:
1 parent
8472309436
commit
08d848054e
1 file changed
+29
-20
@@ -1,25 +1,26 @@
|
||||
import React, { useState, useCallback, useEffect } from 'react'
|
||||
import React, { useState, useCallback, useEffect } from 'react';
|
||||
import { useDuration } from '../hooks/useDuration';
|
||||
|
||||
function CallTimer({ isAccepted }) {
|
||||
const { duration, setDuration } = useDuration()
|
||||
const { duration, setDuration } = useDuration();
|
||||
|
||||
useEffect(() => {
|
||||
let timer;
|
||||
if (isAccepted) {
|
||||
run()
|
||||
timer = setInterval(run, 10)
|
||||
run();
|
||||
timer = setInterval(run, 10);
|
||||
} else {
|
||||
clearInterval(timer)
|
||||
clearInterval(timer);
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
|
||||
let updatedMs = duration.ms, updatedS = duration.s, updatedM = duration.m, updatedH = duration.h;
|
||||
let updatedMs = duration.ms,
|
||||
updatedS = duration.s,
|
||||
updatedM = duration.m,
|
||||
updatedH = duration.h;
|
||||
|
||||
if (!duration) return null;
|
||||
|
||||
|
||||
const run = () => {
|
||||
if (updatedM === 60) {
|
||||
updatedH++;
|
||||
@@ -34,19 +35,27 @@ function CallTimer({ isAccepted }) {
|
||||
updatedMs = 0;
|
||||
}
|
||||
updatedMs++;
|
||||
return setDuration({ ms: updatedMs, s: updatedS, m: updatedM, h: updatedH })
|
||||
}
|
||||
|
||||
return setDuration({
|
||||
ms: updatedMs,
|
||||
s: updatedS,
|
||||
m: updatedM,
|
||||
h: updatedH,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
textAlign: 'center',
|
||||
marginTop: '2em',
|
||||
fontSize: 30
|
||||
}}>
|
||||
<span>{(duration.h >= 10) ? duration.h : '0'+duration.h}</span> :
|
||||
<span>{(duration.m >= 10) ? duration.m : '0'+duration.m}</span> :
|
||||
<span>{(duration.s >= 10) ? duration.s : '0'+duration.s}</span>
|
||||
<div
|
||||
style={{
|
||||
textAlign: 'center',
|
||||
marginTop: '2em',
|
||||
fontSize: 30,
|
||||
}}
|
||||
>
|
||||
<span>{duration.h >= 10 ? duration.h : '0' + duration.h}</span>
|
||||
:
|
||||
<span>{duration.m >= 10 ? duration.m : '0' + duration.m}</span>
|
||||
:
|
||||
<span>{duration.s >= 10 ? duration.s : '0' + duration.s}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user