From 4acb214ec93be9cf7ced9f96bc3e936bfeffd392 Mon Sep 17 00:00:00 2001 From: J Francisco Rader Date: Sun, 21 Feb 2021 12:41:25 -0500 Subject: [PATCH] Task/improve hardcoded styles and types (#107) * Add working notifications with only twitter for now * feat(notification-bar): I didnt copy from NP * feat(notifications): Collapse when no more notifications after closing one * Improve overall messages styling code * Improve Routing performance * improve use keyboard hook * Remove unused returns * Button hover color :) * Button hover color :) x2 * Added hover style to containedPrimary msg btn * Replace custom components for custom theme providers for Messages and Contacts apps * Improve createAppThemeProvider * Improve createAppThemeProvider * Final housekeeping for messages styles * Change placeholder to label in Contacts app text fields * Fix alerts style with navigation and fix calc copy alerrt * Split Phone code for snackbar * Add more options and style Context Menu * Enable Sellout theme provider and make it work with light themes --- phone/src/Phone.tsx | 44 +--- .../apps/calculator/components/Calculator.tsx | 13 +- .../src/apps/camera/hooks/usePhotoService.ts | 2 - .../src/apps/contacts/components/Contact.css | 3 - .../apps/contacts/components/ContactsApp.tsx | 31 +-- .../contacts/components/List/ContactList.tsx | 5 - .../contacts/components/views/ContactInfo.tsx | 79 +++--- .../components/views/ContactsPage.tsx | 2 +- phone/src/apps/contacts/constants.ts | 4 - phone/src/apps/contacts/contacts.theme.ts | 27 ++ .../apps/contacts/hooks/useContactsService.ts | 3 - .../providers/ContactsThemeProvider.tsx | 5 + phone/src/apps/dialer/hooks/useDialService.ts | 3 - .../apps/example/components/ExampleApp.tsx | 23 +- phone/src/apps/example/example.theme.ts | 9 + .../providers/ExampleThemeProvider.tsx | 5 + phone/src/apps/home/components/Home.tsx | 4 +- .../apps/messages/components/MessagesApp.tsx | 82 +++---- .../messages/components/form/MessageInput.tsx | 2 +- .../NewMessageGroupButton.tsx | 2 +- .../components/form/NewMessageGroupForm.tsx | 4 +- .../messages/components/list/list.styles.ts | 4 +- .../src/apps/messages/components/messages.css | 23 -- .../messages/components/messages.styles.ts | 11 - .../components/modal/Conversation.tsx | 33 +-- .../components/modal/MessageBubble.tsx | 75 ++++++ .../components/modal/MessageImageModal.tsx | 18 +- .../components/modal/MessageModal.tsx | 2 +- .../components/modal/MessageSkeleton.tsx | 11 +- .../messages/components/modal/modal.styles.ts | 37 +-- phone/src/apps/messages/messages.theme.ts | 17 ++ .../providers/MessagesThemeProvider.tsx | 4 + phone/src/apps/notes/hooks/useNotesService.ts | 2 - phone/src/apps/sellout/components/Sellout.css | 7 - .../apps/sellout/components/SelloutApp.tsx | 35 +-- .../components/SelloutList/SelloutItem.tsx | 9 +- .../apps/sellout/components/SelloutTitle.tsx | 4 +- .../sellout/components/form/ListingForm.tsx | 4 +- .../components/navigation/NavigationBar.tsx | 4 +- .../providers/SelloutThemeProvider.tsx | 5 + phone/src/apps/sellout/sellout.theme.ts | 14 ++ phone/src/locale/en.json | 5 +- phone/src/modal/hooks/useCallService.ts | 4 - phone/src/os/apps/components/AppRoute.tsx | 16 ++ .../src/os/apps/components/AppWithStartup.tsx | 9 + phone/src/os/apps/config/apps.tsx | 189 ++++++++++++++ phone/src/os/apps/hooks/useApps.tsx | 232 +----------------- .../os/apps/utils/createAppThemeProvider.tsx | 16 ++ phone/src/os/apps/utils/deepMergeObjects.ts | 32 +++ phone/src/os/keyboard/hooks/useKeyboard.ts | 26 +- .../components/NotificationBar.tsx | 4 +- .../os/notifications/hooks/useQuickAccess.tsx | 30 ++- phone/src/os/phone/hooks/usePhoneTheme.ts | 12 + phone/src/ui/components/ContextMenu.tsx | 38 ++- phone/src/ui/components/Snackbar.tsx | 30 +++ phone/src/ui/hooks/useSnackbar.ts | 2 +- 56 files changed, 738 insertions(+), 578 deletions(-) delete mode 100644 phone/src/apps/contacts/components/Contact.css delete mode 100644 phone/src/apps/contacts/constants.ts create mode 100644 phone/src/apps/contacts/contacts.theme.ts create mode 100644 phone/src/apps/contacts/providers/ContactsThemeProvider.tsx create mode 100644 phone/src/apps/example/example.theme.ts create mode 100644 phone/src/apps/example/providers/ExampleThemeProvider.tsx rename phone/src/apps/messages/components/{buttons => form}/NewMessageGroupButton.tsx (100%) delete mode 100644 phone/src/apps/messages/components/messages.css delete mode 100644 phone/src/apps/messages/components/messages.styles.ts create mode 100644 phone/src/apps/messages/components/modal/MessageBubble.tsx create mode 100644 phone/src/apps/messages/messages.theme.ts create mode 100644 phone/src/apps/messages/providers/MessagesThemeProvider.tsx delete mode 100644 phone/src/apps/sellout/components/Sellout.css create mode 100644 phone/src/apps/sellout/providers/SelloutThemeProvider.tsx create mode 100644 phone/src/apps/sellout/sellout.theme.ts create mode 100644 phone/src/os/apps/components/AppRoute.tsx create mode 100644 phone/src/os/apps/components/AppWithStartup.tsx create mode 100644 phone/src/os/apps/config/apps.tsx create mode 100644 phone/src/os/apps/utils/createAppThemeProvider.tsx create mode 100644 phone/src/os/apps/utils/deepMergeObjects.ts create mode 100644 phone/src/os/phone/hooks/usePhoneTheme.ts create mode 100644 phone/src/ui/components/Snackbar.tsx 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 82a985d..3c89e7c 100644 --- a/phone/src/apps/contacts/hooks/useContactsService.ts +++ b/phone/src/apps/contacts/hooks/useContactsService.ts @@ -1,13 +1,10 @@ import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; import { useSetRecoilState } from 'recoil'; import { contactsState } from './state'; -import { useContacts } from './useContacts'; -import { useContactAlert } from './useAlert'; export const useContactsService = () => { const setContacts = useSetRecoilState(contactsState.contacts); const setAlert = useSetRecoilState(contactsState.contactAlert); useNuiEvent('CONTACTS', 'setContacts', setContacts); useNuiEvent('CONTACTS', 'setAlert', setAlert); - return { useContacts, useContactAlert }; }; 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 0c39a35..049b0f6 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", @@ -103,6 +105,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 {