From 9f04ac3243e3799a89a4511329098892fcf0a7ee Mon Sep 17 00:00:00 2001 From: J Francisco Rader Date: Sun, 21 Feb 2021 12:49:09 -0500 Subject: [PATCH 01/17] Add theme provider for notes --- phone/src/apps/notes/NotesApp.css | 7 - phone/src/apps/notes/NotesApp.tsx | 72 +++---- phone/src/apps/notes/NotesTitle.tsx | 24 ++- phone/src/apps/notes/hooks/useNoteModal.ts | 12 -- phone/src/apps/notes/list/NoteList.tsx | 13 +- phone/src/apps/notes/modal/NoteModal.tsx | 196 ++++++++++-------- phone/src/apps/notes/modal/modal.styles.ts | 20 +- phone/src/apps/notes/notes.styles.ts | 9 - phone/src/apps/notes/notes.theme.ts | 17 ++ .../notes/providers/NotesThemeProvider.tsx | 4 + phone/src/apps/sellout/sellout.theme.ts | 13 +- phone/src/locale/en.json | 4 +- phone/src/os/apps/config/apps.tsx | 12 +- 13 files changed, 205 insertions(+), 198 deletions(-) delete mode 100644 phone/src/apps/notes/NotesApp.css delete mode 100644 phone/src/apps/notes/hooks/useNoteModal.ts create mode 100644 phone/src/apps/notes/notes.theme.ts create mode 100644 phone/src/apps/notes/providers/NotesThemeProvider.tsx diff --git a/phone/src/apps/notes/NotesApp.css b/phone/src/apps/notes/NotesApp.css deleted file mode 100644 index 6728c0e..0000000 --- a/phone/src/apps/notes/NotesApp.css +++ /dev/null @@ -1,7 +0,0 @@ -#notes-app .Mui-focused::after { - border-bottom: 3px solid #f9a825; -} - -#notes-app .MuiOutlinedInput-root { - border: 2px soild #f9a825; -} diff --git a/phone/src/apps/notes/NotesApp.tsx b/phone/src/apps/notes/NotesApp.tsx index face916..9b9d223 100644 --- a/phone/src/apps/notes/NotesApp.tsx +++ b/phone/src/apps/notes/NotesApp.tsx @@ -4,17 +4,45 @@ import { AppContent } from '../../ui/components/AppContent'; import { AppTitle } from '../../ui/components/AppTitle'; import { useApp } from '../../os/apps/hooks/useApps'; import NoteList from './list/NoteList'; - -import { useNotes } from './hooks/useNotes'; import { NoteModal } from './modal/NoteModal'; import { Fab } from '@material-ui/core'; import AddIcon from '@material-ui/icons/Add'; - -import { useNoteModal } from './hooks/useNoteModal'; import { useNoteDetail } from './hooks/useNoteDetail'; - import useStyles from './notes.styles'; import InjectDebugData from '../../os/debug/InjectDebugData'; +import { NotesThemeProvider } from './providers/NotesThemeProvider'; +import { Route, useHistory } from 'react-router-dom'; + +export const NotesApp = () => { + const classes = useStyles(); + const history = useHistory(); + const notesApp = useApp('NOTES'); + const { setDetail } = useNoteDetail(); + + const onClickCreate = () => { + setDetail({ title: '', content: '' }); + history.push('/notes/detail'); + }; + + return ( + + + + + + + + + + + + + ); +}; InjectDebugData([ { @@ -34,37 +62,3 @@ InjectDebugData([ ], }, ]); - -export const NotesApp = () => { - const { setNoteModal } = useNoteModal(); - const { detail, setDetail } = useNoteDetail(); - const { notes } = useNotes(); - const notesApp = useApp('NOTES'); - - const classes = useStyles(); - - const handleModal = () => { - setNoteModal(true); - setDetail(null); - }; - - return ( - - - - - - - - - - - ); -}; diff --git a/phone/src/apps/notes/NotesTitle.tsx b/phone/src/apps/notes/NotesTitle.tsx index 9d4404a..d3c2171 100644 --- a/phone/src/apps/notes/NotesTitle.tsx +++ b/phone/src/apps/notes/NotesTitle.tsx @@ -1,18 +1,30 @@ import React from 'react'; -import { yellow } from '@material-ui/core/colors'; - -import useStyles from './notes.styles'; - -import { Paper } from '@material-ui/core'; +import { makeStyles, Paper } from '@material-ui/core'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faStickyNote } from '@fortawesome/free-solid-svg-icons'; +const useStyles = makeStyles((theme) => ({ + header: { + width: '100%', + display: 'flex', + flexFlow: 'row nowrap', + justifyContent: 'center', + alignItems: 'center', + textAlign: 'center', + height: '60px', + }, + icon: { + color: theme.palette.primary.main, + fontSize: 40, + }, +})); + const NotesTitle = () => { const classes = useStyles(); return ( - + ); }; diff --git a/phone/src/apps/notes/hooks/useNoteModal.ts b/phone/src/apps/notes/hooks/useNoteModal.ts deleted file mode 100644 index f946540..0000000 --- a/phone/src/apps/notes/hooks/useNoteModal.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { useRecoilState } from 'recoil'; -import { noteStates } from './state'; - -interface NoteModalProps { - noteModal: boolean; - setNoteModal: (show: boolean) => void; -} - -export const useNoteModal = (): NoteModalProps => { - const [noteModal, setNoteModal] = useRecoilState(noteStates.noteModal); - return { noteModal, setNoteModal }; -}; diff --git a/phone/src/apps/notes/list/NoteList.tsx b/phone/src/apps/notes/list/NoteList.tsx index 0e569c0..9b5634f 100644 --- a/phone/src/apps/notes/list/NoteList.tsx +++ b/phone/src/apps/notes/list/NoteList.tsx @@ -1,18 +1,19 @@ -import { List, ListItem, ListItemText } from '@material-ui/core'; import React from 'react'; - -import { useNoteModal } from '../hooks/useNoteModal'; +import { List, ListItem, ListItemText } from '@material-ui/core'; import { useNoteDetail } from '../hooks/useNoteDetail'; +import { useNotes } from '../hooks/useNotes'; +import { useHistory } from 'react-router-dom'; // add search bar later // TODO: Add interface for note -const NoteList = ({ notes }) => { - const { setNoteModal } = useNoteModal(); +const NoteList = () => { + const history = useHistory(); + const { notes } = useNotes(); const { setDetail } = useNoteDetail(); const handleNoteModal = (note) => { - setNoteModal(true); setDetail(note); + history.push('/notes/detail'); }; return ( diff --git a/phone/src/apps/notes/modal/NoteModal.tsx b/phone/src/apps/notes/modal/NoteModal.tsx index 08d099e..1efad42 100644 --- a/phone/src/apps/notes/modal/NoteModal.tsx +++ b/phone/src/apps/notes/modal/NoteModal.tsx @@ -1,41 +1,38 @@ -import { Button, TextField, Slide } from '@material-ui/core'; -import React, { useState } from 'react'; +import { + Button, + TextField, + Slide, + Paper, + Typography, + Container, + CircularProgress, + Box, +} from '@material-ui/core'; +import React from 'react'; import ArrowBackIcon from '@material-ui/icons/ArrowBack'; - -import { useNoteModal } from '../hooks/useNoteModal'; import { useNoteDetail } from '../hooks/useNoteDetail'; - import useStyles from './modal.styles'; - -import '../NotesApp.css'; import Nui from '../../../os/nui-events/utils/Nui'; +import { useTranslation } from 'react-i18next'; +import { useHistory } from 'react-router-dom'; -// TODO: Fix input focus color export const NoteModal = () => { - const { noteModal, setNoteModal } = useNoteModal(); + const classes = useStyles(); + const history = useHistory(); + const { t } = useTranslation(); const { detail, setDetail } = useNoteDetail(); - const [title, setTitle] = useState(detail ? detail.title : ''); - const [content, setContent] = useState(detail ? detail.content : ''); - const classes = useStyles() - - + const onClose = () => history.goBack(); const _handleClose = () => { setDetail(null); - setNoteModal(false); + onClose(); }; const handleNoteSave = () => { - Nui.send('phone:addNote', { - title, - content, - }); + Nui.send('phone:addNote', detail); setDetail(null); - setNoteModal(false); - - setTitle('') - setContent('') + onClose(); }; const handleDeleteNote = () => { @@ -44,78 +41,99 @@ export const NoteModal = () => { id, }); setDetail(null); - setNoteModal(false); + onClose(); }; const handleUpdateNote = () => { - Nui.send('phone:updateNote', { - id: detail.id, - title, - content, - }); + Nui.send('phone:updateNote', detail); setDetail(null); - setNoteModal(false); + onClose(); }; return ( -
- -
- -
- setTitle(e.target.value)} - /> - setContent(e.target.value)} - /> -

{content.length}/250

- {!detail &&( - - )} - {detail && ( - - )} - {detail && ( - - )} -
-
-
-
+ + + {!detail ? ( + + ) : ( + + + + + + + setDetail((d) => ({ ...d, title: e.target.value })) + } + /> + + setDetail((d) => ({ ...d, content: e.target.value })) + } + /> + {detail.content.length}/250 + {!detail.id && ( + + )} + {!!detail.id && ( + <> + + + + )} + + + )} + + ); }; diff --git a/phone/src/apps/notes/modal/modal.styles.ts b/phone/src/apps/notes/modal/modal.styles.ts index 44d1f40..e233e3f 100644 --- a/phone/src/apps/notes/modal/modal.styles.ts +++ b/phone/src/apps/notes/modal/modal.styles.ts @@ -6,21 +6,7 @@ const useStyles = makeStyles((theme) => ({ position: 'absolute', height: '100%', width: '100%', - background: '#232323', - }, - modalHide: { - display: 'none', - }, - closeButton: { - width: '10%', - position: 'absolute', - top: 10, - left: 0, - }, - noteContainer: { - width: '90%', - marginTop: 80, - margin: '0 auto', + background: theme.palette.background.default, }, input: { marginBottom: 20, @@ -30,18 +16,16 @@ const useStyles = makeStyles((theme) => ({ }, inputPropsContent: { fontSize: 20, + lineHeight: 1.2 }, saveButton: { - background: '#f9a825', padding: '10px 30px', }, updateButton: { - background: '#f9a825', padding: '10px 30px', marginRight: '8px', }, deleteButton: { - background: '#c62828', padding: '10px 30px', }, })); diff --git a/phone/src/apps/notes/notes.styles.ts b/phone/src/apps/notes/notes.styles.ts index c1b1cc5..71b03e3 100644 --- a/phone/src/apps/notes/notes.styles.ts +++ b/phone/src/apps/notes/notes.styles.ts @@ -1,15 +1,6 @@ import { makeStyles } from '@material-ui/core'; const useStyles = makeStyles((theme) => ({ - header: { - width: '100%', - display: 'flex', - flexFlow: 'row nowrap', - justifyContent: 'center', - alignItems: 'center', - textAlign: 'center', - height: '60px', - }, backgroundModal: { background: 'black', opacity: '0.6', diff --git a/phone/src/apps/notes/notes.theme.ts b/phone/src/apps/notes/notes.theme.ts new file mode 100644 index 0000000..30f63b2 --- /dev/null +++ b/phone/src/apps/notes/notes.theme.ts @@ -0,0 +1,17 @@ +import { common, yellow } from "@material-ui/core/colors"; + +export const NOTES_APP_PRIMARY_COLOR = yellow[800]; +export const NOTES_APP_TEXT_COLOR = common.black; + +const theme = { + palette: { + primary: { + main: NOTES_APP_PRIMARY_COLOR, + dark: yellow[900], + light: yellow[500], + contrastText: NOTES_APP_TEXT_COLOR + } + } +} + +export default theme; diff --git a/phone/src/apps/notes/providers/NotesThemeProvider.tsx b/phone/src/apps/notes/providers/NotesThemeProvider.tsx new file mode 100644 index 0000000..d336e03 --- /dev/null +++ b/phone/src/apps/notes/providers/NotesThemeProvider.tsx @@ -0,0 +1,4 @@ +import { createAppThemeProvider } from "../../../os/apps/utils/createAppThemeProvider"; +import notesTheme from '../notes.theme'; + +export const NotesThemeProvider = createAppThemeProvider(notesTheme); diff --git a/phone/src/apps/sellout/sellout.theme.ts b/phone/src/apps/sellout/sellout.theme.ts index b1b511a..438790a 100644 --- a/phone/src/apps/sellout/sellout.theme.ts +++ b/phone/src/apps/sellout/sellout.theme.ts @@ -1,12 +1,15 @@ -import { common } from "@material-ui/core/colors"; +import { common, red } from "@material-ui/core/colors"; + +export const SELLOUT_APP_PRIMARY_COLOR = red[500]; +export const SELLOUT_APP_TEXT_COLOR = common.black; const theme = { palette: { primary: { - main: '#f44336', - dark: '#b3251b', - light: 'f87f76', - contrastText: common.black + main: SELLOUT_APP_PRIMARY_COLOR, + dark: red[700], + light: red[200], + contrastText: SELLOUT_APP_TEXT_COLOR } } } diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index 049b0f6..94c6c3d 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -106,6 +106,8 @@ "GENERIC_SAVE": "Save", "GENERIC_UPDATE": "Update", "GENERIC_DELETE": "Delete", - "GENERIC_CLOSE": "Close" + "GENERIC_CLOSE": "Close", + "GENERIC_TITLE": "Title", + "GENERIC_CONTENT": "Content" } } diff --git a/phone/src/os/apps/config/apps.tsx b/phone/src/os/apps/config/apps.tsx index 98320de..b79a5e4 100644 --- a/phone/src/os/apps/config/apps.tsx +++ b/phone/src/os/apps/config/apps.tsx @@ -5,8 +5,6 @@ import { grey, green, purple, - yellow, - red, } from '@material-ui/core/colors'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { @@ -43,6 +41,8 @@ import { CONTACTS_APP_PRIMARY_COLOR, CONTACTS_APP_TEXT_COLOR, } from '../../../apps/contacts/contacts.theme'; +import { SELLOUT_APP_PRIMARY_COLOR, SELLOUT_APP_TEXT_COLOR } from '../../../apps/sellout/sellout.theme'; +import { NOTES_APP_PRIMARY_COLOR, NOTES_APP_TEXT_COLOR } from '../../../apps/notes/notes.theme'; export interface IAppConfig { id: string; @@ -141,8 +141,8 @@ export const APPS: IAppConfig[] = [ nameLocale: 'APPS_SELLOUT', icon: , notificationIcon: , - backgroundColor: red[500], - color: common.white, + backgroundColor: SELLOUT_APP_PRIMARY_COLOR, + color: SELLOUT_APP_TEXT_COLOR, path: '/sellout', Route: () => ( @@ -155,8 +155,8 @@ export const APPS: IAppConfig[] = [ notificationIcon: ( ), - backgroundColor: yellow[800], - color: common.white, + backgroundColor: NOTES_APP_PRIMARY_COLOR, + color: NOTES_APP_TEXT_COLOR, path: '/notes', Route: () => , }, From bf7d94b33dc1adb5ea51e73317153220276d4fe5 Mon Sep 17 00:00:00 2001 From: J Francisco Rader Date: Sun, 21 Feb 2021 13:03:19 -0500 Subject: [PATCH 02/17] Fix alerts overflow and improve message-bubble style --- .../components/modal/MessageBubble.tsx | 12 ++++++--- phone/src/ui/components/Alert.tsx | 26 +++++++++++++++++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/phone/src/apps/messages/components/modal/MessageBubble.tsx b/phone/src/apps/messages/components/modal/MessageBubble.tsx index de52d8a..a4ebebd 100644 --- a/phone/src/apps/messages/components/modal/MessageBubble.tsx +++ b/phone/src/apps/messages/components/modal/MessageBubble.tsx @@ -12,9 +12,11 @@ const useStyles = makeStyles((theme) => ({ mySms: { float: 'right', margin: theme.spacing(1), - padding: '6px 12px', + padding: '6px 16px', height: 'auto', - width: '80%', + width: 'auto', + minWidth: '60%', + maxWidth: '85%', background: theme.palette.background.default, color: theme.palette.text.primary, borderRadius: '20px', @@ -24,7 +26,9 @@ const useStyles = makeStyles((theme) => ({ float: 'left', margin: theme.spacing(1), padding: '6px 12px', - width: '80%', + width: 'auto', + minWidth: '60%', + maxWidth: '85%', height: 'auto', background: theme.palette.primary.light, color: theme.palette.getContrastText(theme.palette.primary.light), @@ -62,7 +66,7 @@ export const MessageBubble = ({
{message.message}
)} - + {isGroupChat && !message.isMine ? message.display || message.phone_number diff --git a/phone/src/ui/components/Alert.tsx b/phone/src/ui/components/Alert.tsx index 697fb4c..edfd7f7 100644 --- a/phone/src/ui/components/Alert.tsx +++ b/phone/src/ui/components/Alert.tsx @@ -1,8 +1,30 @@ import React from 'react'; import MuiAlert from '@material-ui/lab/Alert'; +import { makeStyles, Typography } from '@material-ui/core'; -export function Alert(props) { - return ; +const useStyles = makeStyles({ + root: { + zIndex: 10000, + }, + msg: { + maxWidth: '300px', + wordWrap: 'break-word', + fontSize: '1em' + }, +}); + +export function Alert({ children, ...props }) { + const classes = useStyles(); + return ( + + {children} + + ); } export default Alert; From 2c6358e4c33f02f345495b361f819194fd023f3b Mon Sep 17 00:00:00 2001 From: J Francisco Rader Date: Sun, 21 Feb 2021 18:13:08 -0500 Subject: [PATCH 03/17] Add status button | Revert white icons --- phone/src/apps/notes/modal/NoteModal.tsx | 70 +++++++++++++--------- phone/src/apps/notes/modal/modal.styles.ts | 14 +---- phone/src/apps/notes/notes.theme.ts | 1 + phone/src/apps/sellout/sellout.theme.ts | 1 + phone/src/locale/en.json | 1 + phone/src/os/apps/config/apps.tsx | 9 +-- phone/src/ui/components/StatusButton.tsx | 57 ++++++++++++++++++ 7 files changed, 109 insertions(+), 44 deletions(-) create mode 100644 phone/src/ui/components/StatusButton.tsx diff --git a/phone/src/apps/notes/modal/NoteModal.tsx b/phone/src/apps/notes/modal/NoteModal.tsx index 1efad42..2b3b110 100644 --- a/phone/src/apps/notes/modal/NoteModal.tsx +++ b/phone/src/apps/notes/modal/NoteModal.tsx @@ -15,6 +15,7 @@ import useStyles from './modal.styles'; import Nui from '../../../os/nui-events/utils/Nui'; import { useTranslation } from 'react-i18next'; import { useHistory } from 'react-router-dom'; +import { StatusButton } from '../../../ui/components/StatusButton'; export const NoteModal = () => { const classes = useStyles(); @@ -99,35 +100,48 @@ export const NoteModal = () => { } /> {detail.content.length}/250 - {!detail.id && ( - - )} - {!!detail.id && ( + {!detail.id ? ( <> - - + + + + + + {t('GENERIC_CANCEL')} + + + + ) : ( + <> + + + + + + {t('GENERIC_DELETE')} + + )} diff --git a/phone/src/apps/notes/modal/modal.styles.ts b/phone/src/apps/notes/modal/modal.styles.ts index e233e3f..f706446 100644 --- a/phone/src/apps/notes/modal/modal.styles.ts +++ b/phone/src/apps/notes/modal/modal.styles.ts @@ -4,7 +4,7 @@ const useStyles = makeStyles((theme) => ({ modalRoot: { zIndex: 20, position: 'absolute', - height: '100%', + height: '99%', width: '100%', background: theme.palette.background.default, }, @@ -16,17 +16,7 @@ const useStyles = makeStyles((theme) => ({ }, inputPropsContent: { fontSize: 20, - lineHeight: 1.2 - }, - saveButton: { - padding: '10px 30px', - }, - updateButton: { - padding: '10px 30px', - marginRight: '8px', - }, - deleteButton: { - padding: '10px 30px', + lineHeight: 1.2, }, })); diff --git a/phone/src/apps/notes/notes.theme.ts b/phone/src/apps/notes/notes.theme.ts index 30f63b2..dddda36 100644 --- a/phone/src/apps/notes/notes.theme.ts +++ b/phone/src/apps/notes/notes.theme.ts @@ -1,6 +1,7 @@ import { common, yellow } from "@material-ui/core/colors"; export const NOTES_APP_PRIMARY_COLOR = yellow[800]; +export const NOTES_APP_ICON_COLOR = common.white; export const NOTES_APP_TEXT_COLOR = common.black; const theme = { diff --git a/phone/src/apps/sellout/sellout.theme.ts b/phone/src/apps/sellout/sellout.theme.ts index 438790a..92e3f23 100644 --- a/phone/src/apps/sellout/sellout.theme.ts +++ b/phone/src/apps/sellout/sellout.theme.ts @@ -1,6 +1,7 @@ import { common, red } from "@material-ui/core/colors"; export const SELLOUT_APP_PRIMARY_COLOR = red[500]; +export const SELLOUT_APP_ICON_COLOR = common.white; export const SELLOUT_APP_TEXT_COLOR = common.black; const theme = { diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index 94c6c3d..a36c0c1 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -107,6 +107,7 @@ "GENERIC_UPDATE": "Update", "GENERIC_DELETE": "Delete", "GENERIC_CLOSE": "Close", + "GENERIC_CANCEL": "Cancel", "GENERIC_TITLE": "Title", "GENERIC_CONTENT": "Content" } diff --git a/phone/src/os/apps/config/apps.tsx b/phone/src/os/apps/config/apps.tsx index b79a5e4..a1e125c 100644 --- a/phone/src/os/apps/config/apps.tsx +++ b/phone/src/os/apps/config/apps.tsx @@ -33,6 +33,7 @@ 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, @@ -41,8 +42,8 @@ import { CONTACTS_APP_PRIMARY_COLOR, CONTACTS_APP_TEXT_COLOR, } from '../../../apps/contacts/contacts.theme'; -import { SELLOUT_APP_PRIMARY_COLOR, SELLOUT_APP_TEXT_COLOR } from '../../../apps/sellout/sellout.theme'; -import { NOTES_APP_PRIMARY_COLOR, NOTES_APP_TEXT_COLOR } from '../../../apps/notes/notes.theme'; +import { SELLOUT_APP_PRIMARY_COLOR, SELLOUT_APP_ICON_COLOR } from '../../../apps/sellout/sellout.theme'; +import { NOTES_APP_ICON_COLOR, NOTES_APP_PRIMARY_COLOR } from '../../../apps/notes/notes.theme'; export interface IAppConfig { id: string; @@ -142,7 +143,7 @@ export const APPS: IAppConfig[] = [ icon: , notificationIcon: , backgroundColor: SELLOUT_APP_PRIMARY_COLOR, - color: SELLOUT_APP_TEXT_COLOR, + color: SELLOUT_APP_ICON_COLOR, path: '/sellout', Route: () => ( @@ -156,7 +157,7 @@ export const APPS: IAppConfig[] = [ ), backgroundColor: NOTES_APP_PRIMARY_COLOR, - color: NOTES_APP_TEXT_COLOR, + color: NOTES_APP_ICON_COLOR, path: '/notes', Route: () => , }, diff --git a/phone/src/ui/components/StatusButton.tsx b/phone/src/ui/components/StatusButton.tsx new file mode 100644 index 0000000..c219659 --- /dev/null +++ b/phone/src/ui/components/StatusButton.tsx @@ -0,0 +1,57 @@ +import { Button, ButtonProps, fade, makeStyles } from '@material-ui/core'; +import React from 'react'; + +type StatusButtonStyleColor = 'success' | 'error' | 'warning' | 'info'; + +interface IStatusButtonStyleProps { + color: StatusButtonStyleColor; +} + +const useStyles = makeStyles( + (theme) => ({ + root: { + color: ({ color }: IStatusButtonStyleProps) => theme.palette[color].main, + '&:hover': { + backgroundColor: ({ color }: IStatusButtonStyleProps) => + fade(theme.palette[color].light, theme.palette.action.hoverOpacity), + }, + }, + outlined: { + border: ({ color }: IStatusButtonStyleProps) => + `1px solid ${fade(theme.palette[color].main, 0.5)}`, + '&:hover': { + border: ({ color }: IStatusButtonStyleProps) => + `1px solid ${theme.palette[color].main}`, + }, + '&$disabled': { + border: `1px solid ${theme.palette.action.disabled}`, + }, + }, + contained: { + color: ({ color }: IStatusButtonStyleProps) => + theme.palette[color].contrastText, + backgroundColor: ({ color }: IStatusButtonStyleProps) => + theme.palette[color].main, + '&:hover': { + backgroundColor: ({ color }: IStatusButtonStyleProps) => + theme.palette[color].dark, + }, + }, + }), + { name: 'MuiButton' } +); + +export const StatusButton = ({ + color = 'info', + variant, + className, + ...props +}: Omit & { color: StatusButtonStyleColor }) => { + const classes = useStyles({ color }); + return ( + + + + ); }; diff --git a/phone/src/ui/components/GridMenu.tsx b/phone/src/ui/components/GridMenu.tsx index bb023c9..f18c5c9 100644 --- a/phone/src/ui/components/GridMenu.tsx +++ b/phone/src/ui/components/GridMenu.tsx @@ -1,53 +1,32 @@ import React from 'react'; import { AppIcon } from './AppIcon'; -import { useTranslation } from 'react-i18next'; -import { Grid, makeStyles, Tooltip, Zoom } from '@material-ui/core'; +import { Box, Grid } from '@material-ui/core'; import { Link } from 'react-router-dom'; -const useStyles = makeStyles((theme) => ({ - root: { - marginTop: theme.spacing(3), - }, - item: { - marginTop: theme.spacing(3), - width: '20%', - }, - tooltip: { - fontSize: 12, - }, -})); - -export const GridMenu = ({ items, Component = AppIcon }) => { - const classes = useStyles(); - const { t } = useTranslation(); - - // TODO: Fix tooltip position to be closer to app icon +export const GridMenu = ({ + items, + Component = AppIcon, + xs = undefined, +}) => { return ( - - - {items && - items.length && - items.map((item) => ( - - + + {items && + items.length && + items.map((item) => ( + + + - - - ))} - + + + + ))} ); }; diff --git a/phone/src/ui/components/StatusIconButton.tsx b/phone/src/ui/components/StatusIconButton.tsx new file mode 100644 index 0000000..1f2fb98 --- /dev/null +++ b/phone/src/ui/components/StatusIconButton.tsx @@ -0,0 +1,60 @@ +import { + fade, + IconButton, + IconButtonProps, + makeStyles, +} from '@material-ui/core'; +import React from 'react'; + +type StatusButtonStyleColor = 'success' | 'error' | 'warning' | 'info'; + +interface IStatusButtonStyleProps { + color: StatusButtonStyleColor; +} + +const useStyles = makeStyles( + (theme) => ({ + root: { + color: ({ color }: IStatusButtonStyleProps) => + theme.palette[color].contrastText, + backgroundColor: ({ color }: IStatusButtonStyleProps) => + theme.palette[color].main, + '&:hover': { + backgroundColor: ({ color }: IStatusButtonStyleProps) => + theme.palette[color].light, + }, + }, + outlined: { + border: ({ color }: IStatusButtonStyleProps) => + `1px solid ${fade(theme.palette[color].main, 0.5)}`, + '&:hover': { + border: ({ color }: IStatusButtonStyleProps) => + `1px solid ${theme.palette[color].main}`, + }, + '&$disabled': { + border: `1px solid ${theme.palette.action.disabled}`, + }, + }, + contained: { + color: ({ color }: IStatusButtonStyleProps) => + theme.palette[color].contrastText, + backgroundColor: ({ color }: IStatusButtonStyleProps) => + theme.palette[color].main, + '&:hover': { + backgroundColor: ({ color }: IStatusButtonStyleProps) => + theme.palette[color].dark, + }, + }, + }), + { name: 'MuiIconButton' } +); + +export const StatusIconButton = ({ + color = 'info', + size, + className, + ...props +}: Omit & { color: StatusButtonStyleColor }) => { + const classes = useStyles({ color }); + return ; +}; From 54bdd07e9cf8e51cb2f5dc94197d505643a49fd3 Mon Sep 17 00:00:00 2001 From: RockySouthpaw <55056068+RockySouthpaw@users.noreply.github.com> Date: Sat, 27 Feb 2021 14:14:49 -0500 Subject: [PATCH 14/17] Fix/number generating (#114) * Fix number not generating on player join. * Update import.sql * Check for existing number Kidz pretty much did this kek * Added error catch to esx:playerLoaded --- resources/import.sql | 2 +- resources/server/sv_main.ts | 35 ++++++++++++++++++----------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/resources/import.sql b/resources/import.sql index 00f6a5f..23d72a2 100644 --- a/resources/import.sql +++ b/resources/import.sql @@ -1,6 +1,6 @@ -- comment this out if your server has a different table/location for phone_number -- or if it already exists in the users table -ALTER TABLE `users` ADD COLUMN `phone_number` VARCHAR(20) NULL DEFAULT NULL; +ALTER TABLE `users` ADD COLUMN `phone_number` VARCHAR(20) DEFAULT NULL; INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES ('phone', 'Phone', 1, 0, 1); INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES ('dphone', 'Destroyed Phone', 1, 0, 1); diff --git a/resources/server/sv_main.ts b/resources/server/sv_main.ts index f11f47b..ae29215 100644 --- a/resources/server/sv_main.ts +++ b/resources/server/sv_main.ts @@ -35,26 +35,27 @@ function getRandomPhoneNumber() { // The numbers inside {} in replace() can be changed to how many digits you want on each side of the dash. // Example: 123-4567 } - mainLogger.verbose(`Getting random number: ${randomNumber}`); return randomNumber; } async function generatePhoneNumber(identifier: string) { - const _identifier = identifier; - let phoneNumber = await usePhoneNumber(_identifier); - let id = await getIdentifierByPhoneNumber(phoneNumber); - - do { - if (!phoneNumber) { - phoneNumber = await getRandomPhoneNumber(); - const query = 'UPDATE users SET phone_number = ? WHERE identifier = ?'; - await pool.query(query, [phoneNumber, _identifier]); - } else { - break; - } - } while (id); + if (!await usePhoneNumber(identifier)) { + let existingId; + let newNumber; + do { + newNumber = getRandomPhoneNumber(); + try { + existingId = await getIdentifierByPhoneNumber(newNumber) + } catch(e) { + existingId = false + } + } while(existingId); + mainLogger.verbose(`Inserting number into Database: ${newNumber}`); + const query = 'UPDATE users SET phone_number = ? WHERE identifier = ?'; + await pool.query(query, [newNumber, identifier]); + } } async function getCredentials(identifier: string): Promise { @@ -65,11 +66,11 @@ async function getCredentials(identifier: string): Promise { return number[0].phone_number; } -on('playerConnecting', async () => { +onNet('esx:playerLoaded', async (playerId: number, xPlayer: any) => { const _source = getSource() try { - const identifier = getIdentifier(_source); - await generatePhoneNumber(identifier) + const identifier = xPlayer.identifier; + await generatePhoneNumber(identifier); } catch(e) { mainLogger.error(`Failed to generate a phone number, ${e.message}`, { source: _source, From 9cfc3fa8ec78e0ba4f897d1d858b10567d3ac51c Mon Sep 17 00:00:00 2001 From: J Francisco Rader Date: Sat, 27 Feb 2021 15:10:59 -0500 Subject: [PATCH 15/17] Remove dependency comments and use useRef instead for useSound hook (#117) * Remove dependency comments and use useRef instead for useSound hook * Handle change URL volume and loop gracefully --- .../apps/example/components/ExampleApp.tsx | 15 +++- phone/src/os/phone/hooks/useSound.ts | 73 ++++++++++--------- 2 files changed, 52 insertions(+), 36 deletions(-) diff --git a/phone/src/apps/example/components/ExampleApp.tsx b/phone/src/apps/example/components/ExampleApp.tsx index ec27821..2f5fc69 100644 --- a/phone/src/apps/example/components/ExampleApp.tsx +++ b/phone/src/apps/example/components/ExampleApp.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import { AppWrapper } from '../../../ui/components'; import { AppContent } from '../../../ui/components/AppContent'; @@ -6,12 +6,17 @@ 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'; +import PlayIcon from '@material-ui/icons/PlayArrow'; +import StopIcon from '@material-ui/icons/Stop'; +import { Button, IconButton } from '@material-ui/core'; +import useSound from '../../../os/phone/hooks/useSound'; export const ExampleApp = () => { // calling the example hook, and we assign the value to a variable const exampleString = useExample(); const example = useApp('EXAMPLE'); + const [soundName, setSound] = useState('pixel.ogg'); + const { play, playing, stop } = useSound('media/ringtones/' + soundName); return ( @@ -21,6 +26,12 @@ export const ExampleApp = () => { {/* Here we are using the value in a h3 tag */}

{exampleString}

+ (playing ? stop() : play())}> + {playing ? : } + +
diff --git a/phone/src/os/phone/hooks/useSound.ts b/phone/src/os/phone/hooks/useSound.ts index 27efa1c..e1cf491 100644 --- a/phone/src/os/phone/hooks/useSound.ts +++ b/phone/src/os/phone/hooks/useSound.ts @@ -13,70 +13,75 @@ interface ISoundOptions { * * @param { volume, interrupt, loop} Additional options **/ - const useSound = ( url: string, { volume = 1, interrupt = false, loop = false }: ISoundOptions = {} ) => { - const isMounted = useRef(false); + const [isMounted, setMounted] = useState(false); + const soundRef = useRef(null); const [playing, setPlaying] = useState(false); - const [sound, setSound] = useState(null); - // Mount & Dismount handling useEffect(() => { - isMounted.current = true; - const sound = new Howl({ + soundRef.current?.unload(); + setPlaying(false); + setMounted(false); + + soundRef.current = new Howl({ src: url, - volume, - loop, + volume: 1, + loop: false, }); - setSound(sound); + + setMounted(true); return () => { - isMounted.current = false; + soundRef.current?.unload(); + soundRef.current = undefined; }; - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [url]); useEffect(() => { - if (sound) { - sound.volume(volume); + if (isMounted) { + soundRef.current.volume(volume); } - // Shouldnt need to rerun if sound changes - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [volume]); + }, [volume, isMounted]); + + useEffect(() => { + if (isMounted) { + soundRef.current.loop(loop); + } + }, [loop, isMounted]); const play = useCallback(() => { - if (!sound) return; + if (!soundRef.current) return; - if (interrupt) return sound.stop(); - - sound.play(); - - if (isMounted.current) { - sound.once('end', () => { - if (!sound.playing()) { + if (isMounted) { + soundRef.current.play(); + soundRef.current.once('end', () => { + if (!soundRef.current.playing()) { setPlaying(false); } }); - } - - if (isMounted.current) { setPlaying(true); } - }, [interrupt, sound]); + }, [isMounted]); const stop = useCallback(() => { - if (!sound) return; + if (!soundRef.current) return; - sound.stop(); - - if (isMounted.current) { + if (isMounted) { + soundRef.current.stop(); setPlaying(false); } - }, [sound]); + }, [isMounted]); + + useEffect(() => { + if (interrupt && isMounted) { + stop(); + } + }, [interrupt, isMounted, stop]); return { play, playing, stop }; }; From ee7e544b23b93f8f69858007b311d816e77c62b5 Mon Sep 17 00:00:00 2001 From: Christopher Gjelten Date: Sat, 27 Feb 2021 21:23:29 +0100 Subject: [PATCH 16/17] Fix: typo in dialerHistory? --- phone/src/apps/dialer/components/views/DialerHistory.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phone/src/apps/dialer/components/views/DialerHistory.tsx b/phone/src/apps/dialer/components/views/DialerHistory.tsx index 3b2de84..80a8dab 100644 --- a/phone/src/apps/dialer/components/views/DialerHistory.tsx +++ b/phone/src/apps/dialer/components/views/DialerHistory.tsx @@ -103,7 +103,7 @@ export const DialerHistory = ({ calls }) => { primary={getDisplayByNumber(call.transmitter)} secondary={dayjs.unix(call.start).format(t('DATE_TIME_FORMAT'))} /> - handleCall(call.receiver)}> + handleCall(call.transmitter)}> {} From 1c81bfa7f2ee306a71c6f69d582df329653a9192 Mon Sep 17 00:00:00 2001 From: Christopher Date: Sun, 28 Feb 2021 00:05:07 +0100 Subject: [PATCH 17/17] fix(camera): resolve issue for deleting images --- phone/src/apps/camera/components/CameraApp.tsx | 2 +- .../apps/camera/components/modal/GalleryModal.tsx | 12 ++++++++---- resources/server/sv_photo.ts | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/phone/src/apps/camera/components/CameraApp.tsx b/phone/src/apps/camera/components/CameraApp.tsx index cc170c9..6c6b175 100644 --- a/phone/src/apps/camera/components/CameraApp.tsx +++ b/phone/src/apps/camera/components/CameraApp.tsx @@ -16,7 +16,7 @@ InjectDebugData([ image: 'https://i.imgur.com/OO8wx6Z.jpg', }, { - id: 1, + id: 2, image: 'https://i.imgur.com/pqGBiST.jpg', }, ], diff --git a/phone/src/apps/camera/components/modal/GalleryModal.tsx b/phone/src/apps/camera/components/modal/GalleryModal.tsx index 5f3b414..96b0522 100644 --- a/phone/src/apps/camera/components/modal/GalleryModal.tsx +++ b/phone/src/apps/camera/components/modal/GalleryModal.tsx @@ -27,12 +27,12 @@ export const GalleryModal = () => { history.push(referal); }; - const handleDeletePhoto = useCallback(() => { + const handleDeletePhoto = () => { Nui.send('photo:deletePhoto', { - id: meta.id, + image: meta.image, }); history.push(referal); - }, [history, meta.id, referal]); + }; const handleSharePhoto = useCallback(() => { setShareOpen(meta); @@ -42,7 +42,11 @@ export const GalleryModal = () => { return ( <> - setShareOpen(null)} /> + setShareOpen(null)} + />