Fix warnings + Improve CallTimer

This commit is contained in:
J Francisco Rader committed 2021-02-06 16:36:14 -05:00
1 parent 40f9555b39
commit 51d31ee122
6 files changed
+24 -39

No files matched your search

+2 -3
View File
@@ -1,7 +1,6 @@
import React, { useState } from 'react';
import { Button, Fab } from '@material-ui/core';
import React from 'react';
import { Fab } from '@material-ui/core';
import { AppWrapper } from '../../ui/components/AppWrapper';
import { AppTitle } from '../../ui/components/AppTitle';
import { AppContent } from '../../ui/components/AppContent';
import { useCall } from '../hooks/useCall';
import CallIcon from '@material-ui/icons/Call';
+20 -29
View File
@@ -1,8 +1,26 @@
import React, { useState, useCallback, useEffect } from 'react';
import React, { useCallback, useEffect, useRef } from 'react';
import { useDuration } from '../hooks/useDuration';
function CallTimer({ isAccepted }) {
const { duration, setDuration } = useDuration();
const updatedTime = useRef({ ms: 0, s: 0, m: 0, h: 0 });
const run = useCallback(() => {
let newTime = { ...updatedTime.current };
if (newTime.m >= 60) {
newTime = { ...newTime, h: newTime.h + 1, m: 0 };
}
if (newTime.s >= 60) {
newTime = { ...newTime, m: newTime.m + 1, s: 0 };
}
if (newTime.ms >= 100) {
newTime = { ...newTime, s: newTime.s + 1, ms: 0 };
}
newTime = { ...newTime, ms: newTime.ms + 1 };
updatedTime.current = newTime;
setDuration(newTime);
}, [setDuration]);
useEffect(() => {
let timer;
@@ -12,37 +30,10 @@ function CallTimer({ isAccepted }) {
} else {
clearInterval(timer);
}
}, []);
let updatedMs = duration.ms,
updatedS = duration.s,
updatedM = duration.m,
updatedH = duration.h;
}, [isAccepted, run]);
if (!duration) return null;
const run = () => {
if (updatedM === 60) {
updatedH++;
updatedM = 0;
}
if (updatedS === 60) {
updatedM++;
updatedS = 0;
}
if (updatedMs === 100) {
updatedS++;
updatedMs = 0;
}
updatedMs++;
return setDuration({
ms: updatedMs,
s: updatedS,
m: updatedM,
h: updatedH,
});
};
return (
<div
style={{
+1 -1
View File
@@ -1,5 +1,5 @@
import { useRecoilState } from 'recoil';
import { CallProps, ICallDuration } from '../../common/typings/call';
import { CallProps } from '../../common/typings/call';
import { callerState } from './state';
interface CallHook {