From c65108b36078427e55b2b03210aaf621b012a9bc Mon Sep 17 00:00:00 2001 From: J Francisco Rader Date: Tue, 25 Aug 2020 22:44:50 -0300 Subject: [PATCH] Improve code --- phone/src/Phone.js | 45 +++++++++---------- phone/src/apps/bank/components/BankApp.js | 23 +++------- .../calculator/components/CalculatorApp.js | 2 +- .../apps/contacts/components/ContactsApp.js | 2 +- phone/src/apps/dialer/components/DialerApp.js | 2 +- .../apps/settings/components/SettingsApp.js | 2 +- phone/src/os/apps/hooks/useApps.js | 13 ++++++ phone/src/os/phone/hooks/usePhoneService.js | 3 +- phone/src/ui/components/AppTitle.js | 4 +- 9 files changed, 45 insertions(+), 51 deletions(-) diff --git a/phone/src/Phone.js b/phone/src/Phone.js index 602cdf4..24fe2b2 100644 --- a/phone/src/Phone.js +++ b/phone/src/Phone.js @@ -6,12 +6,7 @@ import { useSettings } from "./apps/settings/hooks/useSettings"; import MessageIcon from "@material-ui/icons/Email"; import { HomeApp } from "./apps/home/components/Home"; -import { ContactsApp } from "./apps/contacts/components/ContactsApp"; -import { SettingsApp } from "./apps/settings/components/SettingsApp"; -import { DialerApp } from "./apps/dialer/components/DialerApp"; -import { BankApp } from "./apps/bank/components/BankApp"; import { ThemeProvider } from "@material-ui/core"; -import { CalculatorApp } from "./apps/calculator/components/CalculatorApp"; import { useInitKeyboard } from "./os/keyboard/hooks/useKeyboard"; import { NotificationIcon } from "./os/notifications/components/NotificationIcon"; import { NotificationBar } from "./os/notifications/components/NotificationBar"; @@ -19,6 +14,7 @@ import { Navigation } from "./os/navigation-bar/components/Navigation"; import { useNuiService } from "./os/nui-events/hooks/useNuiService"; import { useSimcardService } from "./os/simcard/hooks/useSimcardService"; import { usePhoneService } from "./os/phone/hooks/usePhoneService"; +import { useApps } from "./os/apps/hooks/useApps"; // @TODO: Remove this testing shit // Used for testing NUI events while we work on clientside @@ -32,19 +28,7 @@ setTimeout(() => { }, }) ); -}, 3000); - -setTimeout(() => { - window.dispatchEvent( - new MessageEvent("message", { - data: { - app: "PHONE", - method: "setPowerOff", - data: false, - }, - }) - ); -}, 4000); +}, 1000); setTimeout(() => { window.dispatchEvent( @@ -56,14 +40,27 @@ setTimeout(() => { }, }) ); -}, 3000); +}, 1000); + +setTimeout(() => { + window.dispatchEvent( + new MessageEvent("message", { + data: { + app: "PHONE", + method: "setPowerOff", + data: false, + }, + }) + ); +}, 2300); function Phone() { useNuiService(); const { visibility, powerOff } = usePhoneService(); + const { settings, currentTheme } = useSettings(); + const { allApps } = useApps(); useSimcardService(); useInitKeyboard(); - const { settings, currentTheme } = useSettings(); if (visibility === false) { return null; @@ -101,11 +98,9 @@ function Phone() { />
- - - - - + {allApps.map((App) => ( + + ))}
diff --git a/phone/src/apps/bank/components/BankApp.js b/phone/src/apps/bank/components/BankApp.js index bb4584e..ca0d44b 100644 --- a/phone/src/apps/bank/components/BankApp.js +++ b/phone/src/apps/bank/components/BankApp.js @@ -3,8 +3,8 @@ import { makeStyles } from "@material-ui/core"; import { AppTitle } from "../../../ui/components/AppTitle"; import { AppWrapper } from "../../../ui/components"; import { AppContent } from "../../../ui/components/AppContent"; +import { Button } from "../../../ui/components/Button"; import { useTranslation } from "react-i18next"; -import { Button } from "@material-ui/core"; import { useBank } from "../hooks/useBank"; import { TransactionList } from "./TransactionList"; import "./BankApp.css"; @@ -23,11 +23,6 @@ const useStyles = makeStyles((theme) => ({ textAlign: "center", fontSize: 50, }, - bankOptions: {}, - bankOptionsButton: { - display: "block", - textAlign: "center", - }, })); export const BankApp = () => { @@ -37,18 +32,12 @@ export const BankApp = () => { const bank = useApp("BANK"); return ( - + -
- - - +
+ + +
diff --git a/phone/src/apps/calculator/components/CalculatorApp.js b/phone/src/apps/calculator/components/CalculatorApp.js index d1542a2..b089fcc 100644 --- a/phone/src/apps/calculator/components/CalculatorApp.js +++ b/phone/src/apps/calculator/components/CalculatorApp.js @@ -9,7 +9,7 @@ export const CalculatorApp = () => { const calculator = useApp("CALCULATOR"); return ( - + diff --git a/phone/src/apps/contacts/components/ContactsApp.js b/phone/src/apps/contacts/components/ContactsApp.js index ca0de73..b98c0bf 100644 --- a/phone/src/apps/contacts/components/ContactsApp.js +++ b/phone/src/apps/contacts/components/ContactsApp.js @@ -11,7 +11,7 @@ export const ContactsApp = () => { const contacts = useApp("CONTACTS"); return ( - + { const dialer = useApp("DIALER"); return ( - + diff --git a/phone/src/apps/settings/components/SettingsApp.js b/phone/src/apps/settings/components/SettingsApp.js index a2ad205..b5d2fb7 100644 --- a/phone/src/apps/settings/components/SettingsApp.js +++ b/phone/src/apps/settings/components/SettingsApp.js @@ -32,7 +32,7 @@ export const SettingsApp = () => { const [openMenu, closeMenu, ContextMenu, isMenuOpen] = useContextMenu(); return ( - + , }, { id: "CONTACTS", @@ -27,6 +34,7 @@ const appsState = atom({ backgroundColor: blue[500], color: blue[50], path: "/contacts", + Route: () => , }, { id: "CALCULATOR", @@ -35,6 +43,9 @@ const appsState = atom({ backgroundColor: purple[500], color: grey[50], path: "/calculator", + Route: () => ( + + ), }, { id: "SETTINGS", @@ -43,6 +54,7 @@ const appsState = atom({ backgroundColor: grey[700], color: grey[50], path: "/settings", + Route: () => , }, { id: "BANK", @@ -51,6 +63,7 @@ const appsState = atom({ backgroundColor: orange[600], color: orange[50], path: "/bank", + Route: () => , }, ], }, diff --git a/phone/src/os/phone/hooks/usePhoneService.js b/phone/src/os/phone/hooks/usePhoneService.js index fdf6050..618dfaf 100644 --- a/phone/src/os/phone/hooks/usePhoneService.js +++ b/phone/src/os/phone/hooks/usePhoneService.js @@ -8,6 +8,5 @@ export const usePhoneService = () => { const setPowerOff = useSetRecoilState(phoneState.powerOff); useNuiEvent("PHONE", "setPowerOff", setPowerOff); useNuiEvent("PHONE", "setVisibility", setVisibility); - const { visibility, powerOff } = usePhone(); - return { visibility, powerOff }; + return usePhone(); }; diff --git a/phone/src/ui/components/AppTitle.js b/phone/src/ui/components/AppTitle.js index cd6a720..09bddd8 100644 --- a/phone/src/ui/components/AppTitle.js +++ b/phone/src/ui/components/AppTitle.js @@ -14,9 +14,7 @@ const useStyle = makeStyles((theme) => ({ })); export const AppTitle = ({ - backgroundColor, - color, - nameLocale, + app: { backgroundColor, color, nameLocale }, variant = "h4", ...props }) => {