mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
Prettified Code!
This commit is contained in:
1 parent
8472309436
commit
08d848054e
1 file changed
+28
-19
@@ -1,22 +1,23 @@
|
|||||||
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;
|
||||||
|
|
||||||
@@ -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> :
|
}}
|
||||||
<span>{(duration.m >= 10) ? duration.m : '0'+duration.m}</span> :
|
>
|
||||||
<span>{(duration.s >= 10) ? duration.s : '0'+duration.s}</span>
|
<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>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user