mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-02 22:17:39 +00:00
Merge pull request #67 from project-error/fix/warnings-and-call-timer
Fix warnings + Improve CallTimer
This commit is contained in:
15 files changed
+103
-72
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, {useEffect} from 'react';
|
||||
import { Box, Button } from '@material-ui/core';
|
||||
import useStyles from './grid.styles';
|
||||
import { usePhotos } from '../../hooks/usePhotos';
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -7,9 +7,10 @@ import { useApp } from '../../../os/apps/hooks/useApps';
|
||||
import AlertBar from './AlertBar';
|
||||
import MessageGroupModal from './modal/MessageGroupModal';
|
||||
import MessagesList from './list/MessagesList';
|
||||
import { Route, Switch } from 'react-router-dom';
|
||||
import { Route, Switch, useHistory } from 'react-router-dom';
|
||||
import { MessageModal } from './modal/MessageModal';
|
||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||
import NewMessageGroupButton from './buttons/NewMessageGroupButton';
|
||||
|
||||
InjectDebugData([
|
||||
{
|
||||
@@ -47,6 +48,7 @@ InjectDebugData([
|
||||
|
||||
export const MessagesApp = () => {
|
||||
const messages = useApp('MESSAGES');
|
||||
const history = useHistory();
|
||||
return (
|
||||
<AppWrapper id='messages-app'>
|
||||
<AppTitle app={messages} />
|
||||
@@ -59,7 +61,17 @@ export const MessagesApp = () => {
|
||||
/>
|
||||
</Switch>
|
||||
<Switch>
|
||||
<Route path='/messages' component={MessagesList} />
|
||||
<Route
|
||||
path='/messages'
|
||||
render={() => (
|
||||
<>
|
||||
<MessagesList />
|
||||
<NewMessageGroupButton
|
||||
onClick={() => history.push('/messages/new')}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
<Route exact path='/messages/new' component={MessageGroupModal} />
|
||||
</Switch>
|
||||
</AppContent>
|
||||
|
||||
@@ -8,7 +8,6 @@ import MessageSearch from './MessageSearch';
|
||||
import MessageGroupItem from './MessageGroupItem';
|
||||
import useStyles from './list.styles';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import NewMessageGroupButton from '../buttons/NewMessageGroupButton';
|
||||
|
||||
const MessagesList = (): any => {
|
||||
const classes = useStyles();
|
||||
@@ -61,7 +60,6 @@ const MessagesList = (): any => {
|
||||
/>
|
||||
))}
|
||||
</List>
|
||||
<NewMessageGroupButton onClick={() => history.push('/messages/new')} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -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,48 +1,45 @@
|
||||
import React, { useState, useCallback, useEffect } from 'react';
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { useDuration } from '../hooks/useDuration';
|
||||
|
||||
|
||||
const runTimer = (updatedTime, setDuration) => {
|
||||
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);
|
||||
}
|
||||
|
||||
function CallTimer({ isAccepted }) {
|
||||
const { duration, setDuration } = useDuration();
|
||||
const updatedTime = useRef({ ms: 0, s: 0, m: 0, h: 0 });
|
||||
const timer = useRef(null)
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
let timer;
|
||||
if (isAccepted) {
|
||||
run();
|
||||
timer = setInterval(run, 10);
|
||||
runTimer(updatedTime, setDuration)
|
||||
timer.current = setInterval(() => {
|
||||
runTimer(updatedTime, setDuration)
|
||||
}, 10);
|
||||
} else {
|
||||
clearInterval(timer);
|
||||
clearInterval(timer.current);
|
||||
timer.current = null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
let updatedMs = duration.ms,
|
||||
updatedS = duration.s,
|
||||
updatedM = duration.m,
|
||||
updatedH = duration.h;
|
||||
return () => clearInterval(timer.current)
|
||||
}, [isAccepted, setDuration]);
|
||||
|
||||
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 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, {useEffect} from 'react';
|
||||
import { useConfig } from '../../../config/hooks/useConfig';
|
||||
import {
|
||||
blue,
|
||||
@@ -38,6 +38,23 @@ import { ExampleApp } from '../../../apps/example/components/ExampleApp';
|
||||
import { SelloutApp } from '../../../apps/sellout/components/SelloutApp';
|
||||
import { NotesApp } from '../../../apps/notes/NotesApp';
|
||||
import CameraApp from '../../../apps/camera/components/CameraApp';
|
||||
import Nui from "../../nui-events/utils/Nui";
|
||||
|
||||
const AppWithStartup = ({ children, id }) => {
|
||||
useEffect(() => {
|
||||
Nui.send(`phone:app:${id}`);
|
||||
}, []);
|
||||
return children;
|
||||
};
|
||||
|
||||
const AppRoute = ({ id, component: Component, ...rest }) => {
|
||||
return (
|
||||
<Route
|
||||
{...rest}
|
||||
render={() => <AppWithStartup id={id}><Component /></AppWithStartup>}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const appsState = atom({
|
||||
key: 'apps',
|
||||
@@ -50,7 +67,7 @@ const appsState = atom({
|
||||
backgroundColor: green[600],
|
||||
color: common.white,
|
||||
path: '/phone',
|
||||
Route: () => <Route path='/phone' component={DialerApp} />,
|
||||
Route: () => <AppRoute id="DIALER" path='/phone' component={DialerApp} />,
|
||||
},
|
||||
{
|
||||
id: 'MESSAGES',
|
||||
@@ -60,7 +77,7 @@ const appsState = atom({
|
||||
color: common.white,
|
||||
path: '/messages',
|
||||
sharePath: '/messages/new',
|
||||
Route: () => <Route path='/messages' component={MessagesApp} />,
|
||||
Route: () => <AppRoute id="MESSAGE" path='/messages' component={MessagesApp} />,
|
||||
},
|
||||
{
|
||||
id: 'CONTACTS',
|
||||
@@ -69,7 +86,7 @@ const appsState = atom({
|
||||
backgroundColor: blue[500],
|
||||
color: common.white,
|
||||
path: '/contacts',
|
||||
Route: () => <Route path='/contacts' component={ContactsApp} />,
|
||||
Route: () => <AppRoute id="CONTACTS" path='/contacts' component={ContactsApp} />,
|
||||
},
|
||||
{
|
||||
id: 'CALCULATOR',
|
||||
@@ -78,7 +95,7 @@ const appsState = atom({
|
||||
backgroundColor: purple[500],
|
||||
color: grey[50],
|
||||
path: '/calculator',
|
||||
Route: () => <Route path='/calculator' component={CalculatorApp} />,
|
||||
Route: () => <AppRoute id="CALCULATOR" path='/calculator' component={CalculatorApp} />,
|
||||
},
|
||||
{
|
||||
id: 'SETTINGS',
|
||||
@@ -87,7 +104,7 @@ const appsState = atom({
|
||||
backgroundColor: '#383838',
|
||||
color: grey[50],
|
||||
path: '/settings',
|
||||
Route: () => <Route path='/settings' component={SettingsApp} />,
|
||||
Route: () => <AppRoute id="SETTINGS" path='/settings' component={SettingsApp} />,
|
||||
},
|
||||
{
|
||||
id: 'BANK',
|
||||
@@ -96,7 +113,7 @@ const appsState = atom({
|
||||
backgroundColor: blue[900],
|
||||
color: common.white,
|
||||
path: '/bank',
|
||||
Route: () => <Route path='/bank' component={BankApp} />,
|
||||
Route: () => <AppRoute id="BANK" path='/bank' component={BankApp} />,
|
||||
},
|
||||
{
|
||||
id: 'TWITTER',
|
||||
@@ -105,7 +122,7 @@ const appsState = atom({
|
||||
backgroundColor: blue[600],
|
||||
color: common.white,
|
||||
path: '/twitter',
|
||||
Route: () => <Route path='/twitter' component={TwitterApp} />,
|
||||
Route: () => <AppRoute id="TWITTER" path='/twitter' component={TwitterApp} />,
|
||||
},
|
||||
{
|
||||
id: 'SELLOUT',
|
||||
@@ -114,7 +131,7 @@ const appsState = atom({
|
||||
backgroundColor: red[500],
|
||||
color: common.white,
|
||||
path: '/sellout',
|
||||
Route: () => <Route path='/sellout' component={SelloutApp} />,
|
||||
Route: () => <AppRoute id="SELLOUT" path='/sellout' component={SelloutApp} />,
|
||||
},
|
||||
{
|
||||
id: 'NOTES',
|
||||
@@ -123,7 +140,7 @@ const appsState = atom({
|
||||
backgroundColor: yellow[800],
|
||||
color: common.white,
|
||||
path: '/notes',
|
||||
Route: () => <Route path='/notes' component={NotesApp} />,
|
||||
Route: () => <AppRoute id="NOTES" path='/notes' component={NotesApp} />,
|
||||
},
|
||||
{
|
||||
id: 'CAMERA',
|
||||
@@ -132,7 +149,7 @@ const appsState = atom({
|
||||
backgroundColor: grey['A400'],
|
||||
color: common.white,
|
||||
path: '/camera',
|
||||
Route: () => <Route path='/camera' component={CameraApp} />,
|
||||
Route: () => <AppRoute id="CAMERA" path='/camera' component={CameraApp} />,
|
||||
},
|
||||
{
|
||||
id: 'EXAMPLE',
|
||||
@@ -141,7 +158,7 @@ const appsState = atom({
|
||||
backgroundColor: blue[500],
|
||||
color: blue[50],
|
||||
path: '/example',
|
||||
Route: () => <Route path='/example' component={ExampleApp} />,
|
||||
Route: () => <AppRoute id="EXAMPLE" path='/example' component={ExampleApp}/>,
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -158,5 +175,6 @@ export const useApps = () => {
|
||||
|
||||
export const useApp = (id) => {
|
||||
const { getApp } = useApps();
|
||||
|
||||
return getApp(id);
|
||||
};
|
||||
@@ -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]);
|
||||
};
|
||||
@@ -35,12 +35,8 @@ export const AppIcon = ({ id, name, icon, backgroundColor, color }) => {
|
||||
color: color || green[400],
|
||||
});
|
||||
|
||||
const openAppCallback = () => {
|
||||
Nui.send(`phone:app:${id}`);
|
||||
};
|
||||
|
||||
return (
|
||||
<Button onClick={openAppCallback} className={classes.root}>
|
||||
<Button className={classes.root}>
|
||||
<Avatar className={classes.avatar}>
|
||||
{icon || name[0].toUpperCase()}
|
||||
</Avatar>
|
||||
|
||||
@@ -127,6 +127,10 @@ function takePhoto() {
|
||||
);
|
||||
}
|
||||
|
||||
onNet(events.CAMERA_UPLOAD_PHOTO_SUCCESS, () => {
|
||||
emitNet(events.CAMERA_FETCH_PHOTOS);
|
||||
})
|
||||
|
||||
// delete photo
|
||||
|
||||
RegisterNuiCallbackType(events.CAMERA_DELETE_PHOTO);
|
||||
|
||||
@@ -37,13 +37,18 @@ async function getPlayerFromIdentifier(identifier: string): Promise<XPlayer> {
|
||||
|
||||
async function saveCall(call: ICall) {
|
||||
const query =
|
||||
'INSERT INTO npwd_calls (transmitter, receiver, start) VALUES (?, ?, ?)';
|
||||
await pool.query(query, [call.transmitter, call.receiver, call.start]);
|
||||
'INSERT INTO npwd_calls (identifier, transmitter, receiver, start) VALUES (?, ?, ?, ?)';
|
||||
await pool.query(query, [
|
||||
call.identifier,
|
||||
call.transmitter,
|
||||
call.receiver,
|
||||
call.start,
|
||||
]);
|
||||
}
|
||||
|
||||
async function updateCall(call: ICall, isAccepted: boolean, end?: number) {
|
||||
async function updateCall(call: ICall, isAccepted: boolean, end: number) {
|
||||
const query =
|
||||
'UPDATE npwd_calls SET is_accepted, end (?, ?) WHERE identifier = ?';
|
||||
'UPDATE npwd_calls SET is_accepted=?, end=? WHERE identifier = ?';
|
||||
await pool.query(query, [isAccepted, end, call.identifier]);
|
||||
}
|
||||
|
||||
@@ -115,7 +120,7 @@ onNet(events.PHONE_ACCEPT_CALL, async (transmitterNumber: string) => {
|
||||
const currentCall = calls.get(transmitterNumber);
|
||||
const channelId = pSource;
|
||||
|
||||
await updateCall(currentCall, true);
|
||||
await updateCall(currentCall, true, null);
|
||||
|
||||
// player who is being called
|
||||
emitNet(
|
||||
|
||||
@@ -26,8 +26,14 @@ async function deletePhoto(photo: IPhoto, identifier: string) {
|
||||
}
|
||||
|
||||
onNet(events.CAMERA_UPLOAD_PHOTO, async (image: string) => {
|
||||
const identifier = await useIdentifier();
|
||||
await uploadPhoto(identifier, image);
|
||||
try {
|
||||
const pSource = (global as any).source;
|
||||
const identifier = await useIdentifier();
|
||||
await uploadPhoto(identifier, image);
|
||||
emitNet(events.CAMERA_UPLOAD_PHOTO_SUCCESS, pSource);
|
||||
} catch (error) {
|
||||
console.dir(error)
|
||||
}
|
||||
});
|
||||
|
||||
onNet(events.CAMERA_FETCH_PHOTOS, async () => {
|
||||
|
||||
@@ -88,6 +88,7 @@ export default {
|
||||
// camera
|
||||
CAMERA_TAKE_PHOTO: 'phone:TakePhoto',
|
||||
CAMERA_UPLOAD_PHOTO: 'phone:UploadPhoto',
|
||||
CAMERA_UPLOAD_PHOTO_SUCCESS: 'phone:UploadPhotoSuccess',
|
||||
CAMERA_FETCH_PHOTOS: 'phone:FetchPhotos',
|
||||
CAMERA_SEND_PHOTOS: 'phone:SendPhotos',
|
||||
CAMERA_DELETE_PHOTO: 'photo:deletePhoto',
|
||||
|
||||
Reference in new issue
Block a user