diff --git a/README.md b/README.md index 3a020e9..12e2315 100644 --- a/README.md +++ b/README.md @@ -1,123 +1,40 @@ -# New Phone Who Dis +# New-Phone-Who-Dis (NPWD) +NPWD is our current running project. Our team has been working on the project since Auguest, 2020. This resource isn’t complete yet and currently has no ETA for release. Feel free to test it out in a dev enviorment by following the installation guide. -### Project Error Discord -Join the [Discord](https://discord.gg/HYwBjTbAY5) to follow current development of the project. +Written completely by the Project Error Dev Team in [React](https://reactjs.org/) with a [TypeScript](https://www.typescriptlang.org/) client/server environment. -### Production Server Installation **(WIP)** +## Project Error Discord +- Join the [Discord](https://discord.gg/HYwBjTbAY5) to follow current development of the project. -**Database** +## Documentation & Installation +- [Project-Error Docs](https://docs.projecterror.dev/#/) contains all the information regarding this resource. Please consult it for installation, dependencies, and other important information. -*New Phone Who Dis (NPWD)* uses its own database driver compatible with `mysql-async` and `ghmattimysql`'s connection string. If you -don't utilize these resources, ensure you have this set in your console. +## Support -``` -set mysql_connection_string "server=127.0.0.1;database=es_extended;userid=user;password=pass" -``` +No support is being provided currently for the resource as it is still in an unfinished state. -### Configuration +Should you encounter any issues, please do the following: -This resource is highly configurable through the [config.json](./config.json). This JSON file holds configuration for the phone itself, for the apps running on it and peripheral information. +- Check the [Git Kraken](https://app.gitkraken.com/glo/board/X9YZ_x_SVQEcMwpH) to see if the issue you're referring to is already tracked. +- Check the [State of Development](https://docs.projecterror.dev/#/npwd/state-of-dev?id=introduction) to see if the app is still a **WIP**. + - If the issue isn't on the Git Kraken and the app is finished, please open an issue. + - If the issue isn't on the Git Kraken and the app is **not** finished, please contact us in Discord. -Below is the list of current configuration options **(WIP)**: +We do not want issues opened that are due to the phone being **WIP** as this slows down development since we now have to address it more immediately. -| Option | Default | Description | -| ------------------------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------ | -| Locale | en | The language locale used by the app. See [fivem keybinds](https://docs.fivem.net/docs/game-references/controls/) for options | -| KeyTogglePhone | 288 (F1) | The keybind to open and close the app. See [fivem keybinds](https://docs.fivem.net/docs/game-references/controls/) for options | -| PhoneAsItem | false | whether or not the phone is an item in game | -| SwimDestroy | false | whether or not the phone will have a chance to be destroyed while swimming | -| RunRate | 10 | interval in seconds to check phone destruction | -| DestoryChance | 100 | Percent chance that phone destruction will occur | -| DestroyPhoneReCheck | 3 | Time in minutes before another phone destruction attempt will happen | -| notificationPosition.horizontal | right | Horizontal position of phone notifications. `left`, `center` or `right` | -| notificationPosition.vertical | bottom | Vertical positon of phone notifications. `top` or `bottom` | -| twitter.showNotifications | true | Whether or not to show twitter notifications | -| twitter.generateProfileNameFromUsers | true | Whether or not the server should automtically generate a player's profile name from their user in the database | -| twitter.allowEdtiableProfileName | true | Whether or not players can edit their profile name | -| twitter.allowDeleteTweets | true | Whether or not players can delete their own tweets | -| twitter.allowReportTweets | true | Whether or not players can report tweets. Optional discord integration. | -| twitter.characterLimit | 160 | Limit on how many characters tweets can contain | -| twitter.newLineLimit | 10 | Limit on how many new lines a message can contain | -| twitter.enableAvatars | true | Whether or not player's can select avatars for their twitter profile | -| twitter.enableEmojis | true | Whether or not player's can use emojis in tweets | -| twitter.enableImages | true | Whether or not player's can add images to tweets (external URLs) | -| twitter.maxImages | 3 | The maximum amount of images allowed in a tweet | +## Preview -### Discord +[Latest Teaser Video (October 28th)](https://streamable.com/f1ri9r) -To configure Discord integration; add the following variables to your `server.cfg` file: - -``` -set discord_bot_token "YOUR_DISCORD_BOT_TOKEN" -set discord_channel_id "YOUR_DISCORD_CHANNEL_ID" -``` - -Current Discord integrations with the phone **(WIP)**: - -- Twitter: reporting tweets - -## Development - -This resource is a [React](https://reactjs.org/) project with a TypeScript client/server environment. - -### Prerequisites - -The Installation Steps assumes you have the following prerequisites: - -1. The ability to open a terminal. It's *recomended*, not required, to use [Visual Studio Code](https://code.visualstudio.com/) or Windows Powershell for the sake of this guide to better provide support should issues arise. -1. [Git for windows](https://git-scm.com/download/win) installed -1. [LTS node.js](https://nodejs.org/en/about/releases/) installed -1. [yarn](https://yarnpkg.com/) package manager installed (`npm install -g yarn`) -1. A fivem environment that is set up according to the [setting up a server instructions](https://docs.fivem.net/docs/server-manual/setting-up-a-server/) from the fivem documentation. - -#### Installation Steps - -1. Clone the repo into your `server-data/resources/` folder. The path will be `server-data\resources\new-phone-who-dis`. **Don't clone the repo into a sub folder.** -1. Ensure the resource folder is named `new-phone-who-dis`. -1. Import the [sql file](https://github.com/project-error/new-phone-who-dis/blob/master/resources/import.sql) into your database. -1. Add `ensure new-phone-who-dis` to your `server.cfg`. -1. Make your configurations in the [config.json](https://github.com/project-error/new-phone-who-dis/blob/master/config.json) **before** building the phone. -1. Open a terminal with the program of your choice. -1. Change your directiory into `new-phone-who-dis\phone` *like so*: `cd A:\FXServer\server-data\resources\new-phone-who-dis\phone` -1. Install node dependencies with `yarn install`. -1. Build in the current directory with `yarn build`. -1. Change your directiory into `new-phone-who-dis\resources` *like so*: `cd A:\FXServer\server-data\resources\new-phone-who-dis\resources` -1. Install node dependencies with`yarn install`. -1. Build in the current directory with `yarn build`. -1. Start your FiveM server - -#### Development iteration cycle: -- You must rebuild the resource following any changes by doing `yarn build` in the `resources` and `phone` folder. -- If iteration on UI changes run the project with `yarn watch` which will monitor the JavaScript project and rebuild when you make code changes and then do `ensure new-phone-who-dis` after making your change. -- Avoid commiting `index.html` as the development version overrides the production version - -#### React Devtools - -When in development mode, the bundle includes a standalone React DevTools module, that allows access to react-devtools comparable to the browser environment. - -First ensure you have react-devtools installed globally by running one of the following commands: - -#### Yarn -```shell -yarn global add react-devtools -``` - -#### NPM -```shell -npm install -g react-devtools -``` - -Then run this command from your preffered terminal: -```shell -react-devtools -``` -Now start your `ensure NPWD` with the development build, and you should have access to the React DevTools just as you would in the browser! - -### Important Note - -- By installing NPWD you agree to the use of the following diagnostic package, Sentry, (in use within the React portion of NPWD), that automatically -uploads relevant sesssion details and stack traces whenever an exception is thrown. We use these metrics to further -improve the quality of the phone. To explicitly disable this (we urge you not to as its incredibly useful metrics for us). -Please change the `SentryErrorMetrics` setting to `false` in `phone/config/default.json` and rebuild the phone. - -- This resource has **NOT** been tested with [esx_kashacter](https://github.com/FiveEYZ/esx_kashacter) so compatability with it is unknown. For best results, use the resource on with no kash. +#### Apps (February 20th, 2021) +Most of these apps have UI that does **not** represent the final product and are subject to change. +- [**Bank**](https://i.imgur.com/P5Dg0Mj.png) +- [**Calculator**](https://i.imgur.com/96e3bFF.png) +- [**Camera**](https://i.imgur.com/1aGEV28.png) +- [**Contacts**](https://i.imgur.com/3Qc1eJB.png) +- [**Marketplace**](https://i.imgur.com/8hPm6tU.png) +- [**Messages**](https://i.imgur.com/UYHoVvy.png) +- [**Notes**](https://i.imgur.com/m0ktIyj.png) +- [**Phone**](https://i.imgur.com/zuxERmR.png) +- [**Settings**](https://i.imgur.com/0ggMdij.png) +- [**Twitter**](https://i.imgur.com/WfjOl1t.png) diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index 60a4dd9..781e876 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -1,11 +1,10 @@ -import React, { useMemo } from 'react'; +import React from 'react'; import './Phone.css'; import './i18n'; import { Route } from 'react-router-dom'; import { CallModal } from './modal/components/CallModal'; -import { Alert } from './ui/components/Alert'; import { HomeApp } from './apps/home/components/Home'; -import { createMuiTheme, ThemeProvider, Slide } from '@material-ui/core'; +import { ThemeProvider, Slide } from '@material-ui/core'; import { useInitKeyboard } from './os/keyboard/hooks/useKeyboard'; import { NotificationBar } from './os/notifications/components/NotificationBar'; import { Navigation } from './os/navigation-bar/components/Navigation'; @@ -21,23 +20,18 @@ import { useBankService } from './apps/bank/hooks/useBankService'; import { useMessagesService } from './apps/messages/hooks/useMessageService'; import { useNotesService } from './apps/notes/hooks/useNotesService'; import { usePhotoService } from './apps/camera/hooks/usePhotoService'; -import Nui from './os/nui-events/utils/Nui'; import { useSettings } from './apps/settings/hooks/useSettings'; - -import config from './config/default.json'; import { useCallService } from './modal/hooks/useCallService'; import { useModal } from './modal/hooks/useModal'; import { useDialService } from './apps/dialer/hooks/useDialService'; import InjectDebugData from './os/debug/InjectDebugData'; -import { useSnackbar } from './ui/hooks/useSnackbar'; -import { useTranslation } from 'react-i18next'; import { usePhoneVisibility } from './os/phone/hooks/usePhoneVisibility'; +import { usePhoneTheme } from './os/phone/hooks/usePhoneTheme'; +import { Snackbar } from './ui/components/Snackbar'; function Phone() { - const { t } = useTranslation(); - const { alert } = useSnackbar(); const { modal } = useModal(); - const { allApps } = useApps(); + const { apps } = useApps(); const [settings] = useSettings(); @@ -62,16 +56,7 @@ function Phone() { useCallService(); useDialService(); - const currentTheme = useMemo( - () => createMuiTheme(config.themes[settings.theme]), - [settings.theme] - ); - - document.onkeyup = function (data) { - if (data.which === 27) { - Nui.send('phone:close'); - } - }; + const currentTheme = usePhoneTheme(); return ( @@ -108,25 +93,12 @@ function Phone() { ) : ( <> - {allApps.map((App) => ( + {apps.map((App) => ( ))} )} - {alert ? ( -
- - {t('APPS_' + alert.message)} - -
- ) : null} + diff --git a/phone/src/apps/calculator/components/Calculator.tsx b/phone/src/apps/calculator/components/Calculator.tsx index e45f71a..15854d9 100644 --- a/phone/src/apps/calculator/components/Calculator.tsx +++ b/phone/src/apps/calculator/components/Calculator.tsx @@ -3,6 +3,7 @@ import { useCalculator, CalcButton } from '../hooks/useCalculator'; import { Grid, makeStyles, Box, Paper, Fab } from '@material-ui/core'; import { setClipboard } from '../../../os/phone/hooks/useClipboard'; import FileCopyIcon from '@material-ui/icons/FileCopy'; +import { useSnackbar } from '../../../ui/hooks/useSnackbar'; const useStyles = makeStyles((theme) => ({ button: { @@ -45,6 +46,9 @@ export const Calculator = ({ ...props }) => { eight, nine, } = useCalculator(); + + const { addAlert } = useSnackbar(); + const classes = useStyles(); const resultStr = useMemo( () => @@ -58,7 +62,14 @@ export const Calculator = ({ ...props }) => { return ( - setClipboard(resultStr)} className={classes.copyFab}> + { + setClipboard(resultStr); + addAlert({ message: 'CALCULATOR_COPIED', type: 'info' }); + }} + className={classes.copyFab} + > {resultStr} diff --git a/phone/src/apps/camera/hooks/usePhotoService.ts b/phone/src/apps/camera/hooks/usePhotoService.ts index 5b33e31..67c5190 100644 --- a/phone/src/apps/camera/hooks/usePhotoService.ts +++ b/phone/src/apps/camera/hooks/usePhotoService.ts @@ -1,10 +1,8 @@ import { useSetRecoilState } from 'recoil'; import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; import { photoState } from './state'; -import { usePhotos } from './usePhotos'; export const usePhotoService = () => { const setPhotos = useSetRecoilState(photoState.photos); useNuiEvent('CAMERA', 'setPhotos', setPhotos); - return usePhotos(); }; diff --git a/phone/src/apps/contacts/components/Contact.css b/phone/src/apps/contacts/components/Contact.css deleted file mode 100644 index 9d67f58..0000000 --- a/phone/src/apps/contacts/components/Contact.css +++ /dev/null @@ -1,3 +0,0 @@ -#contact-app .Mui-focused::after { - border-bottom: #2196f3 solid 4px; -} diff --git a/phone/src/apps/contacts/components/ContactsApp.tsx b/phone/src/apps/contacts/components/ContactsApp.tsx index b3b1760..f27a774 100644 --- a/phone/src/apps/contacts/components/ContactsApp.tsx +++ b/phone/src/apps/contacts/components/ContactsApp.tsx @@ -8,6 +8,23 @@ import { Route } from 'react-router-dom'; import ContactsInfoPage from './views/ContactInfo'; import { ContactPage } from './views/ContactsPage'; +import { ContactsThemeProvider } from '../providers/ContactsThemeProvider'; + +export const ContactsApp = () => { + const contacts = useApp('CONTACTS'); + + return ( + + + + + + + + + + ); +}; InjectDebugData([ { @@ -33,17 +50,3 @@ InjectDebugData([ ], }, ]); - -export const ContactsApp = () => { - const contacts = useApp('CONTACTS'); - - return ( - - - - - - - - ); -}; diff --git a/phone/src/apps/contacts/components/List/ContactList.tsx b/phone/src/apps/contacts/components/List/ContactList.tsx index 6d03a33..4e279aa 100644 --- a/phone/src/apps/contacts/components/List/ContactList.tsx +++ b/phone/src/apps/contacts/components/List/ContactList.tsx @@ -7,17 +7,12 @@ import { List, ListItem, } from '@material-ui/core'; - import { useFilteredContacts } from '../../hooks/useFilteredContacts'; - import PhoneIcon from '@material-ui/icons/Phone'; import ChatIcon from '@material-ui/icons/Chat'; import MoreVertIcon from '@material-ui/icons/MoreVert'; import { useContacts } from '../../hooks/useContacts'; - import Nui from '../../../../os/nui-events/utils/Nui'; - -import '../Contact.css'; import { SearchContacts } from './SearchContacts'; import { useHistory } from 'react-router-dom'; import LogDebugEvent from '../../../../os/debug/LogDebugEvents'; diff --git a/phone/src/apps/contacts/components/views/ContactInfo.tsx b/phone/src/apps/contacts/components/views/ContactInfo.tsx index 9235746..57dc069 100644 --- a/phone/src/apps/contacts/components/views/ContactInfo.tsx +++ b/phone/src/apps/contacts/components/views/ContactInfo.tsx @@ -1,6 +1,7 @@ import React, { useState } from 'react'; import { Avatar as MuiAvatar, + Box, Button, Paper, TextField, @@ -43,28 +44,6 @@ const useStyles = makeStyles((theme: Theme) => ({ inputProps: { fontSize: 22, }, - updateButton: { - background: '#2196f3', - width: 150, - height: 45, - fontSize: 16, - marginTop: 29, - marginBottom: 29, - }, - deleteButton: { - background: '#d32f2f', - width: 150, - height: 40, - fontSize: 16, - }, - saveButton: { - background: theme.palette.success.dark, - color: '#fff', - width: 150, - height: 45, - fontsize: 22, - marginTop: theme.spacing(2), - }, })); const ContactsInfoPage = () => { @@ -96,7 +75,7 @@ const ContactsInfoPage = () => { number, avatar, }); - history.goBack() + history.goBack(); }; const handleContactSave = () => { @@ -111,7 +90,7 @@ const ContactsInfoPage = () => { number, avatar, }); - history.goBack() + history.goBack(); }; const handleContactDelete = () => { @@ -123,7 +102,7 @@ const ContactsInfoPage = () => { Nui.send('phone:deleteContact', { id: contact.id, }); - history.goBack() + history.goBack(); }; return ( @@ -137,7 +116,7 @@ const ContactsInfoPage = () => { className={classes.input} value={name} onChange={(e) => setName(e.target.value)} - placeholder={t('APPS_CONTACT_FORM_NAME')} + label={t('APPS_CONTACT_FORM_NAME')} fullWidth inputProps={{ className: classes.inputProps, @@ -147,7 +126,7 @@ const ContactsInfoPage = () => { className={classes.input} value={number} onChange={(e) => setNumber(e.target.value)} - placeholder={t('APPS_CONTACT_FORM_NUMBER')} + label={t('APPS_CONTACT_FORM_NUMBER')} fullWidth inputProps={{ className: classes.inputProps, @@ -155,7 +134,7 @@ const ContactsInfoPage = () => { /> setAvatar(e.target.value)} @@ -165,28 +144,38 @@ const ContactsInfoPage = () => { /> {/* Display if fetched contact */} {contact && ( -
- - -
+ <> + + + + + + + )} {/* Display if no fetched contact */} {!contact && ( -
- -
+
)} diff --git a/phone/src/apps/contacts/components/views/ContactsPage.tsx b/phone/src/apps/contacts/components/views/ContactsPage.tsx index cdaf91a..75d10a8 100644 --- a/phone/src/apps/contacts/components/views/ContactsPage.tsx +++ b/phone/src/apps/contacts/components/views/ContactsPage.tsx @@ -26,8 +26,8 @@ export const ContactPage = () => { <> history.push('/contacts/-1')} - style={{ backgroundColor: '#2196f3', color: '#fff' }} className={classes.absolute} > diff --git a/phone/src/apps/contacts/constants.ts b/phone/src/apps/contacts/constants.ts deleted file mode 100644 index 0285618..0000000 --- a/phone/src/apps/contacts/constants.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { blue, common } from '@material-ui/core/colors'; - -export const CONTACTS_APP_BG_COLOR = blue[500]; -export const CONTACTS_APP_COLOR = common.white; diff --git a/phone/src/apps/contacts/contacts.theme.ts b/phone/src/apps/contacts/contacts.theme.ts new file mode 100644 index 0000000..81ec0ee --- /dev/null +++ b/phone/src/apps/contacts/contacts.theme.ts @@ -0,0 +1,27 @@ +import { blue, common } from '@material-ui/core/colors'; + +export const CONTACTS_APP_PRIMARY_COLOR = blue[500]; +export const CONTACTS_APP_TEXT_COLOR = common.white; + +const theme = { + palette: { + primary: { + main: CONTACTS_APP_PRIMARY_COLOR, + dark: blue[700], + light: blue[300], + contrastText: CONTACTS_APP_TEXT_COLOR, + }, + secondary: { + main: '#d32f2f', + light: '#eb4242', + dark: '#941212', + contrastText: CONTACTS_APP_TEXT_COLOR, + }, + success: { + main: '#2196f3', + contrastText: CONTACTS_APP_TEXT_COLOR, + }, + }, +}; + +export default theme; diff --git a/phone/src/apps/contacts/hooks/useContactsService.ts b/phone/src/apps/contacts/hooks/useContactsService.ts index c8a3a04..fbdc96a 100644 --- a/phone/src/apps/contacts/hooks/useContactsService.ts +++ b/phone/src/apps/contacts/hooks/useContactsService.ts @@ -7,7 +7,8 @@ import { useSnackbar } from '../../../ui/hooks/useSnackbar'; export const useContactsService = () => { const setContacts = useSetRecoilState(contactsState.contacts); const { addAlert } = useSnackbar() + useNuiEvent('CONTACTS', 'setContacts', setContacts); useNuiEvent('CONTACTS', 'setAlert', addAlert); return useContacts(); -}; \ No newline at end of file +}; diff --git a/phone/src/apps/contacts/providers/ContactsThemeProvider.tsx b/phone/src/apps/contacts/providers/ContactsThemeProvider.tsx new file mode 100644 index 0000000..930f31f --- /dev/null +++ b/phone/src/apps/contacts/providers/ContactsThemeProvider.tsx @@ -0,0 +1,5 @@ +import { createAppThemeProvider } from '../../../os/apps/utils/createAppThemeProvider'; + +import contactsTheme from '../contacts.theme'; + +export const ContactsThemeProvider = createAppThemeProvider(contactsTheme); diff --git a/phone/src/apps/dialer/hooks/useDialService.ts b/phone/src/apps/dialer/hooks/useDialService.ts index 7b82ade..a0df85b 100644 --- a/phone/src/apps/dialer/hooks/useDialService.ts +++ b/phone/src/apps/dialer/hooks/useDialService.ts @@ -1,11 +1,8 @@ import { useSetRecoilState } from 'recoil'; import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; import { dialState } from './state'; -import { useDialHistory } from './useDialHistory'; export const useDialService = () => { const setHistory = useSetRecoilState(dialState.history); useNuiEvent('DAILER', 'setHistory', setHistory); - - return useDialHistory(); }; diff --git a/phone/src/apps/example/components/ExampleApp.tsx b/phone/src/apps/example/components/ExampleApp.tsx index ca6e58e..ec27821 100644 --- a/phone/src/apps/example/components/ExampleApp.tsx +++ b/phone/src/apps/example/components/ExampleApp.tsx @@ -4,20 +4,25 @@ import { AppWrapper } from '../../../ui/components'; import { AppContent } from '../../../ui/components/AppContent'; import { useApp } from '../../../os/apps/hooks/useApps'; import { useExample } from '../hooks/useExample'; +import { ExampleThemeProvider } from '../providers/ExampleThemeProvider'; +import { AppTitle } from '../../../ui/components/AppTitle'; +import { Button } from '@material-ui/core'; export const ExampleApp = () => { // calling the example hook, and we assign the value to a variable - const exampleString = useExample(); const example = useApp('EXAMPLE'); return ( - - -

This is an example

-

{example.id}

- {/* Here we are using the value in a h3 tag */} -

{exampleString}

-
-
+ + + + +

This is an example

+ + {/* Here we are using the value in a h3 tag */} +

{exampleString}

+
+
+
); }; diff --git a/phone/src/apps/example/example.theme.ts b/phone/src/apps/example/example.theme.ts new file mode 100644 index 0000000..ff72081 --- /dev/null +++ b/phone/src/apps/example/example.theme.ts @@ -0,0 +1,9 @@ +const theme = { + palette: { + primary: { + main: '#f23123' + } + } +} + +export default theme; \ No newline at end of file diff --git a/phone/src/apps/example/providers/ExampleThemeProvider.tsx b/phone/src/apps/example/providers/ExampleThemeProvider.tsx new file mode 100644 index 0000000..095a825 --- /dev/null +++ b/phone/src/apps/example/providers/ExampleThemeProvider.tsx @@ -0,0 +1,5 @@ +import { createAppThemeProvider } from '../../../os/apps/utils/createAppThemeProvider'; + +import exampleTheme from '../example.theme'; + +export const ExampleThemeProvider = createAppThemeProvider(exampleTheme); diff --git a/phone/src/apps/home/components/Home.tsx b/phone/src/apps/home/components/Home.tsx index b6448fd..e1513fb 100644 --- a/phone/src/apps/home/components/Home.tsx +++ b/phone/src/apps/home/components/Home.tsx @@ -5,11 +5,11 @@ import { GridMenu } from '../../../ui/components/GridMenu'; import { useApps } from '../../../os/apps/hooks/useApps'; export const HomeApp = () => { - const { allApps } = useApps(); + const { apps } = useApps(); return ( - {allApps && } + {apps && } ); diff --git a/phone/src/apps/messages/components/MessagesApp.tsx b/phone/src/apps/messages/components/MessagesApp.tsx index f3dfeb6..fe59786 100644 --- a/phone/src/apps/messages/components/MessagesApp.tsx +++ b/phone/src/apps/messages/components/MessagesApp.tsx @@ -1,4 +1,3 @@ -import './messages.css'; import React, { useEffect } from 'react'; import { AppWrapper } from '../../../ui/components'; import { AppTitle } from '../../../ui/components/AppTitle'; @@ -10,8 +9,9 @@ import MessagesList from './list/MessagesList'; import { Route, Switch, useHistory } from 'react-router-dom'; import { MessageModal } from './modal/MessageModal'; import InjectDebugData from '../../../os/debug/InjectDebugData'; -import NewMessageGroupButton from './buttons/NewMessageGroupButton'; +import NewMessageGroupButton from './form/NewMessageGroupButton'; import Nui from '../../../os/nui-events/utils/Nui'; +import { MessagesThemeProvider } from '../providers/MessagesThemeProvider'; export const MessagesApp = () => { const messages = useApp('MESSAGES'); @@ -22,37 +22,37 @@ export const MessagesApp = () => { }, []); return ( - - - - - - ( - <> - - - )} - /> - - - } - /> - - - history.push('/messages/new')} - /> - - + + + + + + + ( + <> + + + )} + /> + + + } + /> + + + history.push('/messages/new')} /> + + + ); }; @@ -73,7 +73,7 @@ InjectDebugData([ updatedAt: Date.now(), }, { - id: 1, + id: 2, message: 'sup!', user_identifier: '1234', phone_number: '444-4444', @@ -84,7 +84,7 @@ InjectDebugData([ updatedAt: Date.now(), }, { - id: 1, + id: 3, message: 'sup!', user_identifier: '1234', phone_number: '444-4444', @@ -95,7 +95,7 @@ InjectDebugData([ updatedAt: Date.now(), }, { - id: 1, + id: 4, message: 'sup!', user_identifier: '1234', phone_number: '444-4444', @@ -106,7 +106,7 @@ InjectDebugData([ updatedAt: Date.now(), }, { - id: 1, + id: 5, message: 'sup!', user_identifier: '1234', phone_number: '444-4444', @@ -117,7 +117,7 @@ InjectDebugData([ updatedAt: Date.now(), }, { - id: 1, + id: 6, message: 'sup!', user_identifier: '1234', phone_number: '444-4444', @@ -128,7 +128,7 @@ InjectDebugData([ updatedAt: Date.now(), }, { - id: 1, + id: 7, message: 'sup!', user_identifier: '1234', phone_number: '444-4444', @@ -139,7 +139,7 @@ InjectDebugData([ updatedAt: Date.now(), }, { - id: 1, + id: 8, message: 'sup!', user_identifier: '1234', phone_number: '444-4444', @@ -150,7 +150,7 @@ InjectDebugData([ updatedAt: Date.now(), }, { - id: 1, + id: 9, message: 'sup!', user_identifier: '1234', phone_number: '444-4444', diff --git a/phone/src/apps/messages/components/form/MessageInput.tsx b/phone/src/apps/messages/components/form/MessageInput.tsx index 0391b6c..d1cf794 100644 --- a/phone/src/apps/messages/components/form/MessageInput.tsx +++ b/phone/src/apps/messages/components/form/MessageInput.tsx @@ -1,6 +1,6 @@ import React, { FormEvent, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { Paper, TextField, Button, Box, makeStyles } from '@material-ui/core'; +import { Paper, Box, makeStyles, TextField, Button } from '@material-ui/core'; import SendIcon from '@material-ui/icons/Send'; import ImageIcon from '@material-ui/icons/Image'; import Nui from '../../../../os/nui-events/utils/Nui'; diff --git a/phone/src/apps/messages/components/buttons/NewMessageGroupButton.tsx b/phone/src/apps/messages/components/form/NewMessageGroupButton.tsx similarity index 100% rename from phone/src/apps/messages/components/buttons/NewMessageGroupButton.tsx rename to phone/src/apps/messages/components/form/NewMessageGroupButton.tsx index 389b77e..57ab78d 100644 --- a/phone/src/apps/messages/components/buttons/NewMessageGroupButton.tsx +++ b/phone/src/apps/messages/components/form/NewMessageGroupButton.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { makeStyles } from '@material-ui/core/styles'; -import { Fab } from '@material-ui/core'; import AddIcon from '@material-ui/icons/Add'; +import { Fab } from '@material-ui/core'; const useStyles = makeStyles((theme) => ({ root: { diff --git a/phone/src/apps/messages/components/form/NewMessageGroupForm.tsx b/phone/src/apps/messages/components/form/NewMessageGroupForm.tsx index 7e02b2f..738c79a 100644 --- a/phone/src/apps/messages/components/form/NewMessageGroupForm.tsx +++ b/phone/src/apps/messages/components/form/NewMessageGroupForm.tsx @@ -1,6 +1,6 @@ import React, { FormEvent, useCallback, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { TextField, Button, Box } from '@material-ui/core'; +import { Box, Button, TextField } from '@material-ui/core'; import Nui from '../../../../os/nui-events/utils/Nui'; import { useHistory } from 'react-router-dom'; @@ -102,7 +102,7 @@ const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => { )} diff --git a/phone/src/apps/messages/components/list/list.styles.ts b/phone/src/apps/messages/components/list/list.styles.ts index 2f88133..fce8868 100644 --- a/phone/src/apps/messages/components/list/list.styles.ts +++ b/phone/src/apps/messages/components/list/list.styles.ts @@ -17,6 +17,8 @@ const useStyles = makeStyles((theme) => ({ inputRoot: { fontWeight: 400, fontSize: 18, + border: '1px solid', + borderColor: theme.palette.divider, }, inputInput: { padding: theme.spacing(1, 4, 1, 4), @@ -27,7 +29,7 @@ const useStyles = makeStyles((theme) => ({ [theme.breakpoints.up('sm')]: { width: '13ch', '&:focus': { - width: '20ch', + width: '24ch', }, }, }, diff --git a/phone/src/apps/messages/components/messages.css b/phone/src/apps/messages/components/messages.css deleted file mode 100644 index 5a78e8f..0000000 --- a/phone/src/apps/messages/components/messages.css +++ /dev/null @@ -1,23 +0,0 @@ -#messages-app { - position: relative; -} - -/* override the FAB (action buttons) background when selected */ -#messages-app .MuiFab-primary { - background: #ffa000 !important; -} - -/* override the underlines of text fields */ -#messages-app .Mui-focused:after { - border-bottom-color: #ffa000 !important; -} - -/* override form submit button */ -#messages-app .MuiButton-containedPrimary { - background-color: #ffa000 !important; -} - -#messages-app .MuiSkeleton-text { - border-radius: 20px !important; - transform: none; -} diff --git a/phone/src/apps/messages/components/messages.styles.ts b/phone/src/apps/messages/components/messages.styles.ts deleted file mode 100644 index 06ceaf1..0000000 --- a/phone/src/apps/messages/components/messages.styles.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { makeStyles } from '@material-ui/core'; - -const useStyles = makeStyles((theme) => ({ - addMessageFab: { - position: 'sticky', - bottom: theme.spacing(2), - left: theme.spacing(3), - }, -})); - -export default useStyles; diff --git a/phone/src/apps/messages/components/modal/Conversation.tsx b/phone/src/apps/messages/components/modal/Conversation.tsx index e5dcf33..4c5e619 100644 --- a/phone/src/apps/messages/components/modal/Conversation.tsx +++ b/phone/src/apps/messages/components/modal/Conversation.tsx @@ -1,11 +1,12 @@ import React, { useState } from 'react'; -import { Box, Paper, Typography } from '@material-ui/core'; +import { Box } from '@material-ui/core'; import { Message, MessageGroup } from '../../../../common/typings/messages'; import MessageInput from '../form/MessageInput'; import useStyles from './modal.styles'; import { MessageImageModal } from './MessageImageModal'; import { useQueryParams } from '../../../../common/hooks/useQueryParams'; +import { MessageBubble } from './MessageBubble'; interface IProps { activeMessageGroup: MessageGroup; @@ -20,10 +21,6 @@ const Conversation = ({ activeMessageGroup, messages }: IProps) => { const query = useQueryParams(); const referalImage = query?.image || null; - const isImage = (url) => { - return /(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|png|jpeg|gif)/g.test(url); - }; - return ( <> { className={classes.overflowAutoY} > {messages.map((message) => ( -
- - {isImage(message.message) ? ( - multimedia - ) : ( -
{message.message}
- )} - - {activeMessageGroup.isGroupChat && !message.isMine - ? message.display || message.phone_number - : null} - -
-
+ ))}
({ + imageMessage: { + width: '80%', + maxWidth: '80%', + height: '80%', + maxHeight: '80%', + }, + mySms: { + float: 'right', + margin: theme.spacing(1), + padding: '6px 12px', + height: 'auto', + width: '80%', + background: theme.palette.background.default, + color: theme.palette.text.primary, + borderRadius: '20px', + textOverflow: 'ellipsis', + }, + sms: { + float: 'left', + margin: theme.spacing(1), + padding: '6px 12px', + width: '80%', + height: 'auto', + background: theme.palette.primary.light, + color: theme.palette.getContrastText(theme.palette.primary.light), + borderRadius: '15px', + textOverflow: 'ellipsis', + }, +})); + +const isImage = (url) => { + return /(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|png|jpeg|gif)/g.test(url); +}; + +export const MessageBubble = ({ + message, + isGroupChat, +}: { + message: Message; + isGroupChat: boolean; +}) => { + const classes = useStyles(); + return ( +
+ + + {isImage(message.message) ? ( + multimedia + ) : ( +
{message.message}
+ )} +
+ + + {isGroupChat && !message.isMine + ? message.display || message.phone_number + : null} + + +
+
+ ); +}; diff --git a/phone/src/apps/messages/components/modal/MessageImageModal.tsx b/phone/src/apps/messages/components/modal/MessageImageModal.tsx index d627794..3fb388e 100644 --- a/phone/src/apps/messages/components/modal/MessageImageModal.tsx +++ b/phone/src/apps/messages/components/modal/MessageImageModal.tsx @@ -1,10 +1,9 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; import qs from 'qs'; import Nui from '../../../../os/nui-events/utils/Nui'; -import CloseIcon from '@material-ui/icons/Close'; import Modal from '../../../../ui/components/Modal'; import PhotoLibraryIcon from '@material-ui/icons/PhotoLibrary'; -import { Box, Button, TextField, Typography } from '@material-ui/core'; +import { Box, Typography, TextField, Button } from '@material-ui/core'; import FileCopyIcon from '@material-ui/icons/FileCopy'; import useStyles from './modal.styles'; import { useHistory, useLocation } from 'react-router-dom'; @@ -85,13 +84,9 @@ export const MessageImageModal = ({ })}` ), }, - { - label: 'Cancel', - icon: , - onClick: onClose, - }, + ], - [onClose, history, pathname, search] + [history, pathname, search] ); return ( @@ -110,6 +105,7 @@ export const MessageImageModal = ({ diff --git a/phone/src/apps/sellout/components/SelloutTitle.tsx b/phone/src/apps/sellout/components/SelloutTitle.tsx index 25e7a02..ff75a25 100644 --- a/phone/src/apps/sellout/components/SelloutTitle.tsx +++ b/phone/src/apps/sellout/components/SelloutTitle.tsx @@ -12,10 +12,10 @@ const useStyles = makeStyles((theme) => ({ flexFlow: 'row nowrap', justifyContent: 'center', alignItems: 'center', - background: '#262525', + background: theme.palette.background.default, }, icon: { - color: '#f44336', + color: theme.palette.primary.main, fontSize: 40, }, })); diff --git a/phone/src/apps/sellout/components/form/ListingForm.tsx b/phone/src/apps/sellout/components/form/ListingForm.tsx index 9da433d..6bb6164 100644 --- a/phone/src/apps/sellout/components/form/ListingForm.tsx +++ b/phone/src/apps/sellout/components/form/ListingForm.tsx @@ -2,8 +2,6 @@ import React, { useState } from 'react'; import { makeStyles, Button, TextField } from '@material-ui/core'; import Nui from '../../../../os/nui-events/utils/Nui'; -import '../Sellout.css'; - const useStyles = makeStyles((theme) => ({ root: { width: '100%', @@ -22,7 +20,7 @@ const useStyles = makeStyles((theme) => ({ postButton: { display: 'block', margin: 'auto', - background: '#f44336', + background: theme.palette.primary.main, width: '80%', fontSize: 20, }, diff --git a/phone/src/apps/sellout/components/navigation/NavigationBar.tsx b/phone/src/apps/sellout/components/navigation/NavigationBar.tsx index 75b4c30..676c856 100644 --- a/phone/src/apps/sellout/components/navigation/NavigationBar.tsx +++ b/phone/src/apps/sellout/components/navigation/NavigationBar.tsx @@ -9,10 +9,10 @@ import AddCircleIcon from '@material-ui/icons/AddCircle'; const useStyles = makeStyles((theme) => ({ root: { width: '100%', - backgroundColor: '#262525', + backgroundColor: theme.palette.background.default, }, icon: { - color: '#f44336', + color: theme.palette.primary.main, }, })); diff --git a/phone/src/apps/sellout/providers/SelloutThemeProvider.tsx b/phone/src/apps/sellout/providers/SelloutThemeProvider.tsx new file mode 100644 index 0000000..bbec2f5 --- /dev/null +++ b/phone/src/apps/sellout/providers/SelloutThemeProvider.tsx @@ -0,0 +1,5 @@ +import { createAppThemeProvider } from "../../../os/apps/utils/createAppThemeProvider"; + +import selloutTheme from '../sellout.theme'; + +export const SelloutThemeProvider = createAppThemeProvider(selloutTheme); diff --git a/phone/src/apps/sellout/sellout.theme.ts b/phone/src/apps/sellout/sellout.theme.ts new file mode 100644 index 0000000..b1b511a --- /dev/null +++ b/phone/src/apps/sellout/sellout.theme.ts @@ -0,0 +1,14 @@ +import { common } from "@material-ui/core/colors"; + +const theme = { + palette: { + primary: { + main: '#f44336', + dark: '#b3251b', + light: 'f87f76', + contrastText: common.black + } + } +} + +export default theme; diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index 0fc351f..5dd24e3 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -93,6 +93,8 @@ "APPS_NOTES_DELETE_SUCCESS": "Successfully deleted note.", "APPS_NOTES_DELETE_FAILED": "Failed to delete note.", + "APPS_CALCULATOR_COPIED": "Result was copied to clipboard!", + "APPS_SETTINGS_PHONE_NUMBER": "Phone Number", "APPS_SETTINGS_OPTION_WALLPAPER": "Wallpaper", "APPS_SETTINGS_OPTION_FRAME": "Frame", @@ -106,6 +108,7 @@ "GENERIC_SAVE": "Save", "GENERIC_UPDATE": "Update", - "GENERIC_DELETE": "Delete" + "GENERIC_DELETE": "Delete", + "GENERIC_CLOSE": "Close" } } diff --git a/phone/src/modal/hooks/useCallService.ts b/phone/src/modal/hooks/useCallService.ts index 5345d0f..74dbb13 100644 --- a/phone/src/modal/hooks/useCallService.ts +++ b/phone/src/modal/hooks/useCallService.ts @@ -1,8 +1,6 @@ import { useNuiEvent } from '../../os/nui-events/hooks/useNuiEvent'; import { useRecoilState, useSetRecoilState } from 'recoil'; import { callerState } from './state'; -import { useCall } from './useCall'; -import { useModal } from './useModal'; export const useCallService = () => { const [caller, setCaller] = useRecoilState(callerState.currentCall); @@ -10,6 +8,4 @@ export const useCallService = () => { useNuiEvent('CALL', 'setCaller', setCaller, {}, caller); useNuiEvent('CALL', 'callModal', setModal); - return { useCall, useModal }; }; - \ No newline at end of file diff --git a/phone/src/os/apps/components/AppRoute.tsx b/phone/src/os/apps/components/AppRoute.tsx new file mode 100644 index 0000000..4049a14 --- /dev/null +++ b/phone/src/os/apps/components/AppRoute.tsx @@ -0,0 +1,16 @@ +import React from 'react'; +import { Route } from 'react-router-dom'; +import { AppWithStartup } from './AppWithStartup'; + +export const AppRoute = ({ id, component: Component, ...rest }) => { + return ( + ( + + + + )} + /> + ); +}; diff --git a/phone/src/os/apps/components/AppWithStartup.tsx b/phone/src/os/apps/components/AppWithStartup.tsx new file mode 100644 index 0000000..7342147 --- /dev/null +++ b/phone/src/os/apps/components/AppWithStartup.tsx @@ -0,0 +1,9 @@ +import { useEffect } from 'react'; +import Nui from '../../nui-events/utils/Nui'; + +export const AppWithStartup = ({ children, id }) => { + useEffect(() => { + Nui.send(`phone:app:${id}`); + }, [id]); + return children; +}; diff --git a/phone/src/os/apps/config/apps.tsx b/phone/src/os/apps/config/apps.tsx new file mode 100644 index 0000000..98320de --- /dev/null +++ b/phone/src/os/apps/config/apps.tsx @@ -0,0 +1,189 @@ +import React from 'react'; +import { + blue, + common, + grey, + green, + purple, + yellow, + red, +} from '@material-ui/core/colors'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { + faAd, + faPlaneArrival, + faPhoneAlt, + faWonSign, + faStickyNote, +} from '@fortawesome/free-solid-svg-icons'; +import { faTwitter } from '@fortawesome/free-brands-svg-icons'; + +import ContactsIcon from '@material-ui/icons/Contacts'; +import SettingsIcon from '@material-ui/icons/Settings'; +import MessageIcon from '@material-ui/icons/Message'; +import { CalculatorIcon } from '../../../apps/calculator/components/CalculatorIcon'; +import CameraAltIcon from '@material-ui/icons/CameraAlt'; +import { DialerApp } from '../../../apps/dialer/components/DialerApp'; +import { ContactsApp } from '../../../apps/contacts/components/ContactsApp'; +import { CalculatorApp } from '../../../apps/calculator/components/CalculatorApp'; +import { SettingsApp } from '../../../apps/settings/components/SettingsApp'; +import { BankApp } from '../../../apps/bank/components/BankApp'; +import { MessagesApp } from '../../../apps/messages/components/MessagesApp'; +import { TwitterApp } from '../../../apps/twitter/components/TwitterApp'; +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 { AppRoute } from '../components/AppRoute'; +import { + MESSAGES_APP_PRIMARY_COLOR, + MESSAGES_APP_TEXT_COLOR, +} from '../../../apps/messages/messages.theme'; +import { + CONTACTS_APP_PRIMARY_COLOR, + CONTACTS_APP_TEXT_COLOR, +} from '../../../apps/contacts/contacts.theme'; + +export interface IAppConfig { + id: string; + nameLocale: string; + icon: JSX.Element; + notificationIcon: JSX.Element; + backgroundColor: string; + color: string; + path: string; + Route: React.FC; +} + +export const APPS: IAppConfig[] = [ + { + id: 'DIALER', + nameLocale: 'APPS_DIALER', + icon: , + notificationIcon: , + backgroundColor: green[600], + color: common.white, + path: '/phone', + Route: () => , + }, + { + id: 'MESSAGES', + nameLocale: 'APPS_MESSAGES', + icon: , + notificationIcon: , + backgroundColor: MESSAGES_APP_PRIMARY_COLOR, + color: MESSAGES_APP_TEXT_COLOR, + path: '/messages', + Route: () => ( + + ), + }, + { + id: 'CONTACTS', + nameLocale: 'APPS_CONTACTS', + icon: , + notificationIcon: , + backgroundColor: CONTACTS_APP_PRIMARY_COLOR, + color: CONTACTS_APP_TEXT_COLOR, + path: '/contacts', + Route: () => ( + + ), + }, + { + id: 'CALCULATOR', + nameLocale: 'APPS_CALCULATOR', + icon: , + notificationIcon: , + backgroundColor: purple[500], + color: grey[50], + path: '/calculator', + Route: () => ( + + ), + }, + { + id: 'SETTINGS', + nameLocale: 'APPS_SETTINGS', + icon: , + notificationIcon: , + backgroundColor: '#383838', + color: grey[50], + path: '/settings', + Route: () => ( + + ), + }, + { + id: 'BANK', + nameLocale: 'APPS_BANK', + icon: , + notificationIcon: , + backgroundColor: blue[900], + color: common.white, + path: '/bank', + Route: () => , + }, + { + id: 'TWITTER', + nameLocale: 'APPS_TWITTER', + icon: , + notificationIcon: , + backgroundColor: blue[600], + color: common.white, + path: '/twitter', + Route: () => ( + + ), + }, + { + id: 'SELLOUT', + nameLocale: 'APPS_SELLOUT', + icon: , + notificationIcon: , + backgroundColor: red[500], + color: common.white, + path: '/sellout', + Route: () => ( + + ), + }, + { + id: 'NOTES', + nameLocale: 'APPS_NOTES', + icon: , + notificationIcon: ( + + ), + backgroundColor: yellow[800], + color: common.white, + path: '/notes', + Route: () => , + }, + { + id: 'CAMERA', + nameLocale: 'APPS_CAMERA', + icon: , + notificationIcon: , + backgroundColor: grey['A400'], + color: common.white, + path: '/camera', + Route: () => , + }, +]; + +// Example app only in dev +if (process.env.NODE_ENV === 'development') { + APPS.push({ + id: 'EXAMPLE', + nameLocale: 'APPS_EXAMPLE', + icon: , + notificationIcon: , + backgroundColor: blue[500], + color: blue[50], + path: '/example', + Route: () => ( + + ), + }); +} diff --git a/phone/src/os/apps/hooks/useApps.tsx b/phone/src/os/apps/hooks/useApps.tsx index 7eeba8b..04033ba 100644 --- a/phone/src/os/apps/hooks/useApps.tsx +++ b/phone/src/os/apps/hooks/useApps.tsx @@ -1,238 +1,22 @@ -import React, { useCallback, useEffect, useMemo } from 'react'; -import { - blue, - common, - grey, - green, - purple, - yellow, - red, - amber, -} from '@material-ui/core/colors'; -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { - faAd, - faPlaneArrival, - faPhoneAlt, - faWonSign, - faStickyNote, -} from '@fortawesome/free-solid-svg-icons'; -import { faTwitter } from '@fortawesome/free-brands-svg-icons'; - -import ContactsIcon from '@material-ui/icons/Contacts'; -import SettingsIcon from '@material-ui/icons/Settings'; -import MessageIcon from '@material-ui/icons/Message'; -import { atom, useRecoilState } from 'recoil'; -import { CalculatorIcon } from '../../../apps/calculator/components/CalculatorIcon'; -import CameraAltIcon from '@material-ui/icons/CameraAlt'; -import { Route } from 'react-router-dom'; -import { DialerApp } from '../../../apps/dialer/components/DialerApp'; -import { ContactsApp } from '../../../apps/contacts/components/ContactsApp'; -import { CalculatorApp } from '../../../apps/calculator/components/CalculatorApp'; -import { SettingsApp } from '../../../apps/settings/components/SettingsApp'; -import { BankApp } from '../../../apps/bank/components/BankApp'; -import { MessagesApp } from '../../../apps/messages/components/MessagesApp'; -import { TwitterApp } from '../../../apps/twitter/components/TwitterApp'; -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'; +import { useCallback, useMemo } from 'react'; import { useNotifications } from '../../notifications/hooks/useNotifications'; - -export interface IAppConfig { - id: string; - nameLocale: string; - icon: JSX.Element; - notificationIcon: JSX.Element; - backgroundColor: string; - color: string; - path: string; - Route: React.FC; -} - -type AppsRepository = { preinstalled: IAppConfig[] }; - -const AppWithStartup = ({ children, id }) => { - useEffect(() => { - Nui.send(`phone:app:${id}`); - }, [id]); - return children; -}; - -const AppRoute = ({ id, component: Component, ...rest }) => { - return ( - ( - - - - )} - /> - ); -}; - -const appsState = atom({ - key: 'apps', - default: { - preinstalled: [ - { - id: 'DIALER', - nameLocale: 'APPS_DIALER', - icon: , - notificationIcon: , - backgroundColor: green[600], - color: common.white, - path: '/phone', - Route: () => ( - - ), - }, - { - id: 'MESSAGES', - nameLocale: 'APPS_MESSAGES', - icon: , - notificationIcon: , - backgroundColor: amber[700], - color: common.white, - path: '/messages', - Route: () => ( - - ), - }, - { - id: 'CONTACTS', - nameLocale: 'APPS_CONTACTS', - icon: , - notificationIcon: , - backgroundColor: blue[500], - color: common.white, - path: '/contacts', - Route: () => ( - - ), - }, - { - id: 'CALCULATOR', - nameLocale: 'APPS_CALCULATOR', - icon: , - notificationIcon: , - backgroundColor: purple[500], - color: grey[50], - path: '/calculator', - Route: () => ( - - ), - }, - { - id: 'SETTINGS', - nameLocale: 'APPS_SETTINGS', - icon: , - notificationIcon: , - backgroundColor: '#383838', - color: grey[50], - path: '/settings', - Route: () => ( - - ), - }, - { - id: 'BANK', - nameLocale: 'APPS_BANK', - icon: , - notificationIcon: , - backgroundColor: blue[900], - color: common.white, - path: '/bank', - Route: () => , - }, - { - id: 'TWITTER', - nameLocale: 'APPS_TWITTER', - icon: , - notificationIcon: ( - - ), - backgroundColor: blue[600], - color: common.white, - path: '/twitter', - Route: () => ( - - ), - }, - { - id: 'SELLOUT', - nameLocale: 'APPS_SELLOUT', - icon: , - notificationIcon: , - backgroundColor: red[500], - color: common.white, - path: '/sellout', - Route: () => ( - - ), - }, - { - id: 'NOTES', - nameLocale: 'APPS_NOTES', - icon: , - notificationIcon: ( - - ), - backgroundColor: yellow[800], - color: common.white, - path: '/notes', - Route: () => , - }, - { - id: 'CAMERA', - nameLocale: 'APPS_CAMERA', - icon: , - notificationIcon: , - backgroundColor: grey['A400'], - color: common.white, - path: '/camera', - Route: () => ( - - ), - }, - { - id: 'EXAMPLE', - nameLocale: 'APPS_EXAMPLE', - icon: , - notificationIcon: , - backgroundColor: blue[500], - color: blue[50], - path: '/example', - Route: () => ( - - ), - }, - ], - }, -}); +import { APPS, IAppConfig } from '../config/apps'; export const useApps = () => { const { icons } = useNotifications(); - const [apps, setApps] = useRecoilState(appsState); - const allApps = useMemo( + const apps = useMemo( () => - [...apps.preinstalled].map((a) => ({ + APPS.map((a) => ({ ...a, notification: icons.find((i) => i.key === a.id), })), - [apps.preinstalled, icons] + [icons] ); const getApp = useCallback( - (id: string): IAppConfig => allApps.find((a) => a.id === id) || null, - [allApps] + (id: string): IAppConfig => apps.find((a) => a.id === id) || null, + [apps] ); - return { apps, allApps, setApps, getApp }; + return { apps, getApp }; }; export const useApp = (id: string): IAppConfig => { diff --git a/phone/src/os/apps/utils/createAppThemeProvider.tsx b/phone/src/os/apps/utils/createAppThemeProvider.tsx new file mode 100644 index 0000000..fada23a --- /dev/null +++ b/phone/src/os/apps/utils/createAppThemeProvider.tsx @@ -0,0 +1,16 @@ +import React, { useMemo } from 'react'; +import { createMuiTheme, ThemeProvider } from '@material-ui/core'; +import { deepMergeObjects } from './deepMergeObjects'; +import { usePhoneTheme } from '../../phone/hooks/usePhoneTheme'; + +export function createAppThemeProvider(theme: {} = {}) { + const AppThemeProvider = ({ children }: { children: React.ReactNode }) => { + const phoneTheme = usePhoneTheme(); + const mergedTheme = useMemo(() => { + return createMuiTheme(deepMergeObjects(phoneTheme, theme)); + }, [phoneTheme]); + return {children}; + }; + + return AppThemeProvider; +} diff --git a/phone/src/os/apps/utils/deepMergeObjects.ts b/phone/src/os/apps/utils/deepMergeObjects.ts new file mode 100644 index 0000000..f009242 --- /dev/null +++ b/phone/src/os/apps/utils/deepMergeObjects.ts @@ -0,0 +1,32 @@ +/** + * @credits https://stackoverflow.com/questions/27936772/how-to-deep-merge-instead-of-shallow-merge + * Simple object check. + * @param item + * @returns {boolean} + */ +export function isObject(item) { + return (item && typeof item === 'object' && !Array.isArray(item)); +} + +/** + * Deep merge two objects. + * @param target + * @param ...sources + */ +export function deepMergeObjects(target, ...sources) { + if (!sources.length) return target; + const source = sources.shift(); + + if (isObject(target) && isObject(source)) { + for (const key in source) { + if (isObject(source[key])) { + if (!target[key]) Object.assign(target, { [key]: {} }); + deepMergeObjects(target[key], source[key]); + } else { + Object.assign(target, { [key]: source[key] }); + } + } + } + + return deepMergeObjects(target, ...sources); +} \ No newline at end of file diff --git a/phone/src/os/keyboard/hooks/useKeyboard.ts b/phone/src/os/keyboard/hooks/useKeyboard.ts index b0b6bd6..73c93c7 100644 --- a/phone/src/os/keyboard/hooks/useKeyboard.ts +++ b/phone/src/os/keyboard/hooks/useKeyboard.ts @@ -1,5 +1,7 @@ -import { useEffect } from 'react'; +import { useCallback, useEffect } from 'react'; +import { useHistory } from 'react-router-dom'; import { atom, useSetRecoilState, useRecoilValue } from 'recoil'; +import Nui from '../../nui-events/utils/Nui'; const keyboardState = { ArrowRight: atom({ @@ -45,6 +47,7 @@ const validKeys = [ const isKeyValid = (key) => validKeys.indexOf(key) !== -1; export const useInitKeyboard = () => { + const history = useHistory(); const getters = { ArrowRight: useRecoilValue(keyboardState.ArrowRight), ArrowLeft: useRecoilValue(keyboardState.ArrowLeft), @@ -56,6 +59,7 @@ export const useInitKeyboard = () => { }; const setEscape = useSetRecoilState(keyboardState.Escape); + const setBackspace = useSetRecoilState(keyboardState.Backspace); useEffect( function handleNUIKeyboardMessage() { @@ -68,7 +72,7 @@ export const useInitKeyboard = () => { callback.handler && callback.handler.call ) { - return callback.handler(); + return callback.handler(event); } } @@ -78,11 +82,22 @@ export const useInitKeyboard = () => { [getters] ); + const escapeHandler = useCallback(() => Nui.send('phone:close'), []); + + const backspaceHandler = useCallback((event) => { + if (['input', 'textarea'].includes(event.target.nodeName.toLowerCase())) { + // Dont anything if we are typing something :) + return; + } + history.goBack(); + }, [history]); + useEffect( - function registerEscapeHandler() { - setEscape({ handler: () => console.log('close phone') }); + function registerDefaultHandlers() { + setEscape({ handler: escapeHandler }); + setBackspace({ handler: backspaceHandler }); }, - [setEscape] + [setEscape, setBackspace, history, escapeHandler, backspaceHandler] ); }; @@ -92,7 +107,6 @@ export const useKeyboard = () => { ArrowLeft: useSetRecoilState(keyboardState.ArrowLeft), ArrowUp: useSetRecoilState(keyboardState.ArrowUp), ArrowDown: useSetRecoilState(keyboardState.ArrowDown), - Backspace: useSetRecoilState(keyboardState.Backspace), Enter: useSetRecoilState(keyboardState.Enter), }; diff --git a/phone/src/os/notifications/components/NotificationBar.tsx b/phone/src/os/notifications/components/NotificationBar.tsx index dc29719..cf4a57d 100644 --- a/phone/src/os/notifications/components/NotificationBar.tsx +++ b/phone/src/os/notifications/components/NotificationBar.tsx @@ -27,7 +27,7 @@ const useStyles = makeStyles((theme) => ({ height: '30px', width: '100%', color: theme.palette.text.primary, - zIndex: 10, + zIndex: 99, paddingLeft: '15px', paddingRight: '10px', position: 'relative', @@ -52,7 +52,7 @@ const useStyles = makeStyles((theme) => ({ width: '100%', position: 'absolute', top: '30px', - zIndex: 9, + zIndex: 98, }, closeNotifBtn: { position: 'absolute', diff --git a/phone/src/os/notifications/hooks/useQuickAccess.tsx b/phone/src/os/notifications/hooks/useQuickAccess.tsx index 33051f6..e1e9c46 100644 --- a/phone/src/os/notifications/hooks/useQuickAccess.tsx +++ b/phone/src/os/notifications/hooks/useQuickAccess.tsx @@ -1,7 +1,8 @@ import { useCallback, useEffect } from 'react'; import { matchPath, useHistory } from 'react-router-dom'; import { atom, useRecoilState } from 'recoil'; -import { IAppConfig, useApps } from '../../apps/hooks/useApps'; +import { IAppConfig } from '../../apps/config/apps'; +import { useApps } from '../../apps/hooks/useApps'; const state = { recentlyUsed: atom({ @@ -23,24 +24,27 @@ const unshiftApp = (arr: IAppConfig[], app) => { export const useQuickAccess = () => { const history = useHistory(); - const { allApps, getApp } = useApps(); + const { apps, getApp } = useApps(); const [recentlyUsed, setRecentlyUsed] = useRecoilState( state.recentlyUsed ); useEffect(() => { - setRecentlyUsed([getApp("SETTINGS")]) - }, [getApp, setRecentlyUsed]) + setRecentlyUsed([getApp('SETTINGS')]); + }, [getApp, setRecentlyUsed]); - const listener = useCallback((location) => { - const newState = [...recentlyUsed]; - allApps.forEach((app) => { - if (matchPath(location.pathname, { path: app.path, exact: true })) { - unshiftApp(newState, app); - } - }); - setRecentlyUsed(newState.slice(0, MAX_QUICK_ACCESS_ITEMS)); - }, [allApps, recentlyUsed, setRecentlyUsed]); + const listener = useCallback( + (location) => { + const newState = [...recentlyUsed]; + apps.forEach((app) => { + if (matchPath(location.pathname, { path: app.path, exact: true })) { + unshiftApp(newState, app); + } + }); + setRecentlyUsed(newState.slice(0, MAX_QUICK_ACCESS_ITEMS)); + }, + [apps, recentlyUsed, setRecentlyUsed] + ); history.listen(listener); diff --git a/phone/src/os/phone/hooks/usePhoneTheme.ts b/phone/src/os/phone/hooks/usePhoneTheme.ts new file mode 100644 index 0000000..4b21afa --- /dev/null +++ b/phone/src/os/phone/hooks/usePhoneTheme.ts @@ -0,0 +1,12 @@ +import { useMemo } from 'react'; +import { createMuiTheme } from '@material-ui/core'; +import { useSettings } from '../../../apps/settings/hooks/useSettings'; +import * as config from '../../../config/default.json'; + +export const usePhoneTheme = () => { + const [settings] = useSettings(); + + return useMemo(() => createMuiTheme(config.themes[settings.theme]), [ + settings.theme, + ]); +}; diff --git a/phone/src/ui/components/ContextMenu.tsx b/phone/src/ui/components/ContextMenu.tsx index 9a26a31..8423f0f 100644 --- a/phone/src/ui/components/ContextMenu.tsx +++ b/phone/src/ui/components/ContextMenu.tsx @@ -8,9 +8,12 @@ import { } from '@material-ui/core'; import { List } from './List'; import { ListItem } from './ListItem'; +import { useTranslation } from 'react-i18next'; const useStyles = makeStyles((theme) => ({ root: { + borderTop: '1px solid', + borderColor: theme.palette.primary.main, width: '100%', position: 'absolute', bottom: 0, @@ -18,25 +21,40 @@ const useStyles = makeStyles((theme) => ({ }, })); +interface IContextMenuOption { + onClick(e, option): void; + label: string; + description?: string; + selected?: boolean; + icon?: React.ReactNode; + key?: string; +}; + interface IContextMenuProps { open: boolean; onClose(): void; - options: Array<{ - onClick(e, option): void; - label: string; - selected?: boolean; - icon?: React.ReactNode; - key?: string; - }>; + options: Array; } export const ContextMenu = ({ open, onClose, options }: IContextMenuProps) => { const classes = useStyles(); + const { t } = useTranslation(); + + const _options = onClose + ? [ + ...options, + { + label: t('GENERIC_CLOSE'), + onClick: onClose, + } as IContextMenuOption, + ] + : options; + return ( - {options.map((option) => ( + {_options.map((option) => ( { onClose(); }} > - {option.icon && {option.icon}} - + {option.icon && {option.icon}} + ))} diff --git a/phone/src/ui/components/Snackbar.tsx b/phone/src/ui/components/Snackbar.tsx new file mode 100644 index 0000000..3fbeca1 --- /dev/null +++ b/phone/src/ui/components/Snackbar.tsx @@ -0,0 +1,30 @@ +import React from 'react'; +import { makeStyles } from '@material-ui/core'; +import { useTranslation } from 'react-i18next'; +import { useSnackbar } from '../hooks/useSnackbar'; +import Alert from './Alert'; + +const useStyles = makeStyles({ + root: { + marginTop: '-100px', + display: 'flex', + justifyContent: 'center', + alignItems: 'center', + }, +}); + +export const Snackbar = () => { + const classes = useStyles(); + const { t } = useTranslation(); + const { alert } = useSnackbar(); + + return ( +
+ {alert ? ( + + {t('APPS_' + alert.message)} + + ) : null} +
+ ); +}; diff --git a/phone/src/ui/hooks/useSnackbar.ts b/phone/src/ui/hooks/useSnackbar.ts index 0dc7588..b028718 100644 --- a/phone/src/ui/hooks/useSnackbar.ts +++ b/phone/src/ui/hooks/useSnackbar.ts @@ -4,7 +4,7 @@ import { SnackbarContext } from '../providers/SnackbarProvider'; export interface IAlert { message: string; - type: 'success' | 'error' + type: 'success' | 'error' | 'info' } interface ISnackBar { diff --git a/resources/client/client.ts b/resources/client/client.ts index f7a58e8..526700d 100644 --- a/resources/client/client.ts +++ b/resources/client/client.ts @@ -1,4 +1,3 @@ -import { Client } from 'esx.js'; import ClientUtils from './cl_utils'; import './cl_main'; @@ -12,12 +11,4 @@ import './cl_messages'; import './cl_call'; import './functions'; -export let ESX: Client = null; - -setTick(() => { - while (ESX === null) { - emit('esx:getSharedObject', (obj: Client) => (ESX = obj)); - } -}); - export const ClUtils = new ClientUtils();