Prettified Code!

This commit is contained in:
itschip authored and GitHub Action committed 2021-02-01 19:16:38 +00:00
1 parent 8472309436
commit 08d848054e
1 file changed
+29 -20
+29 -20
View File
@@ -1,25 +1,26 @@
import React, { useState, useCallback, useEffect } from 'react' import React, { useState, useCallback, useEffect } from 'react';
import { useDuration } from '../hooks/useDuration'; import { useDuration } from '../hooks/useDuration';
function CallTimer({ isAccepted }) { function CallTimer({ isAccepted }) {
const { duration, setDuration } = useDuration() const { duration, setDuration } = useDuration();
useEffect(() => { useEffect(() => {
let timer; let timer;
if (isAccepted) { if (isAccepted) {
run() run();
timer = setInterval(run, 10) timer = setInterval(run, 10);
} else { } else {
clearInterval(timer) clearInterval(timer);
} }
}, []); }, []);
let updatedMs = duration.ms,
updatedS = duration.s,
let updatedMs = duration.ms, updatedS = duration.s, updatedM = duration.m, updatedH = duration.h; updatedM = duration.m,
updatedH = duration.h;
if (!duration) return null; if (!duration) return null;
const run = () => { const run = () => {
if (updatedM === 60) { if (updatedM === 60) {
updatedH++; updatedH++;
@@ -34,19 +35,27 @@ function CallTimer({ isAccepted }) {
updatedMs = 0; updatedMs = 0;
} }
updatedMs++; updatedMs++;
return setDuration({ ms: updatedMs, s: updatedS, m: updatedM, h: updatedH }) return setDuration({
} ms: updatedMs,
s: updatedS,
m: updatedM,
h: updatedH,
});
};
return ( return (
<div style={{ <div
textAlign: 'center', style={{
marginTop: '2em', textAlign: 'center',
fontSize: 30 marginTop: '2em',
}}> fontSize: 30,
<span>{(duration.h >= 10) ? duration.h : '0'+duration.h}</span>&nbsp;:&nbsp; }}
<span>{(duration.m >= 10) ? duration.m : '0'+duration.m}</span>&nbsp;:&nbsp; >
<span>{(duration.s >= 10) ? duration.s : '0'+duration.s}</span>&nbsp; <span>{duration.h >= 10 ? duration.h : '0' + duration.h}</span>
&nbsp;:&nbsp;
<span>{duration.m >= 10 ? duration.m : '0' + duration.m}</span>
&nbsp;:&nbsp;
<span>{duration.s >= 10 ? duration.s : '0' + duration.s}</span>&nbsp;
</div> </div>
); );
} }