mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 14:38:45 +00:00
Fix warnings + Improve CallTimer
This commit is contained in:
1 parent
0d356c7930
commit
892acd2f59
6 files changed
+24
-39
No files matched your search
@@ -2,7 +2,6 @@ import { useRecoilValue } from 'recoil';
|
||||
import { contactsState } from './state';
|
||||
|
||||
import { ContactProps } from '../../../common/typings/contact';
|
||||
import { useCall } from '../../../modal/hooks/useCall';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
interface IUseContacts {
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import React, { ChangeEvent, useState } from 'react';
|
||||
import { BottomNavigation, BottomNavigationAction } from '@material-ui/core';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faHome } from '@fortawesome/free-solid-svg-icons';
|
||||
import AddCircleIcon from '@material-ui/icons/AddCircle';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { makeStyles, Theme } from '@material-ui/core/styles';
|
||||
import PhoneCallbackIcon from '@material-ui/icons/PhoneCallback';
|
||||
import PhoneIcon from '@material-ui/icons/Phone';
|
||||
import { History } from '@material-ui/icons';
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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,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 {
|
||||
|
||||
@@ -53,5 +53,5 @@ export const useNuiEvent = (
|
||||
window.addEventListener(eventName, eventListener, opts);
|
||||
// Remove Event Listener on component cleanup
|
||||
return () => window.removeEventListener(eventName, eventListener, opts);
|
||||
}, [app, method, capture, passive, once]);
|
||||
}, [app, method, capture, passive, once, currentState]);
|
||||
};
|
||||
Reference in new issue
Block a user