diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index 82c5b6c..fbf4df8 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -86,9 +86,9 @@ if (process.env.NODE_ENV === 'development') { method: 'setCaller', data: { accepted: false, - transmitter: false, - caller: 'Chip', - target: 'Christian', + isTransmitter: false, + transmitter: 'Chip', + receiver: 'Taso', phone_number: '860-4504', }, }, diff --git a/phone/src/modal/components/CallModal.tsx b/phone/src/modal/components/CallModal.tsx index 0910075..b3392ec 100644 --- a/phone/src/modal/components/CallModal.tsx +++ b/phone/src/modal/components/CallModal.tsx @@ -9,6 +9,7 @@ import CallEndIcon from '@material-ui/icons/CallEnd'; import useStyles from './modal.styles'; import { useModal } from '../hooks/useModal'; import Nui from '../../os/nui-events/utils/Nui'; +import CallTimer from './CallTimer'; export const CallModal = () => { const { call } = useCall(); @@ -20,7 +21,6 @@ export const CallModal = () => { Nui.send('phone:acceptCall', { transmitterNumber: call.transmitter, }); - console.log("NOW BEING TRANSMITTER", call.transmitter) }; const handleRejectCall = () => { @@ -41,7 +41,9 @@ export const CallModal = () => { return ( +

{call.receiver}

+
{

{call.transmitter}

- +
{!call.accepted ? ( <> diff --git a/phone/src/modal/components/CallTimer.tsx b/phone/src/modal/components/CallTimer.tsx new file mode 100644 index 0000000..38c8cdf --- /dev/null +++ b/phone/src/modal/components/CallTimer.tsx @@ -0,0 +1,49 @@ +import React, { useState, useCallback, useEffect } from 'react' + +function CallTimer({ isAccepted }) { + const [time, setTime] = useState({ ms: 0, s: 0, m: 0, h: 0 }) + + useEffect(() => { + let timer = null + if (isAccepted) { + run() + timer = setInterval(run, 10) + } + return () => clearInterval(timer) + }, []); + + let updatedMs = time.ms, updatedS = time.s, updatedM = time.m, updatedH = time.h; + + const run = () => { + if (updatedM === 60) { + updatedH++; + updatedM = 0; + } + if (updatedS === 60) { + updatedM++; + updatedS = 0; + } + if (updatedMs === 100) { + updatedS++; + updatedMs = 0 + } + updatedMs++; + return setTime({ ms: updatedMs, s: updatedS, m: updatedM, h: updatedH }) + } + + if (!isAccepted) return null; + + return ( +
+ {(time.h >= 10) ? time.h : '0'+time.h} :  + {(time.m >= 10) ? time.m : '0'+time.m} :  + {(time.s >= 10) ? time.s : '0'+time.s}  +
+ ) +} + +export default CallTimer