From 81f5e270643001d85fa7f0e3d72a3542e2eccb5e Mon Sep 17 00:00:00 2001 From: J Francisco Rader Date: Wed, 10 Feb 2021 12:04:28 -0500 Subject: [PATCH] Remove client phoneConfig event (#73) * Remove client phoneConfig event * Remove unused debug * Remove unused import * Remove unused import * Remove duplicated functions | fix useEffect dependency | etc * Fix warnings * Update phone/src/apps/twitter/components/TwitterApp.tsx Co-authored-by: Taso Co-authored-by: Taso --- phone/package.json | 5 +- phone/src/Phone.tsx | 55 +++---------------- .../camera/components/grid/GalleryGrid.tsx | 2 +- phone/src/apps/notes/modal/NoteModal.tsx | 2 +- .../twitter/components/images/ImagePrompt.tsx | 9 ++- .../apps/twitter/hooks/useTwitterService.ts | 11 +--- phone/src/common/typings/config.ts | 2 +- phone/src/config.autogen.json | 33 +++++++++++ phone/src/os/apps/hooks/useApps.tsx | 2 +- phone/src/os/phone/hooks/usePhone.ts | 8 +-- phone/src/ui/components/AppIcon.tsx | 1 - resources/client/cl_main.ts | 12 ---- 12 files changed, 61 insertions(+), 81 deletions(-) create mode 100644 phone/src/config.autogen.json diff --git a/phone/package.json b/phone/package.json index 834dbe5..02eeb07 100644 --- a/phone/package.json +++ b/phone/package.json @@ -75,10 +75,11 @@ "webpack-cli": "^3.3.12" }, "scripts": { - "start": "react-scripts start", + "copy:config": "cp ../config.json ./src/config.autogen.json", + "start": "yarn copy:config && react-scripts start", "watch": "cra-build-watch --disable-chunks --build-path ../resources/html --output-filename dev.js", "format": "prettier --write src/**/*.{js,jsx,ts,tsx,json,css,scss,md}", - "build": "cross-env NODE_ENV=production webpack --config webpack/webpack.resources.js --color -p --progress --hide-modules --display-optimization-bailout", + "build": "yarn copy:config && cross-env NODE_ENV=production webpack --config webpack/webpack.resources.js --color -p --progress --hide-modules --display-optimization-bailout", "test": "react-scripts test --watchAll=false --testMatch **/src/**/*.test.{ts,js,tsx}", "test:watch": "react-scripts test --watchAll --testMatch **/src/**/*.test.{ts,js,tsx}", "eject": "react-scripts eject", diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index 547f0c0..ebcbf47 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -1,7 +1,7 @@ import React, { useMemo } from 'react'; import './Phone.css'; import './i18n'; -import { Route, useHistory } from 'react-router-dom'; +import { Route } from 'react-router-dom'; import { CallModal } from './modal/components/CallModal'; import { HomeApp } from './apps/home/components/Home'; import { createMuiTheme, ThemeProvider } from '@material-ui/core'; @@ -33,51 +33,6 @@ import { useDialService } from './apps/dialer/hooks/useDialService'; import InjectDebugData from './os/debug/InjectDebugData'; import { useQuickAccess } from './os/notifications/hooks/useQuickAccess'; -InjectDebugData([ - { - app: 'PHONE', - method: 'phoneConfig', - data: { - Locale: 'en', - KeyTogglePhone: 288, - KeyTakeCall: 38, - PhoneAsItem: false, - SwimDestroy: false, - RunRate: 10, - DestoryChance: 100, - DestroyPhoneReCheck: 3, - notificationPosition: { - horizontal: 'right', - vertical: 'top', - }, - general: { - useDashNumber: true, - }, - twitter: { - showNotifications: true, - generateProfileNameFromUsers: true, - allowEdtiableProfileName: true, - allowDeleteTweets: true, - allowReportTweets: true, - characterLimit: 160, - newLineLimit: 10, - enableAvatars: true, - enableEmojis: true, - enableImages: true, - maxImages: 3, - }, - bank: { - showNotifications: true, - }, - }, - }, - { - app: 'PHONE', - method: 'setVisibility', - data: true, - }, -]); - function Phone() { const quickAccess = useQuickAccess(); useNuiService(); @@ -173,3 +128,11 @@ function Phone() { } export default Phone; + +InjectDebugData([ + { + app: 'PHONE', + method: 'setVisibility', + data: true, + }, +]); diff --git a/phone/src/apps/camera/components/grid/GalleryGrid.tsx b/phone/src/apps/camera/components/grid/GalleryGrid.tsx index 8cee9b5..b18d049 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, {useEffect} from 'react'; +import React 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/notes/modal/NoteModal.tsx b/phone/src/apps/notes/modal/NoteModal.tsx index 7867d2a..08d099e 100644 --- a/phone/src/apps/notes/modal/NoteModal.tsx +++ b/phone/src/apps/notes/modal/NoteModal.tsx @@ -1,5 +1,5 @@ import { Button, TextField, Slide } from '@material-ui/core'; -import React, { useState, useEffect } from 'react'; +import React, { useState } from 'react'; import ArrowBackIcon from '@material-ui/icons/ArrowBack'; import { useNoteModal } from '../hooks/useNoteModal'; diff --git a/phone/src/apps/twitter/components/images/ImagePrompt.tsx b/phone/src/apps/twitter/components/images/ImagePrompt.tsx index 8ad2db9..a1b8001 100644 --- a/phone/src/apps/twitter/components/images/ImagePrompt.tsx +++ b/phone/src/apps/twitter/components/images/ImagePrompt.tsx @@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next'; import { makeStyles } from '@material-ui/core/styles'; import { TextField } from '@material-ui/core'; -const useStyles = makeStyles((theme) => ({ +const useStyles = makeStyles({ textField: { flex: '1 1 100%', padding: '10px 15px', @@ -12,7 +12,7 @@ const useStyles = makeStyles((theme) => ({ textFieldInput: { fontSize: '22px', }, -})); +}); export const ImagePrompt = ({ visible, value, handleChange }) => { const textFieldRef = useRef(null); @@ -23,7 +23,10 @@ export const ImagePrompt = ({ visible, value, handleChange }) => { textFieldRef.current && textFieldRef.current.focus(); }, [visible]); - const handleImageChange = useCallback(e => handleChange(e.target.value), []); + const handleImageChange = useCallback( + (e) => handleChange(e.target.value), + [handleChange] + ); if (!visible) return null; return ( diff --git a/phone/src/apps/twitter/hooks/useTwitterService.ts b/phone/src/apps/twitter/hooks/useTwitterService.ts index 8b794c9..0af8c1e 100644 --- a/phone/src/apps/twitter/hooks/useTwitterService.ts +++ b/phone/src/apps/twitter/hooks/useTwitterService.ts @@ -43,9 +43,6 @@ export const useTwitterService = () => { ); const setNotification = useSetRecoilState(twitterState.notification); - const _setProfile = (profile) => { - setProfile(profile); - }; const _setUpdateProfileSuccess = (isSuccessful) => { setUpdateProfileSuccess(isSuccessful); setUpdateProfileLoading(false); // on any result we should set loading to false @@ -56,10 +53,6 @@ export const useTwitterService = () => { setCreateLoading(false); }; - const _setNotification = (tweet) => { - setNotification(tweet); - }; - const _setTweets = (tweets) => { setTweets(tweets.map(processTweet)); }; @@ -67,12 +60,12 @@ export const useTwitterService = () => { setFilteredTweets(tweets.map(processTweet)); }; - useNuiEvent(APP_TWITTER, 'getOrCreateTwitterProfile', _setProfile); + useNuiEvent(APP_TWITTER, 'getOrCreateTwitterProfile', setProfile); useNuiEvent(APP_TWITTER, 'updateProfileLoading', setUpdateProfileLoading); useNuiEvent(APP_TWITTER, 'updateProfileResult', _setUpdateProfileSuccess); useNuiEvent(APP_TWITTER, 'fetchTweets', _setTweets); useNuiEvent(APP_TWITTER, 'fetchTweetsFiltered', _setFilteredTweets); useNuiEvent(APP_TWITTER, 'createTweetLoading', setCreateLoading); useNuiEvent(APP_TWITTER, 'createTweetResult', _setCreateSuccess); - useNuiEvent(APP_TWITTER, 'createTweetBroadcast', _setNotification); + useNuiEvent(APP_TWITTER, 'createTweetBroadcast', setNotification); }; diff --git a/phone/src/common/typings/config.ts b/phone/src/common/typings/config.ts index 847d338..3ff10c3 100644 --- a/phone/src/common/typings/config.ts +++ b/phone/src/common/typings/config.ts @@ -25,7 +25,7 @@ interface BankConfig { showNotifications: boolean; } -export interface ServerConfig { +export interface IServerConfig { Locale: string; KeyTogglePhone: number; KeyTakeCall: number; diff --git a/phone/src/config.autogen.json b/phone/src/config.autogen.json new file mode 100644 index 0000000..49e47a6 --- /dev/null +++ b/phone/src/config.autogen.json @@ -0,0 +1,33 @@ +{ + "Locale": "en", + "KeyTogglePhone": 288, + "KeyTakeCall": 38, + "PhoneAsItem": false, + "SwimDestroy": false, + "RunRate": 10, + "DestoryChance": 100, + "DestroyPhoneReCheck": 3, + "notificationPosition": { + "horizontal": "right", + "vertical": "top" + }, + "general": { + "useDashNumber": true + }, + "twitter": { + "showNotifications": true, + "generateProfileNameFromUsers": true, + "allowEdtiableProfileName": true, + "allowDeleteTweets": true, + "allowReportTweets": true, + "characterLimit": 160, + "newLineLimit": 10, + "enableAvatars": true, + "enableEmojis": true, + "enableImages": true, + "maxImages": 3 + }, + "bank": { + "showNotifications": true + } + } \ No newline at end of file diff --git a/phone/src/os/apps/hooks/useApps.tsx b/phone/src/os/apps/hooks/useApps.tsx index 28d319d..fdfbe24 100644 --- a/phone/src/os/apps/hooks/useApps.tsx +++ b/phone/src/os/apps/hooks/useApps.tsx @@ -55,7 +55,7 @@ type AppsRepository = { preinstalled: IAppConfig[] }; const AppWithStartup = ({ children, id }) => { useEffect(() => { Nui.send(`phone:app:${id}`); - }, []); + }, [id]); return children; }; diff --git a/phone/src/os/phone/hooks/usePhone.ts b/phone/src/os/phone/hooks/usePhone.ts index 42dff45..675944e 100644 --- a/phone/src/os/phone/hooks/usePhone.ts +++ b/phone/src/os/phone/hooks/usePhone.ts @@ -1,14 +1,14 @@ import { useRecoilValue } from 'recoil'; import { phoneState } from './state'; -import { ServerConfig } from '../../../common/typings/config'; +import { IServerConfig } from '../../../common/typings/config'; +import ServerConfig from '../../../config.autogen.json'; interface IUsePhone { visibility: boolean; - config?: ServerConfig; + config?: IServerConfig; } export const usePhone = (): IUsePhone => { const visibility = useRecoilValue(phoneState.visibility); - const config = useRecoilValue(phoneState.phoneConfig); - return { visibility, config }; + return { visibility, config: ServerConfig as any }; }; diff --git a/phone/src/ui/components/AppIcon.tsx b/phone/src/ui/components/AppIcon.tsx index 5bc7fae..1504d52 100644 --- a/phone/src/ui/components/AppIcon.tsx +++ b/phone/src/ui/components/AppIcon.tsx @@ -3,7 +3,6 @@ import { makeStyles } from '@material-ui/core/styles'; import Avatar from '@material-ui/core/Avatar'; import { green } from '@material-ui/core/colors'; import { Button } from '@material-ui/core'; -import Nui from '../../os/nui-events/utils/Nui'; interface IStyles { root: any; diff --git a/resources/client/cl_main.ts b/resources/client/cl_main.ts index c99da94..17b94ea 100644 --- a/resources/client/cl_main.ts +++ b/resources/client/cl_main.ts @@ -210,16 +210,6 @@ function noPhone() { ESX.ShowNotification('Oi Mate, No El Telephono', false, false, 1); } -function sendPhoneConfig() { - SendNuiMessage( - JSON.stringify({ - app: 'PHONE', - method: 'phoneConfig', - data: config, - }) - ); -} - setTick(() => { if (IsControlJustPressed(1, config.KeyTogglePhone)) { Phone(); @@ -263,7 +253,6 @@ async function Phone() { data: true, }) ); - sendPhoneConfig(); SetNuiFocus(true, true); //SetNuiFocusKeepInput(true) } else { @@ -301,7 +290,6 @@ async function Phone() { data: true, }) ); - sendPhoneConfig(); SetNuiFocus(true, true); //SetNuiFocusKeepInput(true) } else {