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 './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 (
<ThemeProvider theme={currentTheme}>
@@ -108,25 +93,12 @@ function Phone() {
) : (
<>
<Route exact path='/' component={HomeApp} />
{allApps.map((App) => (
{apps.map((App) => (
<App.Route key={App.id} />
))}
</>
)}
{alert ? (
<div
style={{
marginTop: '-100px',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Alert severity={alert.type} variant='filled'>
{t('APPS_' + alert.message)}
</Alert>
</div>
) : null}
<Snackbar />
</div>
<Navigation />
</>
@@ -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 (
<Box display='flex' flexDirection='column'>
<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 />
</Fab>
{resultStr}
@@ -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();
};
@@ -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 { 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([
{
@@ -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,
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';
@@ -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 = () => {
/>
<TextField
className={classes.input}
placeholder={t('APPS_CONTACT_FORM_AVATAR')}
label={t('APPS_CONTACT_FORM_AVATAR')}
fullWidth
value={avatar}
onChange={(e) => setAvatar(e.target.value)}
@@ -165,28 +144,38 @@ const ContactsInfoPage = () => {
/>
{/* Display if fetched contact */}
{contact && (
<div style={{ display: 'block' }}>
<Button
onClick={handleContactSave}
className={classes.updateButton}
>
{t('GENERIC_UPDATE')}
</Button>
<Button
onClick={handleContactDelete}
className={classes.deleteButton}
>
{t('GENERIC_DELETE')}
</Button>
</div>
<>
<Box py={1} display='block'>
<Button
color='primary'
variant='contained'
onClick={handleContactSave}
>
{t('GENERIC_UPDATE')}
</Button>
</Box>
<Box py={1} display='block'>
<Button
variant='contained'
color='secondary'
onClick={handleContactDelete}
>
{t('GENERIC_DELETE')}
</Button>
</Box>
</>
)}
{/* Display if no fetched contact */}
{!contact && (
<div style={{ display: 'block' }}>
<Button onClick={handleContactAdd} className={classes.saveButton}>
<Box display='block'>
<Button
color='primary'
variant='contained'
onClick={handleContactAdd}
>
{t('APPS_CONTACT_MODAL_BUTTON_ADD')}
</Button>
</div>
</Box>
)}
</div>
</Paper>
@@ -26,8 +26,8 @@ export const ContactPage = () => {
<>
<ContactList />
<Fab
color='primary'
onClick={() => history.push('/contacts/-1')}
style={{ backgroundColor: '#2196f3', color: '#fff' }}
className={classes.absolute}
>
<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 { 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 };
};
@@ -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 { 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();
};
@@ -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 (
<AppWrapper>
<AppContent>
<h1>This is an example</h1>
<h2>{example.id}</h2>
{/* Here we are using the value in a h3 tag */}
<h3>{exampleString}</h3>
</AppContent>
</AppWrapper>
<ExampleThemeProvider>
<AppWrapper>
<AppTitle app={example} />
<AppContent>
<h1>This is an example</h1>
<Button color='primary'>{example.id}</Button>
{/* Here we are using the value in a h3 tag */}
<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';
export const HomeApp = () => {
const { allApps } = useApps();
const { apps } = useApps();
return (
<AppWrapper>
<Box width='100%' mt={6} px={1}>
{allApps && <GridMenu items={allApps} />}
{apps && <GridMenu items={apps} />}
</Box>
</AppWrapper>
);
@@ -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 (
<AppWrapper id='messages-app'>
<AppTitle app={messages} />
<AppContent>
<Switch>
<Route
path='/messages/conversations/:groupId'
component={MessageModal}
/>
<Route
exact
path='/messages'
render={() => (
<>
<MessagesList />
</>
)}
/>
</Switch>
<Switch>
<Route
exact
path={['/messages/new/:phoneNumber', '/messages/new']}
render={() => <MessageGroupModal />}
/>
</Switch>
</AppContent>
<NewMessageGroupButton
onClick={() => history.push('/messages/new')}
/>
<AlertBar />
</AppWrapper>
<MessagesThemeProvider>
<AppWrapper id='messages-app'>
<AppTitle app={messages} />
<AppContent>
<Switch>
<Route
path='/messages/conversations/:groupId'
component={MessageModal}
/>
<Route
exact
path='/messages'
render={() => (
<>
<MessagesList />
</>
)}
/>
</Switch>
<Switch>
<Route
exact
path={['/messages/new/:phoneNumber', '/messages/new']}
render={() => <MessageGroupModal />}
/>
</Switch>
</AppContent>
<NewMessageGroupButton onClick={() => history.push('/messages/new')} />
<AlertBar />
</AppWrapper>
</MessagesThemeProvider>
);
};
@@ -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',
@@ -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';
@@ -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: {
@@ -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 }) => {
)}
<Box px={2} py={3}>
<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>
</Box>
</form>
@@ -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',
},
},
},
@@ -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 { 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 (
<>
<MessageImageModal
@@ -41,27 +38,11 @@ const Conversation = ({ activeMessageGroup, messages }: IProps) => {
className={classes.overflowAutoY}
>
{messages.map((message) => (
<div key={message.id}>
<Paper
className={message.isMine ? classes.sourceSms : classes.sms}
variant='outlined'
>
{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>
<MessageBubble
key={message.id}
message={message}
isGroupChat={activeMessageGroup?.isGroupChat}
/>
))}
</Box>
<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 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: <CloseIcon />,
onClick: onClose,
},
],
[onClose, history, pathname, search]
[history, pathname, search]
);
return (
@@ -110,6 +105,7 @@ export const MessageImageModal = ({
<Button
fullWidth
variant='contained'
color='primary'
onClick={() => sendFromQueryParam(queryParamImagePreview)}
>
Share
@@ -117,19 +113,19 @@ export const MessageImageModal = ({
</Box>
</Modal>
<Modal visible={pasteVisible} handleClose={() => setPasteVisible(false)}>
<div>
<Box p={1}>
<TextField
placeholder='A link to your image or gif'
onChange={(e) => setMessage(e.target.value)}
value={message}
className={classes.input}
fullWidth
inputProps={{
className: classes.messagesInput,
}}
inputRef={(input) => input && input.focus()}
onKeyPress={sendFromClipboard}
/>
</div>
</Box>
</Modal>
</>
);
@@ -1,5 +1,5 @@
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 useStyles from './modal.styles';
@@ -6,6 +6,10 @@ const useStyles = makeStyles({
root: {
margin: '0px 0px 12px 8px',
},
skeleton: {
borderRadius: '20px',
transform: 'none',
},
});
export default function MessageSkeleton({ height, isMine = false }) {
@@ -14,7 +18,12 @@ export default function MessageSkeleton({ height, isMine = false }) {
const marginLeft = isMine ? '60px' : '8px';
return (
<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>
);
}
@@ -1,8 +1,8 @@
import { makeStyles } from '@material-ui/core';
const useStyles = makeStyles((theme) => ({
const useStyles = makeStyles({
modalRoot: {
zIndex: 10,
zIndex: 9,
position: 'absolute',
height: '100%',
width: '100%',
@@ -31,40 +31,9 @@ const useStyles = makeStyles((theme) => ({
paddingTop: '8px',
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: {
fontSize: 20,
},
input: {
width: '100%',
margin: 10,
},
imageMessage: {
width: '80%',
maxWidth: '80%',
height: '80%',
maxHeight: '80%',
},
}));
});
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 { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
import { useNotes } from './useNotes';
import { noteStates } from './state';
import { useSnackbar } from '../../../ui/hooks/useSnackbar';
@@ -10,5 +9,4 @@ export const useNotesService = () => {
useNuiEvent('NOTES', 'setNotes', setNotes);
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 { NavigationBar } from './navigation/NavigationBar';
import { Switch, Route } from 'react-router-dom';
import './Sellout.css';
import { ListingFormContainer } from './form/ListingFormContainer';
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([
{
@@ -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',
alignItems: 'flex',
height: 'auto',
background: '#232323',
background: theme.palette.background.default,
marginBottom: 20,
},
icon: {
color: theme.palette.primary.main
},
header: {
margin: 10,
},
@@ -79,10 +82,10 @@ export const SelloutItem = (listing) => {
</Typography>
<div>
<Button>
<ChatIcon style={{ color: '#f44336' }} />
<ChatIcon className={classes.icon} />
</Button>
<Button>
<PhoneIcon style={{ color: '#f44336' }} />
<PhoneIcon className={classes.icon} />
</Button>
</div>
</Paper>
@@ -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,
},
}));
@@ -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,
},
@@ -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,
},
}));
@@ -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_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"
}
}
-4
View File
@@ -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 };
};
+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 {
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 (
<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} />
),
},
],
},
});
import { APPS, IAppConfig } from '../config/apps';
export const useApps = () => {
const { icons } = useNotifications();
const [apps, setApps] = useRecoilState<AppsRepository>(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 => {
@@ -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 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<any>(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),
};
@@ -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',
@@ -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<IAppConfig[]>(
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);
+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';
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<IContextMenuOption>;
}
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 (
<Slide direction='up' in={open} mountOnEnter unmountOnExit>
<Paper square className={classes.root}>
<List disablePadding>
{options.map((option) => (
{_options.map((option) => (
<ListItem
selected={option.selected}
key={option.key || option.label}
@@ -46,8 +64,8 @@ export const ContextMenu = ({ open, onClose, options }: IContextMenuProps) => {
onClose();
}}
>
{option.icon && <ListItemIcon>{option.icon}</ListItemIcon>}
<ListItemText primary={option.label} />
{option.icon && <ListItemIcon >{option.icon}</ListItemIcon>}
<ListItemText primary={option.label} secondary={option.description} />
</ListItem>
))}
</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 {
message: string;
type: 'success' | 'error'
type: 'success' | 'error' | 'info'
}
interface ISnackBar {