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
This commit is contained in:
J Francisco Rader authored and GitHub committed 2021-02-21 12:41:25 -05:00
1 parent 75e23b783c
commit 4acb214ec9
56 files changed
+738 -578

No files matched your search

+8 -36
View File
@@ -1,11 +1,10 @@
import React, { useMemo } from 'react'; import React from 'react';
import './Phone.css'; import './Phone.css';
import './i18n'; import './i18n';
import { Route } from 'react-router-dom'; import { Route } from 'react-router-dom';
import { CallModal } from './modal/components/CallModal'; import { CallModal } from './modal/components/CallModal';
import { Alert } from './ui/components/Alert';
import { HomeApp } from './apps/home/components/Home'; 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 { useInitKeyboard } from './os/keyboard/hooks/useKeyboard';
import { NotificationBar } from './os/notifications/components/NotificationBar'; import { NotificationBar } from './os/notifications/components/NotificationBar';
import { Navigation } from './os/navigation-bar/components/Navigation'; 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 { useMessagesService } from './apps/messages/hooks/useMessageService';
import { useNotesService } from './apps/notes/hooks/useNotesService'; import { useNotesService } from './apps/notes/hooks/useNotesService';
import { usePhotoService } from './apps/camera/hooks/usePhotoService'; import { usePhotoService } from './apps/camera/hooks/usePhotoService';
import Nui from './os/nui-events/utils/Nui';
import { useSettings } from './apps/settings/hooks/useSettings'; import { useSettings } from './apps/settings/hooks/useSettings';
import config from './config/default.json';
import { useCallService } from './modal/hooks/useCallService'; import { useCallService } from './modal/hooks/useCallService';
import { useModal } from './modal/hooks/useModal'; import { useModal } from './modal/hooks/useModal';
import { useDialService } from './apps/dialer/hooks/useDialService'; import { useDialService } from './apps/dialer/hooks/useDialService';
import InjectDebugData from './os/debug/InjectDebugData'; 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 { usePhoneVisibility } from './os/phone/hooks/usePhoneVisibility';
import { usePhoneTheme } from './os/phone/hooks/usePhoneTheme';
import { Snackbar } from './ui/components/Snackbar';
function Phone() { function Phone() {
const { t } = useTranslation();
const { alert } = useSnackbar();
const { modal } = useModal(); const { modal } = useModal();
const { allApps } = useApps(); const { apps } = useApps();
const [settings] = useSettings(); const [settings] = useSettings();
@@ -62,16 +56,7 @@ function Phone() {
useCallService(); useCallService();
useDialService(); useDialService();
const currentTheme = useMemo( const currentTheme = usePhoneTheme();
() => createMuiTheme(config.themes[settings.theme]),
[settings.theme]
);
document.onkeyup = function (data) {
if (data.which === 27) {
Nui.send('phone:close');
}
};
return ( return (
<ThemeProvider theme={currentTheme}> <ThemeProvider theme={currentTheme}>
@@ -108,25 +93,12 @@ function Phone() {
) : ( ) : (
<> <>
<Route exact path='/' component={HomeApp} /> <Route exact path='/' component={HomeApp} />
{allApps.map((App) => ( {apps.map((App) => (
<App.Route key={App.id} /> <App.Route key={App.id} />
))} ))}
</> </>
)} )}
{alert ? ( <Snackbar />
<div
style={{
marginTop: '-100px',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Alert severity={alert.type} variant='filled'>
{t('APPS_' + alert.message)}
</Alert>
</div>
) : null}
</div> </div>
<Navigation /> <Navigation />
</> </>
@@ -3,6 +3,7 @@ import { useCalculator, CalcButton } from '../hooks/useCalculator';
import { Grid, makeStyles, Box, Paper, Fab } from '@material-ui/core'; import { Grid, makeStyles, Box, Paper, Fab } from '@material-ui/core';
import { setClipboard } from '../../../os/phone/hooks/useClipboard'; import { setClipboard } from '../../../os/phone/hooks/useClipboard';
import FileCopyIcon from '@material-ui/icons/FileCopy'; import FileCopyIcon from '@material-ui/icons/FileCopy';
import { useSnackbar } from '../../../ui/hooks/useSnackbar';
const useStyles = makeStyles((theme) => ({ const useStyles = makeStyles((theme) => ({
button: { button: {
@@ -45,6 +46,9 @@ export const Calculator = ({ ...props }) => {
eight, eight,
nine, nine,
} = useCalculator(); } = useCalculator();
const { addAlert } = useSnackbar();
const classes = useStyles(); const classes = useStyles();
const resultStr = useMemo( const resultStr = useMemo(
() => () =>
@@ -58,7 +62,14 @@ export const Calculator = ({ ...props }) => {
return ( return (
<Box display='flex' flexDirection='column'> <Box display='flex' flexDirection='column'>
<Box flexGrow={1} component={Paper} p={4} className={classes.result}> <Box flexGrow={1} component={Paper} p={4} className={classes.result}>
<Fab size="small" onClick={() => setClipboard(resultStr)} className={classes.copyFab}> <Fab
size='small'
onClick={() => {
setClipboard(resultStr);
addAlert({ message: 'CALCULATOR_COPIED', type: 'info' });
}}
className={classes.copyFab}
>
<FileCopyIcon /> <FileCopyIcon />
</Fab> </Fab>
{resultStr} {resultStr}
@@ -1,10 +1,8 @@
import { useSetRecoilState } from 'recoil'; import { useSetRecoilState } from 'recoil';
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
import { photoState } from './state'; import { photoState } from './state';
import { usePhotos } from './usePhotos';
export const usePhotoService = () => { export const usePhotoService = () => {
const setPhotos = useSetRecoilState(photoState.photos); const setPhotos = useSetRecoilState(photoState.photos);
useNuiEvent('CAMERA', 'setPhotos', setPhotos); useNuiEvent('CAMERA', 'setPhotos', setPhotos);
return usePhotos();
}; };
@@ -1,3 +0,0 @@
#contact-app .Mui-focused::after {
border-bottom: #2196f3 solid 4px;
}
@@ -8,6 +8,23 @@ import { Route } from 'react-router-dom';
import ContactsInfoPage from './views/ContactInfo'; import ContactsInfoPage from './views/ContactInfo';
import { ContactPage } from './views/ContactsPage'; import { ContactPage } from './views/ContactsPage';
import { ContactsThemeProvider } from '../providers/ContactsThemeProvider';
export const ContactsApp = () => {
const contacts = useApp('CONTACTS');
return (
<ContactsThemeProvider>
<AppWrapper id='contact-app'>
<AppTitle app={contacts} />
<AppContent>
<Route path='/contacts/' exact component={ContactPage} />
<Route path='/contacts/:id' exact component={ContactsInfoPage} />
</AppContent>
</AppWrapper>
</ContactsThemeProvider>
);
};
InjectDebugData([ InjectDebugData([
{ {
@@ -33,17 +50,3 @@ InjectDebugData([
], ],
}, },
]); ]);
export const ContactsApp = () => {
const contacts = useApp('CONTACTS');
return (
<AppWrapper id='contact-app'>
<AppTitle app={contacts} />
<AppContent>
<Route path='/contacts/' exact component={ContactPage} />
<Route path='/contacts/:id' exact component={ContactsInfoPage} />
</AppContent>
</AppWrapper>
);
};
@@ -7,17 +7,12 @@ import {
List, List,
ListItem, ListItem,
} from '@material-ui/core'; } from '@material-ui/core';
import { useFilteredContacts } from '../../hooks/useFilteredContacts'; import { useFilteredContacts } from '../../hooks/useFilteredContacts';
import PhoneIcon from '@material-ui/icons/Phone'; import PhoneIcon from '@material-ui/icons/Phone';
import ChatIcon from '@material-ui/icons/Chat'; import ChatIcon from '@material-ui/icons/Chat';
import MoreVertIcon from '@material-ui/icons/MoreVert'; import MoreVertIcon from '@material-ui/icons/MoreVert';
import { useContacts } from '../../hooks/useContacts'; import { useContacts } from '../../hooks/useContacts';
import Nui from '../../../../os/nui-events/utils/Nui'; import Nui from '../../../../os/nui-events/utils/Nui';
import '../Contact.css';
import { SearchContacts } from './SearchContacts'; import { SearchContacts } from './SearchContacts';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import LogDebugEvent from '../../../../os/debug/LogDebugEvents'; import LogDebugEvent from '../../../../os/debug/LogDebugEvents';
@@ -1,6 +1,7 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { import {
Avatar as MuiAvatar, Avatar as MuiAvatar,
Box,
Button, Button,
Paper, Paper,
TextField, TextField,
@@ -43,28 +44,6 @@ const useStyles = makeStyles((theme: Theme) => ({
inputProps: { inputProps: {
fontSize: 22, 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 = () => { const ContactsInfoPage = () => {
@@ -96,7 +75,7 @@ const ContactsInfoPage = () => {
number, number,
avatar, avatar,
}); });
history.goBack() history.goBack();
}; };
const handleContactSave = () => { const handleContactSave = () => {
@@ -111,7 +90,7 @@ const ContactsInfoPage = () => {
number, number,
avatar, avatar,
}); });
history.goBack() history.goBack();
}; };
const handleContactDelete = () => { const handleContactDelete = () => {
@@ -123,7 +102,7 @@ const ContactsInfoPage = () => {
Nui.send('phone:deleteContact', { Nui.send('phone:deleteContact', {
id: contact.id, id: contact.id,
}); });
history.goBack() history.goBack();
}; };
return ( return (
@@ -137,7 +116,7 @@ const ContactsInfoPage = () => {
className={classes.input} className={classes.input}
value={name} value={name}
onChange={(e) => setName(e.target.value)} onChange={(e) => setName(e.target.value)}
placeholder={t('APPS_CONTACT_FORM_NAME')} label={t('APPS_CONTACT_FORM_NAME')}
fullWidth fullWidth
inputProps={{ inputProps={{
className: classes.inputProps, className: classes.inputProps,
@@ -147,7 +126,7 @@ const ContactsInfoPage = () => {
className={classes.input} className={classes.input}
value={number} value={number}
onChange={(e) => setNumber(e.target.value)} onChange={(e) => setNumber(e.target.value)}
placeholder={t('APPS_CONTACT_FORM_NUMBER')} label={t('APPS_CONTACT_FORM_NUMBER')}
fullWidth fullWidth
inputProps={{ inputProps={{
className: classes.inputProps, className: classes.inputProps,
@@ -155,7 +134,7 @@ const ContactsInfoPage = () => {
/> />
<TextField <TextField
className={classes.input} className={classes.input}
placeholder={t('APPS_CONTACT_FORM_AVATAR')} label={t('APPS_CONTACT_FORM_AVATAR')}
fullWidth fullWidth
value={avatar} value={avatar}
onChange={(e) => setAvatar(e.target.value)} onChange={(e) => setAvatar(e.target.value)}
@@ -165,28 +144,38 @@ const ContactsInfoPage = () => {
/> />
{/* Display if fetched contact */} {/* Display if fetched contact */}
{contact && ( {contact && (
<div style={{ display: 'block' }}> <>
<Button <Box py={1} display='block'>
onClick={handleContactSave} <Button
className={classes.updateButton} color='primary'
> variant='contained'
{t('GENERIC_UPDATE')} onClick={handleContactSave}
</Button> >
<Button {t('GENERIC_UPDATE')}
onClick={handleContactDelete} </Button>
className={classes.deleteButton} </Box>
> <Box py={1} display='block'>
{t('GENERIC_DELETE')} <Button
</Button> variant='contained'
</div> color='secondary'
onClick={handleContactDelete}
>
{t('GENERIC_DELETE')}
</Button>
</Box>
</>
)} )}
{/* Display if no fetched contact */} {/* Display if no fetched contact */}
{!contact && ( {!contact && (
<div style={{ display: 'block' }}> <Box display='block'>
<Button onClick={handleContactAdd} className={classes.saveButton}> <Button
color='primary'
variant='contained'
onClick={handleContactAdd}
>
{t('APPS_CONTACT_MODAL_BUTTON_ADD')} {t('APPS_CONTACT_MODAL_BUTTON_ADD')}
</Button> </Button>
</div> </Box>
)} )}
</div> </div>
</Paper> </Paper>
@@ -26,8 +26,8 @@ export const ContactPage = () => {
<> <>
<ContactList /> <ContactList />
<Fab <Fab
color='primary'
onClick={() => history.push('/contacts/-1')} onClick={() => history.push('/contacts/-1')}
style={{ backgroundColor: '#2196f3', color: '#fff' }}
className={classes.absolute} className={classes.absolute}
> >
<PersonAddIcon /> <PersonAddIcon />
-4
View File
@@ -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;
+27
View File
@@ -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;
@@ -1,13 +1,10 @@
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
import { useSetRecoilState } from 'recoil'; import { useSetRecoilState } from 'recoil';
import { contactsState } from './state'; import { contactsState } from './state';
import { useContacts } from './useContacts';
import { useContactAlert } from './useAlert';
export const useContactsService = () => { export const useContactsService = () => {
const setContacts = useSetRecoilState(contactsState.contacts); const setContacts = useSetRecoilState(contactsState.contacts);
const setAlert = useSetRecoilState(contactsState.contactAlert); const setAlert = useSetRecoilState(contactsState.contactAlert);
useNuiEvent('CONTACTS', 'setContacts', setContacts); useNuiEvent('CONTACTS', 'setContacts', setContacts);
useNuiEvent('CONTACTS', 'setAlert', setAlert); useNuiEvent('CONTACTS', 'setAlert', setAlert);
return { useContacts, useContactAlert };
}; };
@@ -0,0 +1,5 @@
import { createAppThemeProvider } from '../../../os/apps/utils/createAppThemeProvider';
import contactsTheme from '../contacts.theme';
export const ContactsThemeProvider = createAppThemeProvider(contactsTheme);
@@ -1,11 +1,8 @@
import { useSetRecoilState } from 'recoil'; import { useSetRecoilState } from 'recoil';
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
import { dialState } from './state'; import { dialState } from './state';
import { useDialHistory } from './useDialHistory';
export const useDialService = () => { export const useDialService = () => {
const setHistory = useSetRecoilState(dialState.history); const setHistory = useSetRecoilState(dialState.history);
useNuiEvent('DAILER', 'setHistory', setHistory); useNuiEvent('DAILER', 'setHistory', setHistory);
return useDialHistory();
}; };
@@ -4,20 +4,25 @@ import { AppWrapper } from '../../../ui/components';
import { AppContent } from '../../../ui/components/AppContent'; import { AppContent } from '../../../ui/components/AppContent';
import { useApp } from '../../../os/apps/hooks/useApps'; import { useApp } from '../../../os/apps/hooks/useApps';
import { useExample } from '../hooks/useExample'; 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 = () => { export const ExampleApp = () => {
// calling the example hook, and we assign the value to a variable // calling the example hook, and we assign the value to a variable
const exampleString = useExample(); const exampleString = useExample();
const example = useApp('EXAMPLE'); const example = useApp('EXAMPLE');
return ( return (
<AppWrapper> <ExampleThemeProvider>
<AppContent> <AppWrapper>
<h1>This is an example</h1> <AppTitle app={example} />
<h2>{example.id}</h2> <AppContent>
{/* Here we are using the value in a h3 tag */} <h1>This is an example</h1>
<h3>{exampleString}</h3> <Button color='primary'>{example.id}</Button>
</AppContent> {/* Here we are using the value in a h3 tag */}
</AppWrapper> <h3>{exampleString}</h3>
</AppContent>
</AppWrapper>
</ExampleThemeProvider>
); );
}; };
+9
View File
@@ -0,0 +1,9 @@
const theme = {
palette: {
primary: {
main: '#f23123'
}
}
}
export default theme;
@@ -0,0 +1,5 @@
import { createAppThemeProvider } from '../../../os/apps/utils/createAppThemeProvider';
import exampleTheme from '../example.theme';
export const ExampleThemeProvider = createAppThemeProvider(exampleTheme);
+2 -2
View File
@@ -5,11 +5,11 @@ import { GridMenu } from '../../../ui/components/GridMenu';
import { useApps } from '../../../os/apps/hooks/useApps'; import { useApps } from '../../../os/apps/hooks/useApps';
export const HomeApp = () => { export const HomeApp = () => {
const { allApps } = useApps(); const { apps } = useApps();
return ( return (
<AppWrapper> <AppWrapper>
<Box width='100%' mt={6} px={1}> <Box width='100%' mt={6} px={1}>
{allApps && <GridMenu items={allApps} />} {apps && <GridMenu items={apps} />}
</Box> </Box>
</AppWrapper> </AppWrapper>
); );
@@ -1,4 +1,3 @@
import './messages.css';
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import { AppWrapper } from '../../../ui/components'; import { AppWrapper } from '../../../ui/components';
import { AppTitle } from '../../../ui/components/AppTitle'; import { AppTitle } from '../../../ui/components/AppTitle';
@@ -10,8 +9,9 @@ import MessagesList from './list/MessagesList';
import { Route, Switch, useHistory } from 'react-router-dom'; import { Route, Switch, useHistory } from 'react-router-dom';
import { MessageModal } from './modal/MessageModal'; import { MessageModal } from './modal/MessageModal';
import InjectDebugData from '../../../os/debug/InjectDebugData'; 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 Nui from '../../../os/nui-events/utils/Nui';
import { MessagesThemeProvider } from '../providers/MessagesThemeProvider';
export const MessagesApp = () => { export const MessagesApp = () => {
const messages = useApp('MESSAGES'); const messages = useApp('MESSAGES');
@@ -22,37 +22,37 @@ export const MessagesApp = () => {
}, []); }, []);
return ( return (
<AppWrapper id='messages-app'> <MessagesThemeProvider>
<AppTitle app={messages} /> <AppWrapper id='messages-app'>
<AppContent> <AppTitle app={messages} />
<Switch> <AppContent>
<Route <Switch>
path='/messages/conversations/:groupId' <Route
component={MessageModal} path='/messages/conversations/:groupId'
/> component={MessageModal}
<Route />
exact <Route
path='/messages' exact
render={() => ( path='/messages'
<> render={() => (
<MessagesList /> <>
</> <MessagesList />
)} </>
/> )}
</Switch> />
<Switch> </Switch>
<Route <Switch>
exact <Route
path={['/messages/new/:phoneNumber', '/messages/new']} exact
render={() => <MessageGroupModal />} path={['/messages/new/:phoneNumber', '/messages/new']}
/> render={() => <MessageGroupModal />}
</Switch> />
</AppContent> </Switch>
<NewMessageGroupButton </AppContent>
onClick={() => history.push('/messages/new')} <NewMessageGroupButton onClick={() => history.push('/messages/new')} />
/> <AlertBar />
<AlertBar /> </AppWrapper>
</AppWrapper> </MessagesThemeProvider>
); );
}; };
@@ -73,7 +73,7 @@ InjectDebugData([
updatedAt: Date.now(), updatedAt: Date.now(),
}, },
{ {
id: 1, id: 2,
message: 'sup!', message: 'sup!',
user_identifier: '1234', user_identifier: '1234',
phone_number: '444-4444', phone_number: '444-4444',
@@ -84,7 +84,7 @@ InjectDebugData([
updatedAt: Date.now(), updatedAt: Date.now(),
}, },
{ {
id: 1, id: 3,
message: 'sup!', message: 'sup!',
user_identifier: '1234', user_identifier: '1234',
phone_number: '444-4444', phone_number: '444-4444',
@@ -95,7 +95,7 @@ InjectDebugData([
updatedAt: Date.now(), updatedAt: Date.now(),
}, },
{ {
id: 1, id: 4,
message: 'sup!', message: 'sup!',
user_identifier: '1234', user_identifier: '1234',
phone_number: '444-4444', phone_number: '444-4444',
@@ -106,7 +106,7 @@ InjectDebugData([
updatedAt: Date.now(), updatedAt: Date.now(),
}, },
{ {
id: 1, id: 5,
message: 'sup!', message: 'sup!',
user_identifier: '1234', user_identifier: '1234',
phone_number: '444-4444', phone_number: '444-4444',
@@ -117,7 +117,7 @@ InjectDebugData([
updatedAt: Date.now(), updatedAt: Date.now(),
}, },
{ {
id: 1, id: 6,
message: 'sup!', message: 'sup!',
user_identifier: '1234', user_identifier: '1234',
phone_number: '444-4444', phone_number: '444-4444',
@@ -128,7 +128,7 @@ InjectDebugData([
updatedAt: Date.now(), updatedAt: Date.now(),
}, },
{ {
id: 1, id: 7,
message: 'sup!', message: 'sup!',
user_identifier: '1234', user_identifier: '1234',
phone_number: '444-4444', phone_number: '444-4444',
@@ -139,7 +139,7 @@ InjectDebugData([
updatedAt: Date.now(), updatedAt: Date.now(),
}, },
{ {
id: 1, id: 8,
message: 'sup!', message: 'sup!',
user_identifier: '1234', user_identifier: '1234',
phone_number: '444-4444', phone_number: '444-4444',
@@ -150,7 +150,7 @@ InjectDebugData([
updatedAt: Date.now(), updatedAt: Date.now(),
}, },
{ {
id: 1, id: 9,
message: 'sup!', message: 'sup!',
user_identifier: '1234', user_identifier: '1234',
phone_number: '444-4444', phone_number: '444-4444',
@@ -1,6 +1,6 @@
import React, { FormEvent, useState } from 'react'; import React, { FormEvent, useState } from 'react';
import { useTranslation } from 'react-i18next'; 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 SendIcon from '@material-ui/icons/Send';
import ImageIcon from '@material-ui/icons/Image'; import ImageIcon from '@material-ui/icons/Image';
import Nui from '../../../../os/nui-events/utils/Nui'; import Nui from '../../../../os/nui-events/utils/Nui';
@@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import { makeStyles } from '@material-ui/core/styles'; import { makeStyles } from '@material-ui/core/styles';
import { Fab } from '@material-ui/core';
import AddIcon from '@material-ui/icons/Add'; import AddIcon from '@material-ui/icons/Add';
import { Fab } from '@material-ui/core';
const useStyles = makeStyles((theme) => ({ const useStyles = makeStyles((theme) => ({
root: { root: {
@@ -1,6 +1,6 @@
import React, { FormEvent, useCallback, useEffect, useState } from 'react'; import React, { FormEvent, useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next'; 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 Nui from '../../../../os/nui-events/utils/Nui';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
@@ -102,7 +102,7 @@ const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => {
)} )}
<Box px={2} py={3}> <Box px={2} py={3}>
<Button disabled={submitDisabled} variant='contained' fullWidth color='primary' type='submit'> <Button disabled={submitDisabled} variant='contained' fullWidth color='primary' type='submit'>
{t('APPS_MESSAGES_NEW_MESSAGE_GROUP_SUBMIT')} {t('APPS_MESSAGES_NEW_MESSAGE_GROUP_SUBMIT')}
</Button> </Button>
</Box> </Box>
</form> </form>
@@ -17,6 +17,8 @@ const useStyles = makeStyles((theme) => ({
inputRoot: { inputRoot: {
fontWeight: 400, fontWeight: 400,
fontSize: 18, fontSize: 18,
border: '1px solid',
borderColor: theme.palette.divider,
}, },
inputInput: { inputInput: {
padding: theme.spacing(1, 4, 1, 4), padding: theme.spacing(1, 4, 1, 4),
@@ -27,7 +29,7 @@ const useStyles = makeStyles((theme) => ({
[theme.breakpoints.up('sm')]: { [theme.breakpoints.up('sm')]: {
width: '13ch', width: '13ch',
'&:focus': { '&:focus': {
width: '20ch', width: '24ch',
}, },
}, },
}, },
@@ -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;
}
@@ -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;
@@ -1,11 +1,12 @@
import React, { useState } from 'react'; 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 { Message, MessageGroup } from '../../../../common/typings/messages';
import MessageInput from '../form/MessageInput'; import MessageInput from '../form/MessageInput';
import useStyles from './modal.styles'; import useStyles from './modal.styles';
import { MessageImageModal } from './MessageImageModal'; import { MessageImageModal } from './MessageImageModal';
import { useQueryParams } from '../../../../common/hooks/useQueryParams'; import { useQueryParams } from '../../../../common/hooks/useQueryParams';
import { MessageBubble } from './MessageBubble';
interface IProps { interface IProps {
activeMessageGroup: MessageGroup; activeMessageGroup: MessageGroup;
@@ -20,10 +21,6 @@ const Conversation = ({ activeMessageGroup, messages }: IProps) => {
const query = useQueryParams(); const query = useQueryParams();
const referalImage = query?.image || null; const referalImage = query?.image || null;
const isImage = (url) => {
return /(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|png|jpeg|gif)/g.test(url);
};
return ( return (
<> <>
<MessageImageModal <MessageImageModal
@@ -41,27 +38,11 @@ const Conversation = ({ activeMessageGroup, messages }: IProps) => {
className={classes.overflowAutoY} className={classes.overflowAutoY}
> >
{messages.map((message) => ( {messages.map((message) => (
<div key={message.id}> <MessageBubble
<Paper key={message.id}
className={message.isMine ? classes.sourceSms : classes.sms} message={message}
variant='outlined' isGroupChat={activeMessageGroup?.isGroupChat}
> />
{isImage(message.message) ? (
<img
src={message.message}
className={classes.imageMessage}
alt='multimedia'
/>
) : (
<div>{message.message}</div>
)}
<Typography variant='subtitle1' color='secondary'>
{activeMessageGroup.isGroupChat && !message.isMine
? message.display || message.phone_number
: null}
</Typography>
</Paper>
</div>
))} ))}
</Box> </Box>
<MessageInput <MessageInput
@@ -0,0 +1,75 @@
import { Box, makeStyles, Paper, Typography } from '@material-ui/core';
import React from 'react';
import { Message } from '../../../../common/typings/messages';
const useStyles = makeStyles((theme) => ({
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 (
<div>
<Paper
className={message.isMine ? classes.mySms : classes.sms}
variant='outlined'
>
<Box>
{isImage(message.message) ? (
<img
src={message.message}
className={classes.imageMessage}
alt='multimedia'
/>
) : (
<div>{message.message}</div>
)}
</Box>
<Box textAlign='right'>
<Typography variant='subtitle1' color='secondary'>
{isGroupChat && !message.isMine
? message.display || message.phone_number
: null}
</Typography>
</Box>
</Paper>
</div>
);
};
@@ -1,10 +1,9 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react'; import React, { useCallback, useEffect, useMemo, useState } from 'react';
import qs from 'qs'; import qs from 'qs';
import Nui from '../../../../os/nui-events/utils/Nui'; import Nui from '../../../../os/nui-events/utils/Nui';
import CloseIcon from '@material-ui/icons/Close';
import Modal from '../../../../ui/components/Modal'; import Modal from '../../../../ui/components/Modal';
import PhotoLibraryIcon from '@material-ui/icons/PhotoLibrary'; 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 FileCopyIcon from '@material-ui/icons/FileCopy';
import useStyles from './modal.styles'; import useStyles from './modal.styles';
import { useHistory, useLocation } from 'react-router-dom'; import { useHistory, useLocation } from 'react-router-dom';
@@ -85,13 +84,9 @@ export const MessageImageModal = ({
})}` })}`
), ),
}, },
{
label: 'Cancel',
icon: <CloseIcon />,
onClick: onClose,
},
], ],
[onClose, history, pathname, search] [history, pathname, search]
); );
return ( return (
@@ -110,6 +105,7 @@ export const MessageImageModal = ({
<Button <Button
fullWidth fullWidth
variant='contained' variant='contained'
color='primary'
onClick={() => sendFromQueryParam(queryParamImagePreview)} onClick={() => sendFromQueryParam(queryParamImagePreview)}
> >
Share Share
@@ -117,19 +113,19 @@ export const MessageImageModal = ({
</Box> </Box>
</Modal> </Modal>
<Modal visible={pasteVisible} handleClose={() => setPasteVisible(false)}> <Modal visible={pasteVisible} handleClose={() => setPasteVisible(false)}>
<div> <Box p={1}>
<TextField <TextField
placeholder='A link to your image or gif' placeholder='A link to your image or gif'
onChange={(e) => setMessage(e.target.value)} onChange={(e) => setMessage(e.target.value)}
value={message} value={message}
className={classes.input} fullWidth
inputProps={{ inputProps={{
className: classes.messagesInput, className: classes.messagesInput,
}} }}
inputRef={(input) => input && input.focus()} inputRef={(input) => input && input.focus()}
onKeyPress={sendFromClipboard} onKeyPress={sendFromClipboard}
/> />
</div> </Box>
</Modal> </Modal>
</> </>
); );
@@ -1,5 +1,5 @@
import React, { useEffect, useRef, useState } from 'react'; import React, { useEffect, useRef, useState } from 'react';
import { Slide, Paper, Button, Typography } from '@material-ui/core'; import { Slide, Paper, Typography, Button } from '@material-ui/core';
import ArrowBackIcon from '@material-ui/icons/ArrowBack'; import ArrowBackIcon from '@material-ui/icons/ArrowBack';
import useStyles from './modal.styles'; import useStyles from './modal.styles';
@@ -6,6 +6,10 @@ const useStyles = makeStyles({
root: { root: {
margin: '0px 0px 12px 8px', margin: '0px 0px 12px 8px',
}, },
skeleton: {
borderRadius: '20px',
transform: 'none',
},
}); });
export default function MessageSkeleton({ height, isMine = false }) { export default function MessageSkeleton({ height, isMine = false }) {
@@ -14,7 +18,12 @@ export default function MessageSkeleton({ height, isMine = false }) {
const marginLeft = isMine ? '60px' : '8px'; const marginLeft = isMine ? '60px' : '8px';
return ( return (
<div className={classes.root} style={{ marginLeft, height: `${height}px` }}> <div className={classes.root} style={{ marginLeft, height: `${height}px` }}>
<Skeleton variant='text' width={325} height={height} /> <Skeleton
className={classes.skeleton}
variant='text'
width={325}
height={height}
/>
</div> </div>
); );
} }
@@ -1,8 +1,8 @@
import { makeStyles } from '@material-ui/core'; import { makeStyles } from '@material-ui/core';
const useStyles = makeStyles((theme) => ({ const useStyles = makeStyles({
modalRoot: { modalRoot: {
zIndex: 10, zIndex: 9,
position: 'absolute', position: 'absolute',
height: '100%', height: '100%',
width: '100%', width: '100%',
@@ -31,40 +31,9 @@ const useStyles = makeStyles((theme) => ({
paddingTop: '8px', paddingTop: '8px',
fontSize: '20px', fontSize: '20px',
}, },
sourceSms: {
float: 'right',
margin: 10,
padding: '6px 12px',
height: 'auto',
width: '80%',
background: '#0288d1',
borderRadius: '20px',
textOverflow: 'ellipsis',
},
sms: {
float: 'left',
margin: 10,
padding: '6px 12px',
width: '80%',
height: 'auto',
background: '#ddd',
color: '#232323',
borderRadius: '15px',
textOverflow: 'ellipsis',
},
messagesInput: { messagesInput: {
fontSize: 20, fontSize: 20,
}, },
input: { });
width: '100%',
margin: 10,
},
imageMessage: {
width: '80%',
maxWidth: '80%',
height: '80%',
maxHeight: '80%',
},
}));
export default useStyles; export default useStyles;
+17
View File
@@ -0,0 +1,17 @@
import { amber, common } from '@material-ui/core/colors';
export const MESSAGES_APP_PRIMARY_COLOR = amber[800];
export const MESSAGES_APP_TEXT_COLOR = common.white;
const theme = {
palette: {
primary: {
main: MESSAGES_APP_PRIMARY_COLOR,
dark: amber[900],
light: amber[100],
contrastText: MESSAGES_APP_TEXT_COLOR
},
},
};
export default theme;
@@ -0,0 +1,4 @@
import { createAppThemeProvider } from '../../../os/apps/utils/createAppThemeProvider';
import messagesTheme from '../messages.theme';
export const MessagesThemeProvider = createAppThemeProvider(messagesTheme);
@@ -1,6 +1,5 @@
import { useSetRecoilState } from 'recoil'; import { useSetRecoilState } from 'recoil';
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
import { useNotes } from './useNotes';
import { noteStates } from './state'; import { noteStates } from './state';
import { useSnackbar } from '../../../ui/hooks/useSnackbar'; import { useSnackbar } from '../../../ui/hooks/useSnackbar';
@@ -10,5 +9,4 @@ export const useNotesService = () => {
useNuiEvent('NOTES', 'setNotes', setNotes); useNuiEvent('NOTES', 'setNotes', setNotes);
useNuiEvent('NOTES', 'setAlert', addAlert); useNuiEvent('NOTES', 'setAlert', addAlert);
return useNotes();
}; };
@@ -1,7 +0,0 @@
#sellout-app .Mui-selected {
color: #f44336 !important;
}
#sellout-app .Mui-focused::after {
border-bottom: #f44336 solid 3px;
}
@@ -5,10 +5,26 @@ import { SelloutTitle } from './SelloutTitle';
import { SelloutListContainer } from './SelloutList/SelloutListContainer'; import { SelloutListContainer } from './SelloutList/SelloutListContainer';
import { NavigationBar } from './navigation/NavigationBar'; import { NavigationBar } from './navigation/NavigationBar';
import { Switch, Route } from 'react-router-dom'; import { Switch, Route } from 'react-router-dom';
import './Sellout.css';
import { ListingFormContainer } from './form/ListingFormContainer'; import { ListingFormContainer } from './form/ListingFormContainer';
import InjectDebugData from '../../../os/debug/InjectDebugData'; import InjectDebugData from '../../../os/debug/InjectDebugData';
import { SelloutThemeProvider } from '../providers/SelloutThemeProvider';
export const SelloutApp = () => {
return (
<SelloutThemeProvider>
<AppWrapper id='sellout-app'>
<SelloutTitle />
<AppContent>
<Switch>
<Route path='/sellout' exact component={SelloutListContainer} />
<Route path='/sellout/new' component={ListingFormContainer} />
</Switch>
</AppContent>
<NavigationBar />
</AppWrapper>
</SelloutThemeProvider>
);
};
InjectDebugData([ InjectDebugData([
{ {
@@ -34,18 +50,3 @@ InjectDebugData([
], ],
}, },
]); ]);
export const SelloutApp = () => {
return (
<AppWrapper id='sellout-app'>
<SelloutTitle />
<AppContent>
<Switch>
<Route path='/sellout' exact component={SelloutListContainer} />
<Route path='/sellout/new' component={ListingFormContainer} />
</Switch>
</AppContent>
<NavigationBar />
</AppWrapper>
);
};
@@ -27,9 +27,12 @@ const useStyles = makeStyles((theme) => ({
flexFlow: 'column', flexFlow: 'column',
alignItems: 'flex', alignItems: 'flex',
height: 'auto', height: 'auto',
background: '#232323', background: theme.palette.background.default,
marginBottom: 20, marginBottom: 20,
}, },
icon: {
color: theme.palette.primary.main
},
header: { header: {
margin: 10, margin: 10,
}, },
@@ -79,10 +82,10 @@ export const SelloutItem = (listing) => {
</Typography> </Typography>
<div> <div>
<Button> <Button>
<ChatIcon style={{ color: '#f44336' }} /> <ChatIcon className={classes.icon} />
</Button> </Button>
<Button> <Button>
<PhoneIcon style={{ color: '#f44336' }} /> <PhoneIcon className={classes.icon} />
</Button> </Button>
</div> </div>
</Paper> </Paper>
@@ -12,10 +12,10 @@ const useStyles = makeStyles((theme) => ({
flexFlow: 'row nowrap', flexFlow: 'row nowrap',
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
background: '#262525', background: theme.palette.background.default,
}, },
icon: { icon: {
color: '#f44336', color: theme.palette.primary.main,
fontSize: 40, fontSize: 40,
}, },
})); }));
@@ -2,8 +2,6 @@ import React, { useState } from 'react';
import { makeStyles, Button, TextField } from '@material-ui/core'; import { makeStyles, Button, TextField } from '@material-ui/core';
import Nui from '../../../../os/nui-events/utils/Nui'; import Nui from '../../../../os/nui-events/utils/Nui';
import '../Sellout.css';
const useStyles = makeStyles((theme) => ({ const useStyles = makeStyles((theme) => ({
root: { root: {
width: '100%', width: '100%',
@@ -22,7 +20,7 @@ const useStyles = makeStyles((theme) => ({
postButton: { postButton: {
display: 'block', display: 'block',
margin: 'auto', margin: 'auto',
background: '#f44336', background: theme.palette.primary.main,
width: '80%', width: '80%',
fontSize: 20, fontSize: 20,
}, },
@@ -9,10 +9,10 @@ import AddCircleIcon from '@material-ui/icons/AddCircle';
const useStyles = makeStyles((theme) => ({ const useStyles = makeStyles((theme) => ({
root: { root: {
width: '100%', width: '100%',
backgroundColor: '#262525', backgroundColor: theme.palette.background.default,
}, },
icon: { icon: {
color: '#f44336', color: theme.palette.primary.main,
}, },
})); }));
@@ -0,0 +1,5 @@
import { createAppThemeProvider } from "../../../os/apps/utils/createAppThemeProvider";
import selloutTheme from '../sellout.theme';
export const SelloutThemeProvider = createAppThemeProvider(selloutTheme);
+14
View File
@@ -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;
+4 -1
View File
@@ -93,6 +93,8 @@
"APPS_NOTES_DELETE_SUCCESS": "Successfully deleted note.", "APPS_NOTES_DELETE_SUCCESS": "Successfully deleted note.",
"APPS_NOTES_DELETE_FAILED": "Failed to delete 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_PHONE_NUMBER": "Phone Number",
"APPS_SETTINGS_OPTION_WALLPAPER": "Wallpaper", "APPS_SETTINGS_OPTION_WALLPAPER": "Wallpaper",
"APPS_SETTINGS_OPTION_FRAME": "Frame", "APPS_SETTINGS_OPTION_FRAME": "Frame",
@@ -103,6 +105,7 @@
"GENERIC_SAVE": "Save", "GENERIC_SAVE": "Save",
"GENERIC_UPDATE": "Update", "GENERIC_UPDATE": "Update",
"GENERIC_DELETE": "Delete" "GENERIC_DELETE": "Delete",
"GENERIC_CLOSE": "Close"
} }
} }
-4
View File
@@ -1,8 +1,6 @@
import { useNuiEvent } from '../../os/nui-events/hooks/useNuiEvent'; import { useNuiEvent } from '../../os/nui-events/hooks/useNuiEvent';
import { useRecoilState, useSetRecoilState } from 'recoil'; import { useRecoilState, useSetRecoilState } from 'recoil';
import { callerState } from './state'; import { callerState } from './state';
import { useCall } from './useCall';
import { useModal } from './useModal';
export const useCallService = () => { export const useCallService = () => {
const [caller, setCaller] = useRecoilState(callerState.currentCall); const [caller, setCaller] = useRecoilState(callerState.currentCall);
@@ -10,6 +8,4 @@ export const useCallService = () => {
useNuiEvent('CALL', 'setCaller', setCaller, {}, caller); useNuiEvent('CALL', 'setCaller', setCaller, {}, caller);
useNuiEvent('CALL', 'callModal', setModal); useNuiEvent('CALL', 'callModal', setModal);
return { useCall, useModal };
}; };
+16
View File
@@ -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 (
<Route
{...rest}
render={() => (
<AppWithStartup id={id}>
<Component />
</AppWithStartup>
)}
/>
);
};
@@ -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;
};
+189
View File
@@ -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: <FontAwesomeIcon icon={faPhoneAlt} size='xs' />,
notificationIcon: <FontAwesomeIcon icon={faPhoneAlt} size='xs' />,
backgroundColor: green[600],
color: common.white,
path: '/phone',
Route: () => <AppRoute id='DIALER' path='/phone' component={DialerApp} />,
},
{
id: 'MESSAGES',
nameLocale: 'APPS_MESSAGES',
icon: <MessageIcon fontSize='default' />,
notificationIcon: <MessageIcon fontSize='small' />,
backgroundColor: MESSAGES_APP_PRIMARY_COLOR,
color: MESSAGES_APP_TEXT_COLOR,
path: '/messages',
Route: () => (
<AppRoute id='MESSAGE' path='/messages' component={MessagesApp} />
),
},
{
id: 'CONTACTS',
nameLocale: 'APPS_CONTACTS',
icon: <ContactsIcon />,
notificationIcon: <ContactsIcon fontSize='small' />,
backgroundColor: CONTACTS_APP_PRIMARY_COLOR,
color: CONTACTS_APP_TEXT_COLOR,
path: '/contacts',
Route: () => (
<AppRoute id='CONTACTS' path='/contacts' component={ContactsApp} />
),
},
{
id: 'CALCULATOR',
nameLocale: 'APPS_CALCULATOR',
icon: <CalculatorIcon />,
notificationIcon: <CalculatorIcon fontSize='small' />,
backgroundColor: purple[500],
color: grey[50],
path: '/calculator',
Route: () => (
<AppRoute id='CALCULATOR' path='/calculator' component={CalculatorApp} />
),
},
{
id: 'SETTINGS',
nameLocale: 'APPS_SETTINGS',
icon: <SettingsIcon />,
notificationIcon: <SettingsIcon fontSize='small' />,
backgroundColor: '#383838',
color: grey[50],
path: '/settings',
Route: () => (
<AppRoute id='SETTINGS' path='/settings' component={SettingsApp} />
),
},
{
id: 'BANK',
nameLocale: 'APPS_BANK',
icon: <FontAwesomeIcon icon={faWonSign} size='xs' />,
notificationIcon: <FontAwesomeIcon icon={faWonSign} size='xs' />,
backgroundColor: blue[900],
color: common.white,
path: '/bank',
Route: () => <AppRoute id='BANK' path='/bank' component={BankApp} />,
},
{
id: 'TWITTER',
nameLocale: 'APPS_TWITTER',
icon: <FontAwesomeIcon icon={faTwitter} fixedWidth size='xs' />,
notificationIcon: <FontAwesomeIcon icon={faTwitter} fixedWidth size='xs' />,
backgroundColor: blue[600],
color: common.white,
path: '/twitter',
Route: () => (
<AppRoute id='TWITTER' path='/twitter' component={TwitterApp} />
),
},
{
id: 'SELLOUT',
nameLocale: 'APPS_SELLOUT',
icon: <FontAwesomeIcon icon={faAd} fixedWidth />,
notificationIcon: <FontAwesomeIcon icon={faAd} fixedWidth size='xs' />,
backgroundColor: red[500],
color: common.white,
path: '/sellout',
Route: () => (
<AppRoute id='SELLOUT' path='/sellout' component={SelloutApp} />
),
},
{
id: 'NOTES',
nameLocale: 'APPS_NOTES',
icon: <FontAwesomeIcon icon={faStickyNote} fixedWidth />,
notificationIcon: (
<FontAwesomeIcon icon={faStickyNote} fixedWidth size='xs' />
),
backgroundColor: yellow[800],
color: common.white,
path: '/notes',
Route: () => <AppRoute id='NOTES' path='/notes' component={NotesApp} />,
},
{
id: 'CAMERA',
nameLocale: 'APPS_CAMERA',
icon: <CameraAltIcon fontSize='large' />,
notificationIcon: <CameraAltIcon fontSize='small' />,
backgroundColor: grey['A400'],
color: common.white,
path: '/camera',
Route: () => <AppRoute id='CAMERA' path='/camera' component={CameraApp} />,
},
];
// Example app only in dev
if (process.env.NODE_ENV === 'development') {
APPS.push({
id: 'EXAMPLE',
nameLocale: 'APPS_EXAMPLE',
icon: <FontAwesomeIcon icon={faPlaneArrival} size='sm' />,
notificationIcon: <FontAwesomeIcon icon={faPlaneArrival} size='xs' />,
backgroundColor: blue[500],
color: blue[50],
path: '/example',
Route: () => (
<AppRoute id='EXAMPLE' path='/example' component={ExampleApp} />
),
});
}
+8 -224
View File
@@ -1,238 +1,22 @@
import React, { useCallback, useEffect, useMemo } from 'react'; import { useCallback, 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 { useNotifications } from '../../notifications/hooks/useNotifications'; import { useNotifications } from '../../notifications/hooks/useNotifications';
import { APPS, IAppConfig } from '../config/apps';
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 (
<Route
{...rest}
render={() => (
<AppWithStartup id={id}>
<Component />
</AppWithStartup>
)}
/>
);
};
const appsState = atom<AppsRepository>({
key: 'apps',
default: {
preinstalled: [
{
id: 'DIALER',
nameLocale: 'APPS_DIALER',
icon: <FontAwesomeIcon icon={faPhoneAlt} size='xs' />,
notificationIcon: <FontAwesomeIcon icon={faPhoneAlt} size='xs' />,
backgroundColor: green[600],
color: common.white,
path: '/phone',
Route: () => (
<AppRoute id='DIALER' path='/phone' component={DialerApp} />
),
},
{
id: 'MESSAGES',
nameLocale: 'APPS_MESSAGES',
icon: <MessageIcon fontSize='default' />,
notificationIcon: <MessageIcon fontSize='small' />,
backgroundColor: amber[700],
color: common.white,
path: '/messages',
Route: () => (
<AppRoute id='MESSAGE' path='/messages' component={MessagesApp} />
),
},
{
id: 'CONTACTS',
nameLocale: 'APPS_CONTACTS',
icon: <ContactsIcon />,
notificationIcon: <ContactsIcon fontSize='small' />,
backgroundColor: blue[500],
color: common.white,
path: '/contacts',
Route: () => (
<AppRoute id='CONTACTS' path='/contacts' component={ContactsApp} />
),
},
{
id: 'CALCULATOR',
nameLocale: 'APPS_CALCULATOR',
icon: <CalculatorIcon />,
notificationIcon: <CalculatorIcon fontSize='small' />,
backgroundColor: purple[500],
color: grey[50],
path: '/calculator',
Route: () => (
<AppRoute
id='CALCULATOR'
path='/calculator'
component={CalculatorApp}
/>
),
},
{
id: 'SETTINGS',
nameLocale: 'APPS_SETTINGS',
icon: <SettingsIcon />,
notificationIcon: <SettingsIcon fontSize='small' />,
backgroundColor: '#383838',
color: grey[50],
path: '/settings',
Route: () => (
<AppRoute id='SETTINGS' path='/settings' component={SettingsApp} />
),
},
{
id: 'BANK',
nameLocale: 'APPS_BANK',
icon: <FontAwesomeIcon icon={faWonSign} size='xs' />,
notificationIcon: <FontAwesomeIcon icon={faWonSign} size='xs' />,
backgroundColor: blue[900],
color: common.white,
path: '/bank',
Route: () => <AppRoute id='BANK' path='/bank' component={BankApp} />,
},
{
id: 'TWITTER',
nameLocale: 'APPS_TWITTER',
icon: <FontAwesomeIcon icon={faTwitter} fixedWidth size='xs' />,
notificationIcon: (
<FontAwesomeIcon icon={faTwitter} fixedWidth size='xs' />
),
backgroundColor: blue[600],
color: common.white,
path: '/twitter',
Route: () => (
<AppRoute id='TWITTER' path='/twitter' component={TwitterApp} />
),
},
{
id: 'SELLOUT',
nameLocale: 'APPS_SELLOUT',
icon: <FontAwesomeIcon icon={faAd} fixedWidth />,
notificationIcon: <FontAwesomeIcon icon={faAd} fixedWidth size='xs' />,
backgroundColor: red[500],
color: common.white,
path: '/sellout',
Route: () => (
<AppRoute id='SELLOUT' path='/sellout' component={SelloutApp} />
),
},
{
id: 'NOTES',
nameLocale: 'APPS_NOTES',
icon: <FontAwesomeIcon icon={faStickyNote} fixedWidth />,
notificationIcon: (
<FontAwesomeIcon icon={faStickyNote} fixedWidth size='xs' />
),
backgroundColor: yellow[800],
color: common.white,
path: '/notes',
Route: () => <AppRoute id='NOTES' path='/notes' component={NotesApp} />,
},
{
id: 'CAMERA',
nameLocale: 'APPS_CAMERA',
icon: <CameraAltIcon fontSize='large' />,
notificationIcon: <CameraAltIcon fontSize='small' />,
backgroundColor: grey['A400'],
color: common.white,
path: '/camera',
Route: () => (
<AppRoute id='CAMERA' path='/camera' component={CameraApp} />
),
},
{
id: 'EXAMPLE',
nameLocale: 'APPS_EXAMPLE',
icon: <FontAwesomeIcon icon={faPlaneArrival} size='sm' />,
notificationIcon: <FontAwesomeIcon icon={faPlaneArrival} size='xs' />,
backgroundColor: blue[500],
color: blue[50],
path: '/example',
Route: () => (
<AppRoute id='EXAMPLE' path='/example' component={ExampleApp} />
),
},
],
},
});
export const useApps = () => { export const useApps = () => {
const { icons } = useNotifications(); const { icons } = useNotifications();
const [apps, setApps] = useRecoilState<AppsRepository>(appsState); const apps = useMemo(
const allApps = useMemo(
() => () =>
[...apps.preinstalled].map((a) => ({ APPS.map((a) => ({
...a, ...a,
notification: icons.find((i) => i.key === a.id), notification: icons.find((i) => i.key === a.id),
})), })),
[apps.preinstalled, icons] [icons]
); );
const getApp = useCallback( const getApp = useCallback(
(id: string): IAppConfig => allApps.find((a) => a.id === id) || null, (id: string): IAppConfig => apps.find((a) => a.id === id) || null,
[allApps] [apps]
); );
return { apps, allApps, setApps, getApp }; return { apps, getApp };
}; };
export const useApp = (id: string): IAppConfig => { export const useApp = (id: string): IAppConfig => {
@@ -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 <ThemeProvider theme={mergedTheme}>{children}</ThemeProvider>;
};
return AppThemeProvider;
}
@@ -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);
}
+20 -6
View File
@@ -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 { atom, useSetRecoilState, useRecoilValue } from 'recoil';
import Nui from '../../nui-events/utils/Nui';
const keyboardState = { const keyboardState = {
ArrowRight: atom({ ArrowRight: atom({
@@ -45,6 +47,7 @@ const validKeys = [
const isKeyValid = (key) => validKeys.indexOf(key) !== -1; const isKeyValid = (key) => validKeys.indexOf(key) !== -1;
export const useInitKeyboard = () => { export const useInitKeyboard = () => {
const history = useHistory();
const getters = { const getters = {
ArrowRight: useRecoilValue(keyboardState.ArrowRight), ArrowRight: useRecoilValue(keyboardState.ArrowRight),
ArrowLeft: useRecoilValue(keyboardState.ArrowLeft), ArrowLeft: useRecoilValue(keyboardState.ArrowLeft),
@@ -56,6 +59,7 @@ export const useInitKeyboard = () => {
}; };
const setEscape = useSetRecoilState<any>(keyboardState.Escape); const setEscape = useSetRecoilState<any>(keyboardState.Escape);
const setBackspace = useSetRecoilState(keyboardState.Backspace);
useEffect( useEffect(
function handleNUIKeyboardMessage() { function handleNUIKeyboardMessage() {
@@ -68,7 +72,7 @@ export const useInitKeyboard = () => {
callback.handler && callback.handler &&
callback.handler.call callback.handler.call
) { ) {
return callback.handler(); return callback.handler(event);
} }
} }
@@ -78,11 +82,22 @@ export const useInitKeyboard = () => {
[getters] [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( useEffect(
function registerEscapeHandler() { function registerDefaultHandlers() {
setEscape({ handler: () => console.log('close phone') }); setEscape({ handler: escapeHandler });
setBackspace({ handler: backspaceHandler });
}, },
[setEscape] [setEscape, setBackspace, history, escapeHandler, backspaceHandler]
); );
}; };
@@ -92,7 +107,6 @@ export const useKeyboard = () => {
ArrowLeft: useSetRecoilState(keyboardState.ArrowLeft), ArrowLeft: useSetRecoilState(keyboardState.ArrowLeft),
ArrowUp: useSetRecoilState(keyboardState.ArrowUp), ArrowUp: useSetRecoilState(keyboardState.ArrowUp),
ArrowDown: useSetRecoilState(keyboardState.ArrowDown), ArrowDown: useSetRecoilState(keyboardState.ArrowDown),
Backspace: useSetRecoilState(keyboardState.Backspace),
Enter: useSetRecoilState(keyboardState.Enter), Enter: useSetRecoilState(keyboardState.Enter),
}; };
@@ -27,7 +27,7 @@ const useStyles = makeStyles((theme) => ({
height: '30px', height: '30px',
width: '100%', width: '100%',
color: theme.palette.text.primary, color: theme.palette.text.primary,
zIndex: 10, zIndex: 99,
paddingLeft: '15px', paddingLeft: '15px',
paddingRight: '10px', paddingRight: '10px',
position: 'relative', position: 'relative',
@@ -52,7 +52,7 @@ const useStyles = makeStyles((theme) => ({
width: '100%', width: '100%',
position: 'absolute', position: 'absolute',
top: '30px', top: '30px',
zIndex: 9, zIndex: 98,
}, },
closeNotifBtn: { closeNotifBtn: {
position: 'absolute', position: 'absolute',
@@ -1,7 +1,8 @@
import { useCallback, useEffect } from 'react'; import { useCallback, useEffect } from 'react';
import { matchPath, useHistory } from 'react-router-dom'; import { matchPath, useHistory } from 'react-router-dom';
import { atom, useRecoilState } from 'recoil'; 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 = { const state = {
recentlyUsed: atom({ recentlyUsed: atom({
@@ -23,24 +24,27 @@ const unshiftApp = (arr: IAppConfig[], app) => {
export const useQuickAccess = () => { export const useQuickAccess = () => {
const history = useHistory(); const history = useHistory();
const { allApps, getApp } = useApps(); const { apps, getApp } = useApps();
const [recentlyUsed, setRecentlyUsed] = useRecoilState<IAppConfig[]>( const [recentlyUsed, setRecentlyUsed] = useRecoilState<IAppConfig[]>(
state.recentlyUsed state.recentlyUsed
); );
useEffect(() => { useEffect(() => {
setRecentlyUsed([getApp("SETTINGS")]) setRecentlyUsed([getApp('SETTINGS')]);
}, [getApp, setRecentlyUsed]) }, [getApp, setRecentlyUsed]);
const listener = useCallback((location) => { const listener = useCallback(
const newState = [...recentlyUsed]; (location) => {
allApps.forEach((app) => { const newState = [...recentlyUsed];
if (matchPath(location.pathname, { path: app.path, exact: true })) { apps.forEach((app) => {
unshiftApp(newState, app); if (matchPath(location.pathname, { path: app.path, exact: true })) {
} unshiftApp(newState, app);
}); }
setRecentlyUsed(newState.slice(0, MAX_QUICK_ACCESS_ITEMS)); });
}, [allApps, recentlyUsed, setRecentlyUsed]); setRecentlyUsed(newState.slice(0, MAX_QUICK_ACCESS_ITEMS));
},
[apps, recentlyUsed, setRecentlyUsed]
);
history.listen(listener); history.listen(listener);
+12
View File
@@ -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,
]);
};
+28 -10
View File
@@ -8,9 +8,12 @@ import {
} from '@material-ui/core'; } from '@material-ui/core';
import { List } from './List'; import { List } from './List';
import { ListItem } from './ListItem'; import { ListItem } from './ListItem';
import { useTranslation } from 'react-i18next';
const useStyles = makeStyles((theme) => ({ const useStyles = makeStyles((theme) => ({
root: { root: {
borderTop: '1px solid',
borderColor: theme.palette.primary.main,
width: '100%', width: '100%',
position: 'absolute', position: 'absolute',
bottom: 0, 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 { interface IContextMenuProps {
open: boolean; open: boolean;
onClose(): void; onClose(): void;
options: Array<{ options: Array<IContextMenuOption>;
onClick(e, option): void;
label: string;
selected?: boolean;
icon?: React.ReactNode;
key?: string;
}>;
} }
export const ContextMenu = ({ open, onClose, options }: IContextMenuProps) => { export const ContextMenu = ({ open, onClose, options }: IContextMenuProps) => {
const classes = useStyles(); const classes = useStyles();
const { t } = useTranslation();
const _options = onClose
? [
...options,
{
label: t('GENERIC_CLOSE'),
onClick: onClose,
} as IContextMenuOption,
]
: options;
return ( return (
<Slide direction='up' in={open} mountOnEnter unmountOnExit> <Slide direction='up' in={open} mountOnEnter unmountOnExit>
<Paper square className={classes.root}> <Paper square className={classes.root}>
<List disablePadding> <List disablePadding>
{options.map((option) => ( {_options.map((option) => (
<ListItem <ListItem
selected={option.selected} selected={option.selected}
key={option.key || option.label} key={option.key || option.label}
@@ -46,8 +64,8 @@ export const ContextMenu = ({ open, onClose, options }: IContextMenuProps) => {
onClose(); onClose();
}} }}
> >
{option.icon && <ListItemIcon>{option.icon}</ListItemIcon>} {option.icon && <ListItemIcon >{option.icon}</ListItemIcon>}
<ListItemText primary={option.label} /> <ListItemText primary={option.label} secondary={option.description} />
</ListItem> </ListItem>
))} ))}
</List> </List>
+30
View File
@@ -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 (
<div className={classes.root}>
{alert ? (
<Alert severity={alert.type}>
{t('APPS_' + alert.message)}
</Alert>
) : null}
</div>
);
};
+1 -1
View File
@@ -4,7 +4,7 @@ import { SnackbarContext } from '../providers/SnackbarProvider';
export interface IAlert { export interface IAlert {
message: string; message: string;
type: 'success' | 'error' type: 'success' | 'error' | 'info'
} }
interface ISnackBar { interface ISnackBar {