From 08d848054e729085797fdde4684f5c71e63373d3 Mon Sep 17 00:00:00 2001 From: itschip Date: Mon, 1 Feb 2021 19:16:38 +0000 Subject: [PATCH] Prettified Code! --- phone/src/modal/components/CallTimer.tsx | 49 ++++++++++++++---------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/phone/src/modal/components/CallTimer.tsx b/phone/src/modal/components/CallTimer.tsx index 8614ec2..ceea576 100644 --- a/phone/src/modal/components/CallTimer.tsx +++ b/phone/src/modal/components/CallTimer.tsx @@ -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 ( -
- {(duration.h >= 10) ? duration.h : '0'+duration.h} :  - {(duration.m >= 10) ? duration.m : '0'+duration.m} :  - {(duration.s >= 10) ? duration.s : '0'+duration.s}  +
+ {duration.h >= 10 ? duration.h : '0' + duration.h} +  :  + {duration.m >= 10 ? duration.m : '0' + duration.m} +  :  + {duration.s >= 10 ? duration.s : '0' + duration.s} 
); }