diff --git a/phone/src/apps/camera/components/grid/GalleryGrid.tsx b/phone/src/apps/camera/components/grid/GalleryGrid.tsx index b18d049..8cee9b5 100644 --- a/phone/src/apps/camera/components/grid/GalleryGrid.tsx +++ b/phone/src/apps/camera/components/grid/GalleryGrid.tsx @@ -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'; diff --git a/phone/src/apps/contacts/hooks/useContacts.ts b/phone/src/apps/contacts/hooks/useContacts.ts index 15df383..780e993 100644 --- a/phone/src/apps/contacts/hooks/useContacts.ts +++ b/phone/src/apps/contacts/hooks/useContacts.ts @@ -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 { diff --git a/phone/src/apps/dialer/components/DialerNavBar.tsx b/phone/src/apps/dialer/components/DialerNavBar.tsx index 3da86d9..6951e4f 100644 --- a/phone/src/apps/dialer/components/DialerNavBar.tsx +++ b/phone/src/apps/dialer/components/DialerNavBar.tsx @@ -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'; diff --git a/phone/src/apps/messages/components/MessagesApp.tsx b/phone/src/apps/messages/components/MessagesApp.tsx index 8b1b67f..2790cfa 100644 --- a/phone/src/apps/messages/components/MessagesApp.tsx +++ b/phone/src/apps/messages/components/MessagesApp.tsx @@ -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 ( @@ -59,7 +61,17 @@ export const MessagesApp = () => { /> - + ( + <> + + history.push('/messages/new')} + /> + + )} + /> diff --git a/phone/src/apps/messages/components/list/MessagesList.tsx b/phone/src/apps/messages/components/list/MessagesList.tsx index c7b09cf..1f7df94 100644 --- a/phone/src/apps/messages/components/list/MessagesList.tsx +++ b/phone/src/apps/messages/components/list/MessagesList.tsx @@ -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 => { /> ))} - history.push('/messages/new')} /> ); }; diff --git a/phone/src/modal/components/CallModal.tsx b/phone/src/modal/components/CallModal.tsx index ff33f4e..6603f33 100644 --- a/phone/src/modal/components/CallModal.tsx +++ b/phone/src/modal/components/CallModal.tsx @@ -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'; diff --git a/phone/src/modal/components/CallTimer.tsx b/phone/src/modal/components/CallTimer.tsx index ceea576..2b6414b 100644 --- a/phone/src/modal/components/CallTimer.tsx +++ b/phone/src/modal/components/CallTimer.tsx @@ -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 (
{ + useEffect(() => { + Nui.send(`phone:app:${id}`); + }, []); + return children; +}; + +const AppRoute = ({ id, component: Component, ...rest }) => { + return ( + } + /> + ); +}; const appsState = atom({ key: 'apps', @@ -50,7 +67,7 @@ const appsState = atom({ backgroundColor: green[600], color: common.white, path: '/phone', - Route: () => , + Route: () => , }, { id: 'MESSAGES', @@ -60,7 +77,7 @@ const appsState = atom({ color: common.white, path: '/messages', sharePath: '/messages/new', - Route: () => , + Route: () => , }, { id: 'CONTACTS', @@ -69,7 +86,7 @@ const appsState = atom({ backgroundColor: blue[500], color: common.white, path: '/contacts', - Route: () => , + Route: () => , }, { id: 'CALCULATOR', @@ -78,7 +95,7 @@ const appsState = atom({ backgroundColor: purple[500], color: grey[50], path: '/calculator', - Route: () => , + Route: () => , }, { id: 'SETTINGS', @@ -87,7 +104,7 @@ const appsState = atom({ backgroundColor: '#383838', color: grey[50], path: '/settings', - Route: () => , + Route: () => , }, { id: 'BANK', @@ -96,7 +113,7 @@ const appsState = atom({ backgroundColor: blue[900], color: common.white, path: '/bank', - Route: () => , + Route: () => , }, { id: 'TWITTER', @@ -105,7 +122,7 @@ const appsState = atom({ backgroundColor: blue[600], color: common.white, path: '/twitter', - Route: () => , + Route: () => , }, { id: 'SELLOUT', @@ -114,7 +131,7 @@ const appsState = atom({ backgroundColor: red[500], color: common.white, path: '/sellout', - Route: () => , + Route: () => , }, { id: 'NOTES', @@ -123,7 +140,7 @@ const appsState = atom({ backgroundColor: yellow[800], color: common.white, path: '/notes', - Route: () => , + Route: () => , }, { id: 'CAMERA', @@ -132,7 +149,7 @@ const appsState = atom({ backgroundColor: grey['A400'], color: common.white, path: '/camera', - Route: () => , + Route: () => , }, { id: 'EXAMPLE', @@ -141,7 +158,7 @@ const appsState = atom({ backgroundColor: blue[500], color: blue[50], path: '/example', - Route: () => , + Route: () => , }, ], }, @@ -158,5 +175,6 @@ export const useApps = () => { export const useApp = (id) => { const { getApp } = useApps(); + return getApp(id); }; diff --git a/phone/src/os/nui-events/hooks/useNuiEvent.ts b/phone/src/os/nui-events/hooks/useNuiEvent.ts index fa9b235..5897bf4 100644 --- a/phone/src/os/nui-events/hooks/useNuiEvent.ts +++ b/phone/src/os/nui-events/hooks/useNuiEvent.ts @@ -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]); }; diff --git a/phone/src/ui/components/AppIcon.tsx b/phone/src/ui/components/AppIcon.tsx index 0b3c10a..5bc7fae 100644 --- a/phone/src/ui/components/AppIcon.tsx +++ b/phone/src/ui/components/AppIcon.tsx @@ -35,12 +35,8 @@ export const AppIcon = ({ id, name, icon, backgroundColor, color }) => { color: color || green[400], }); - const openAppCallback = () => { - Nui.send(`phone:app:${id}`); - }; - return ( -