From babce2f5683ab95dbff9ad10887436154d9e1f10 Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 9 Feb 2021 00:35:35 +0100 Subject: [PATCH 01/30] feat(SnackbarProvider): initial provider --- phone/src/ui/components/SnackBar.tsx | 9 ++++++ phone/src/ui/components/SnackbarProvider.tsx | 30 ++++++++++++++++++++ phone/src/ui/hooks/useSnackbar.ts | 8 ++++++ 3 files changed, 47 insertions(+) create mode 100644 phone/src/ui/components/SnackBar.tsx create mode 100644 phone/src/ui/components/SnackbarProvider.tsx create mode 100644 phone/src/ui/hooks/useSnackbar.ts diff --git a/phone/src/ui/components/SnackBar.tsx b/phone/src/ui/components/SnackBar.tsx new file mode 100644 index 0000000..4d23f16 --- /dev/null +++ b/phone/src/ui/components/SnackBar.tsx @@ -0,0 +1,9 @@ +import React from 'react'; + +export const SnackBar = ({ children }) => { + return ( +
+

{children}

+
+ ) +} \ No newline at end of file diff --git a/phone/src/ui/components/SnackbarProvider.tsx b/phone/src/ui/components/SnackbarProvider.tsx new file mode 100644 index 0000000..7947098 --- /dev/null +++ b/phone/src/ui/components/SnackbarProvider.tsx @@ -0,0 +1,30 @@ +import React, { createContext, useState, useEffect, useMemo, useCallback } from 'react'; +import { SnackBar } from './SnackBar'; + + +export const SnackbarContext = createContext(null); +const AUTO_HIDE = 2000; + +function SnackbarProvider({ children }) { + const [alerts, setAlerts] = useState([]); + + const alertIdx = alerts.join(','); + + useEffect(() => { + const timer = setTimeout(() => setAlerts((alert) => alerts.slice(0, alerts.length - 1)), AUTO_HIDE); + return () => clearTimeout(timer); + }, [alertIdx]) + + const addAlert = useCallback((content) => setAlerts((alerts) => [content, ...alerts]), []); + + const value = useMemo(() => ({ addAlert }), [addAlert]); + + return ( + + {children} + {alerts.map((alert) => {alert})} + + ) +} + +export default SnackbarProvider; \ No newline at end of file diff --git a/phone/src/ui/hooks/useSnackbar.ts b/phone/src/ui/hooks/useSnackbar.ts new file mode 100644 index 0000000..fe6077a --- /dev/null +++ b/phone/src/ui/hooks/useSnackbar.ts @@ -0,0 +1,8 @@ +import { useContext } from 'react'; +import { SnackbarContext } from '../components/SnackbarProvider'; + +interface ISnackBar { + addAlert: (message: string, severity: string) => void; +} + +export const useSnackbar = (): ISnackBar => useContext(SnackbarContext); \ No newline at end of file From c0509be2d18f51e40ace633ba778940e84695ed2 Mon Sep 17 00:00:00 2001 From: Taso Date: Tue, 9 Feb 2021 09:59:54 -0500 Subject: [PATCH 02/30] Refactored Contacts to use Routes and not a Modal (#80) The new route allows for other components to directly route to contacts/:id, where id is the contact id for a users given contacts. It also adds a getContact function accessible by the useConfig hook in case a contact needs to be retrieved using a contact id. --- .../apps/contacts/components/ContactModal.tsx | 85 -------- .../apps/contacts/components/ContactTitle.tsx | 13 -- .../apps/contacts/components/ContactsApp.tsx | 47 ++--- .../contacts/components/List/ContactList.tsx | 94 +++++---- .../contacts/components/modal/InfoModal.tsx | 112 ---------- .../contacts/components/modal/modal.styles.ts | 49 ----- .../components/styles.contactmodal.ts | 45 ---- .../contacts/components/styles.contacts.ts | 35 ---- .../contacts/components/views/ContactInfo.tsx | 197 ++++++++++++++++++ .../components/views/ContactsPage.tsx | 39 ++++ .../apps/contacts/hooks/useContactDetail.ts | 15 -- .../apps/contacts/hooks/useContactModal.ts | 12 -- phone/src/apps/contacts/hooks/useContacts.ts | 26 ++- phone/src/common/typings/contact.ts | 8 +- 14 files changed, 324 insertions(+), 453 deletions(-) delete mode 100644 phone/src/apps/contacts/components/ContactModal.tsx delete mode 100644 phone/src/apps/contacts/components/ContactTitle.tsx delete mode 100644 phone/src/apps/contacts/components/modal/InfoModal.tsx delete mode 100644 phone/src/apps/contacts/components/modal/modal.styles.ts delete mode 100644 phone/src/apps/contacts/components/styles.contactmodal.ts delete mode 100644 phone/src/apps/contacts/components/styles.contacts.ts create mode 100644 phone/src/apps/contacts/components/views/ContactInfo.tsx create mode 100644 phone/src/apps/contacts/components/views/ContactsPage.tsx delete mode 100644 phone/src/apps/contacts/hooks/useContactDetail.ts delete mode 100644 phone/src/apps/contacts/hooks/useContactModal.ts diff --git a/phone/src/apps/contacts/components/ContactModal.tsx b/phone/src/apps/contacts/components/ContactModal.tsx deleted file mode 100644 index 994c4da..0000000 --- a/phone/src/apps/contacts/components/ContactModal.tsx +++ /dev/null @@ -1,85 +0,0 @@ -import React, { useState } from 'react'; -import { Button, TextField } from '@material-ui/core'; -import Nui from '../../../os/nui-events/utils/Nui'; -import List from '@material-ui/core/List'; -import ListItem from '@material-ui/core/ListItem'; -import Modal from '../../../ui/components/Modal'; -import { useModal } from '../hooks/useModal'; -import PersonIcon from '@material-ui/icons/Person'; -import PhoneIcon from '@material-ui/icons/Phone'; -import AccountCircleIcon from '@material-ui/icons/AccountCircle'; -import useStyles from './styles.contactmodal'; -import { useTranslation } from 'react-i18next'; - -export const AddContactModal = () => { - const [name, setName] = useState(''); - const [number, setNumber] = useState(''); - const [avatar, setAvatar] = useState(''); - const classes = useStyles(); - - const { t } = useTranslation(); - - const { showModal, setShowModal } = useModal(); - - const addContact = () => { - if (name === '' || number === '') { - console.log('You need to pass in values'); - } else { - Nui.send('contacts:add', { - name, - number, - avatar, - }); - setShowModal(false) - } - }; - - const _handleClose = () => { - setShowModal(false); - }; - - return ( - - - - - setName(e.target.value)} - fullWidth - variant='standard' - placeholder={t('APPS_CONTACT_MODAL_PLACEHOLDER_NAME')} - /> - - - - setNumber(e.target.value)} - fullWidth - placeholder={t('APPS_CONTACT_MODAL_PLACEHOLDER_NUMBER')} - variant='standard' - type='text' - /> - - - - setAvatar(e.target.value)} - fullWidth - placeholder={t('APPS_CONTACT_MODAL_PLACEHOLDER_AVATAR')} - variant='standard' - type='text' - /> - - - - - ); -}; diff --git a/phone/src/apps/contacts/components/ContactTitle.tsx b/phone/src/apps/contacts/components/ContactTitle.tsx deleted file mode 100644 index adcda87..0000000 --- a/phone/src/apps/contacts/components/ContactTitle.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import React from 'react'; -import Paper from '@material-ui/core/Paper'; -import ContactsIcon from '@material-ui/icons/Contacts'; -import useStyles from './styles.contacts'; - -export const ContactTitle = () => { - const classes = useStyles(); - return ( - - - - ); -}; diff --git a/phone/src/apps/contacts/components/ContactsApp.tsx b/phone/src/apps/contacts/components/ContactsApp.tsx index 506be6a..b3b1760 100644 --- a/phone/src/apps/contacts/components/ContactsApp.tsx +++ b/phone/src/apps/contacts/components/ContactsApp.tsx @@ -2,18 +2,12 @@ import React from 'react'; import { AppWrapper } from '../../../ui/components'; import { AppTitle } from '../../../ui/components/AppTitle'; import { AppContent } from '../../../ui/components/AppContent'; -import { ContactList } from './List/ContactList'; import { useApp } from '../../../os/apps/hooks/useApps'; -import { AddContactModal } from './ContactModal'; -import { useModal } from '../hooks/useModal'; -import PersonAddIcon from '@material-ui/icons/PersonAdd'; -import Fab from '@material-ui/core/Fab'; -import { InfoModal } from './modal/InfoModal'; -import { useContactDetail } from '../hooks/useContactDetail'; -import { ContactAlert } from './alert/ContactAlert'; - -import useStyles from './styles.contacts'; import InjectDebugData from '../../../os/debug/InjectDebugData'; +import { Route } from 'react-router-dom'; + +import ContactsInfoPage from './views/ContactInfo'; +import { ContactPage } from './views/ContactsPage'; InjectDebugData([ { @@ -23,43 +17,32 @@ InjectDebugData([ { id: 1, display: 'Ruqen', - number: '43534444', + number: '555-15196', }, { - id: 1, + id: 2, display: 'Taso', - number: '456466', + number: '215-8139', + avatar: 'http://i.tasoagc.dev/i9Ig', + }, + { + id: 3, + display: 'Chip', + number: '417-8792', }, ], }, ]); export const ContactsApp = () => { - const classes = useStyles(); - const { showModal, setShowModal } = useModal(); const contacts = useApp('CONTACTS'); - const { contactDetail } = useContactDetail(); - - const openModal = () => { - setShowModal(true); - }; return ( - - -
- - - - - + + ); diff --git a/phone/src/apps/contacts/components/List/ContactList.tsx b/phone/src/apps/contacts/components/List/ContactList.tsx index da9e14d..b120a45 100644 --- a/phone/src/apps/contacts/components/List/ContactList.tsx +++ b/phone/src/apps/contacts/components/List/ContactList.tsx @@ -14,78 +14,84 @@ 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 { useContactModal } from '../../hooks/useContactModal'; -import { useContactDetail } from '../../hooks/useContactDetail'; 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'; export const ContactList = () => { const { filteredContacts } = useFilteredContacts(); - const { setShowContactModal } = useContactModal(); - const { setContactDetail } = useContactDetail(); + const history = useHistory(); - const contacts = useContacts(); + const { contacts } = useContacts(); - const openContactInfo = (contact) => { - setShowContactModal(true); - setContactDetail(contact); + const openContactInfo = (contactId: number) => { + history.push(`/contacts/${contactId}`); }; - const startCall = (number) => { - console.log(number); + + const startCall = (number: string) => { + LogDebugEvent({ + action: 'Emitting `Start Call` to Scripts', + level: 2, + data: true, + }); Nui.send('phone:beginCall', { number, }); }; + const handleMessage = () => { + LogDebugEvent({ + action: 'Routing to Message', + level: 1, + data: true, + }); + // TODO: Integrate to send to message event when route becomes available + }; + const filteredRegEx = new RegExp(filteredContacts, 'gi'); return ( <> - {contacts.contacts + {contacts .filter( (contact) => contact.display.match(filteredRegEx) || contact.number.match(filteredRegEx) ) .map((contact) => ( - <> - - - {contact.avatar ? ( - - ) : ( - - {contact.display.slice(0, 1).toUpperCase()} - - )} - - - - - - - + + + {contact.avatar ? ( + + ) : ( + + {contact.display.slice(0, 1).toUpperCase()} + + )} + + + + + + ))} diff --git a/phone/src/apps/contacts/components/modal/InfoModal.tsx b/phone/src/apps/contacts/components/modal/InfoModal.tsx deleted file mode 100644 index 98456a5..0000000 --- a/phone/src/apps/contacts/components/modal/InfoModal.tsx +++ /dev/null @@ -1,112 +0,0 @@ -import React, { useState } from 'react'; -import { - Paper, - Slide, - Button, - TextField, - Avatar as MuiAvatar, -} from '@material-ui/core'; -import useStyles from './modal.styles'; -import { useContactModal } from '../../hooks/useContactModal'; -import ArrowBackIcon from '@material-ui/icons/ArrowBack'; - -import { useTranslation } from 'react-i18next'; -import { useContactDetail } from '../../hooks/useContactDetail'; -import Nui from '../../../../os/nui-events/utils/Nui'; - -export const InfoModal = () => { - const classes = useStyles(); - const { showContactModal, setShowContactModal } = useContactModal(); - const { t } = useTranslation(); - const { contactDetail, setContactDetail } = useContactDetail(); - - const [display, setDisplay] = useState( - contactDetail ? contactDetail.display : '' - ); - console.log(contactDetail); - const [number, setNumber] = useState( - contactDetail ? contactDetail.number : '' - ); - const [avatar, setAvatar] = useState( - contactDetail ? contactDetail.avatar : '' - ); - - const closeModal = () => { - setShowContactModal(false); - setContactDetail(null); - }; - - const updateContact = () => { - Nui.send('phone:updateContact', { - id: contactDetail.id, - display, - number, - avatar, - }); - setContactDetail(null); - setShowContactModal(false); - }; - - const deleteContact = () => { - Nui.send('phone:deleteContact', { - id: contactDetail.id, - }); - setContactDetail(null); - setShowContactModal(false); - }; - - return ( - - - -
- - setDisplay(e.target.value)} - placeholder={t('APPS_CONTACT_FORM_NAME')} - fullWidth - inputProps={{ - className: classes.inputProps, - }} - /> - setNumber(e.target.value)} - placeholder={t('APPS_CONTACT_FORM_NUMBER')} - fullWidth - inputProps={{ - className: classes.inputProps, - }} - /> - setAvatar(e.target.value)} - inputProps={{ - className: classes.inputProps, - }} - /> - -
- - -
-
-
-
- ); -}; diff --git a/phone/src/apps/contacts/components/modal/modal.styles.ts b/phone/src/apps/contacts/components/modal/modal.styles.ts deleted file mode 100644 index 4b4c94e..0000000 --- a/phone/src/apps/contacts/components/modal/modal.styles.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { makeStyles } from '@material-ui/core'; - -const useStyles = makeStyles((theme) => ({ - modalRoot: { - zIndex: 10, - position: 'absolute', - height: '100%', - width: '100%', - }, - modalHide: { - display: 'none', - }, - listContainer: { - marginTop: 30, - width: '75%', - margin: '0 auto', - textAlign: 'center', - }, - avatar: { - margin: 'auto', - height: '125px', - width: '124px', - marginBottom: 29, - }, - input: { - marginBottom: 20, - margin: 'auto', - textAlign: 'center', - }, - 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, - }, -})); - -export default useStyles; diff --git a/phone/src/apps/contacts/components/styles.contactmodal.ts b/phone/src/apps/contacts/components/styles.contactmodal.ts deleted file mode 100644 index b208bb9..0000000 --- a/phone/src/apps/contacts/components/styles.contactmodal.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { makeStyles, Theme } from '@material-ui/core/styles'; - -const useStyles = makeStyles((theme: Theme) => ({ - button: { - margin: 5, - marginTop: 20, - }, - root: { - position: 'fixed', - bottom: 380, - zIndex: 2, - background: '#232323', - marginLeft: '-4em', - height: '20%', - }, - clearButton: { - width: '10%', - position: 'absolute', - right: 0, - }, - textInputField: { - fontSize: 20, - borderBottomColor: 'red', - }, - addBtn: { - margin: 'auto', - fontSize: 16, - width: 150, - background: '#2196f3', - marginBottom: 10, - padding: 8, - }, - cancelBtn: { - margin: 'auto', - width: 150, - background: '#232323', - marginBottom: 20, - padding: 8, - }, - icons: { - marginRight: 5, - }, -})); - -export default useStyles; diff --git a/phone/src/apps/contacts/components/styles.contacts.ts b/phone/src/apps/contacts/components/styles.contacts.ts deleted file mode 100644 index d7c622f..0000000 --- a/phone/src/apps/contacts/components/styles.contacts.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { makeStyles, Theme } from '@material-ui/core/styles'; - -const useStyles = makeStyles((theme: Theme) => ({ - backgroundModal: { - background: 'black', - opacity: '0.6', - position: 'absolute', - top: 0, - left: 0, - right: 0, - bottom: 0, - zIndex: 5, - }, - absolute: { - position: 'absolute', - bottom: theme.spacing(2), - left: theme.spacing(3), - }, - // title - root: { - height: '60px', - width: '100%', - display: 'flex', - flexFlow: 'row nowrap', - justifyContent: 'center', - alignItems: 'center', - background: '#424242', - }, - icon: { - color: '#fff', - fontSize: 30, - }, -})); - -export default useStyles; diff --git a/phone/src/apps/contacts/components/views/ContactInfo.tsx b/phone/src/apps/contacts/components/views/ContactInfo.tsx new file mode 100644 index 0000000..c4cfb95 --- /dev/null +++ b/phone/src/apps/contacts/components/views/ContactInfo.tsx @@ -0,0 +1,197 @@ +import React, { useState } from 'react'; +import { + Avatar as MuiAvatar, + Button, + Paper, + TextField, +} from '@material-ui/core'; +import { makeStyles, Theme } from '@material-ui/core/styles'; +import { useTranslation } from 'react-i18next'; +import { useHistory, useParams } from 'react-router-dom'; +import { useContacts } from '../../hooks/useContacts'; +import Nui from '../../../../os/nui-events/utils/Nui'; +import ArrowBackIcon from '@material-ui/icons/ArrowBack'; +import LogDebugEvent from '../../../../os/debug/LogDebugEvents'; + +interface ContactInfoRouteParams { + mode: string; + id: string; +} + +const useStyles = makeStyles((theme: Theme) => ({ + root: { + height: '100%', + width: '100%', + }, + listContainer: { + marginTop: 30, + width: '75%', + margin: '0 auto', + textAlign: 'center', + }, + avatar: { + margin: 'auto', + height: '125px', + width: '124px', + marginBottom: 29, + }, + input: { + marginBottom: 20, + margin: 'auto', + textAlign: 'center', + }, + 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 = () => { + const classes = useStyles(); + + const history = useHistory(); + + const { getContact } = useContacts(); + + const { id } = useParams(); + + const contact = getContact(parseInt(id)); + + // Set state after checking if null + const [name, setName] = useState(contact ? contact.display : contact); + const [number, setNumber] = useState(contact ? contact.number : contact); + const [avatar, setAvatar] = useState(contact ? contact.avatar : contact); + + const { t } = useTranslation(); + + const handleContactAdd = () => { + LogDebugEvent({ + action: 'Handling Contact Add', + data: contact, + level: 2, + }); + Nui.send('phone:addContact', { + name, + number, + avatar, + }); + }; + + const handleContactSave = () => { + LogDebugEvent({ + action: 'Handling Contact Update', + data: contact, + level: 2, + }); + Nui.send('phone:updateContact', { + id: contact.id, + display: name, + number, + avatar, + }); + }; + + const handleContactDelete = () => { + LogDebugEvent({ + action: 'Handling Contact Delete', + data: contact, + level: 2, + }); + Nui.send('phone:deleteContact', { + id: contact.id, + }); + }; + + return ( + + +
+ {avatar ? ( + + ) : ( + + )} + setName(e.target.value)} + placeholder={t('APPS_CONTACT_FORM_NAME')} + fullWidth + inputProps={{ + className: classes.inputProps, + }} + /> + setNumber(e.target.value)} + placeholder={t('APPS_CONTACT_FORM_NUMBER')} + fullWidth + inputProps={{ + className: classes.inputProps, + }} + /> + setAvatar(e.target.value)} + inputProps={{ + className: classes.inputProps, + }} + /> + {/* Display if fetched contact */} + {contact && ( +
+ + +
+ )} + {/* Display if no fetched contact */} + {!contact && ( +
+ +
+ )} +
+
+ ); +}; + +export default ContactsInfoPage; diff --git a/phone/src/apps/contacts/components/views/ContactsPage.tsx b/phone/src/apps/contacts/components/views/ContactsPage.tsx new file mode 100644 index 0000000..49644c6 --- /dev/null +++ b/phone/src/apps/contacts/components/views/ContactsPage.tsx @@ -0,0 +1,39 @@ +import React from 'react'; +import { ContactList } from '../List/ContactList'; +import Fab from '@material-ui/core/Fab'; +import PersonAddIcon from '@material-ui/icons/PersonAdd'; +import { ContactAlert } from '../alert/ContactAlert'; +import { useHistory } from 'react-router-dom'; +import { makeStyles, Theme } from '@material-ui/core/styles'; + +const useStyles = makeStyles((theme: Theme) => ({ + absolute: { + position: 'absolute', + bottom: theme.spacing(2), + right: theme.spacing(2), + }, + icon: { + color: '#fff', + fontSize: 30, + }, +})); + +export const ContactPage = () => { + const history = useHistory(); + + const classes = useStyles(); + + return ( + <> + + history.push('/contacts/add')} + style={{ backgroundColor: '#2196f3', color: '#fff' }} + className={classes.absolute} + > + + + + + ); +}; diff --git a/phone/src/apps/contacts/hooks/useContactDetail.ts b/phone/src/apps/contacts/hooks/useContactDetail.ts deleted file mode 100644 index fc929cf..0000000 --- a/phone/src/apps/contacts/hooks/useContactDetail.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { useRecoilState } from 'recoil'; -import { ContactProps } from '../../../common/typings/contact'; -import { contactsState } from './state'; - -interface ContactDetailProps { - contactDetail: ContactProps; - setContactDetail: (contact: object) => void; -} - - - -export const useContactDetail = (): ContactDetailProps => { - const [ contactDetail, setContactDetail ] = useRecoilState(contactsState.contactDetail); - return { contactDetail, setContactDetail }; -}; diff --git a/phone/src/apps/contacts/hooks/useContactModal.ts b/phone/src/apps/contacts/hooks/useContactModal.ts deleted file mode 100644 index bb87cea..0000000 --- a/phone/src/apps/contacts/hooks/useContactModal.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { useRecoilState } from 'recoil'; -import { contactsState } from './state'; - -interface ModalProps { - showContactModal: boolean; - setShowContactModal: (show: boolean) => void; -} - -export const useContactModal = (): ModalProps => { - const [ showContactModal, setShowContactModal ] = useRecoilState(contactsState.showContactsModal); - return { showContactModal, setShowContactModal }; -}; diff --git a/phone/src/apps/contacts/hooks/useContacts.ts b/phone/src/apps/contacts/hooks/useContacts.ts index 780e993..55a1ef4 100644 --- a/phone/src/apps/contacts/hooks/useContacts.ts +++ b/phone/src/apps/contacts/hooks/useContacts.ts @@ -1,19 +1,31 @@ import { useRecoilValue } from 'recoil'; import { contactsState } from './state'; -import { ContactProps } from '../../../common/typings/contact'; +import { Contact } from '../../../common/typings/contact'; import { useCallback } from 'react'; interface IUseContacts { - contacts: ContactProps[] + contacts: Contact[]; getDisplayByNumber: (number: string) => string; + getContact: (id: number) => Contact; } export const useContacts = (): IUseContacts => { const contacts = useRecoilValue(contactsState.contacts); - const getDisplayByNumber = useCallback((number: string) => { - const found = contacts.find((contact) => contact.number === number) - return found ? found.display : number - }, [contacts]) - return { contacts, getDisplayByNumber }; + const getDisplayByNumber = useCallback( + (number: string) => { + const found = contacts.find((contact) => contact.number === number); + return found ? found.display : number; + }, + [contacts] + ); + const getContact = useCallback( + (id: number): Contact | null => { + for (const contact of contacts) { + if (contact.id === id) return contact; + } + }, + [contacts] + ); + return { contacts, getDisplayByNumber, getContact }; }; diff --git a/phone/src/common/typings/contact.ts b/phone/src/common/typings/contact.ts index f085d32..6d387bb 100644 --- a/phone/src/common/typings/contact.ts +++ b/phone/src/common/typings/contact.ts @@ -11,9 +11,9 @@ export interface IContactAlert { setAlert: (type: string) => void; } -export interface ContactProps { - id: string; +export interface Contact { + id: number; display: string; number: string; - avatar?: string -} \ No newline at end of file + avatar?: string; +} From b73919c147bc6863998d84b618e84c76f99f2f86 Mon Sep 17 00:00:00 2001 From: Taso Date: Tue, 9 Feb 2021 11:14:52 -0500 Subject: [PATCH 03/30] fix(phone/tweet): Fixed possible XSS vector As we were parsing user input for \n in order to convert to
tags, a XSS vulnerability was introduced allowing for users to pass arbitrary script tags to be rendered in tweets. --- phone/package.json | 1 + phone/src/apps/twitter/components/TwitterApp.tsx | 12 ++++++++++++ phone/src/apps/twitter/components/tweet/Tweet.tsx | 15 +++++++++++++-- phone/yarn.lock | 5 +++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/phone/package.json b/phone/package.json index 1e6e99a..834dbe5 100644 --- a/phone/package.json +++ b/phone/package.json @@ -21,6 +21,7 @@ "@types/jest": "^26.0.14", "core-js": "^3.6.5", "dayjs": "^1.10.4", + "dompurify": "^2.2.6", "emoji-mart": "^3.0.0", "enzyme": "^3.11.0", "enzyme-adapter-react-16": "^1.15.5", diff --git a/phone/src/apps/twitter/components/TwitterApp.tsx b/phone/src/apps/twitter/components/TwitterApp.tsx index 446ef13..11c2573 100644 --- a/phone/src/apps/twitter/components/TwitterApp.tsx +++ b/phone/src/apps/twitter/components/TwitterApp.tsx @@ -37,6 +37,18 @@ InjectDebugData([ app: 'TWITTER', method: 'fetchTweets', data: [ + { + id: 59, + message: 'XSS\n\nBro', + avatar_url: 'http://i.tasoagc.dev/jtKL', + seconds_since_tweet: 500, + isMine: false, + updateAt: '2021-02-08 14:37:46', + visible: 1, + likes: 50000, + profile_name: 'jQuery Main', + images: 'http://i.tasoagc.dev/0xdp', + }, { id: 2, message: 'GCPhone will never die', diff --git a/phone/src/apps/twitter/components/tweet/Tweet.tsx b/phone/src/apps/twitter/components/tweet/Tweet.tsx index 5e99f83..d382a36 100644 --- a/phone/src/apps/twitter/components/tweet/Tweet.tsx +++ b/phone/src/apps/twitter/components/tweet/Tweet.tsx @@ -7,7 +7,6 @@ import { ListItem, Typography, } from '@material-ui/core'; - import { secondsToHumanReadable } from '../../utils/time'; import LikeButton from '../buttons/LikeButton'; import ReplyButton from '../buttons/ReplyButton'; @@ -16,6 +15,7 @@ import Avatar from '../Avatar'; import ShowMore from './ShowMore'; import { QuoteButton } from '../buttons/QuoteButton'; import { usePhone } from '../../../../os/phone/hooks/usePhone'; +import DOMPurify from 'dompurify'; const useStyles = makeStyles(() => ({ root: { @@ -80,7 +80,16 @@ export const Tweet = (tweet) => { // this is a workaround to transfer string new lines and returns that // are stored into the database into html for the UI to render + + // We are replacing with
to eventually render in HTML const formattedMessage = message.replace(/\n\r?/g, '
'); + + // Therefore we need to sanitize this message to protect against XSS + const sanitizedMessage = DOMPurify.sanitize(formattedMessage, { + // Be as strict as possible, whitelisting
tag + ALLOWED_TAGS: ['br'], + }); + const profileName = profile_name ? `@${profile_name}` : ''; return ( @@ -106,7 +115,9 @@ export const Tweet = (tweet) => {
{enableImages && }
diff --git a/phone/yarn.lock b/phone/yarn.lock index 1598c19..34f5fc5 100644 --- a/phone/yarn.lock +++ b/phone/yarn.lock @@ -4629,6 +4629,11 @@ domhandler@^2.3.0: dependencies: domelementtype "1" +dompurify@^2.2.6: + version "2.2.6" + resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-2.2.6.tgz#54945dc5c0b45ce5ae228705777e8e59d7b2edc4" + integrity sha512-7b7ZArhhH0SP6W2R9cqK6RjaU82FZ2UPM7RO8qN1b1wyvC/NY1FNWcX1Pu00fFOAnzEORtwXe4bPaClg6pUybQ== + domutils@1.5.1: version "1.5.1" resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.5.1.tgz#dcd8488a26f563d61079e48c9f7b7e32373682cf" From fdfd4133e20bb40f4fe6ea523e990cb3287bdff7 Mon Sep 17 00:00:00 2001 From: RockySouthpaw <55056068+RockySouthpaw@users.noreply.github.com> Date: Tue, 9 Feb 2021 12:55:29 -0500 Subject: [PATCH 04/30] Added kash disclaimer. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e7327b5..2f39e73 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,9 @@ The Installation Steps assumes you have the following prerequisites: #### Important Note -By installing NPWD you agree to the use of the following diagnostic package, Sentry, (in use within the React portion of NPWD), that automatically +- By installing NPWD you agree to the use of the following diagnostic package, Sentry, (in use within the React portion of NPWD), that automatically uploads relevant sesssion details and stack traces whenever an exception is thrown. We use these metrics to further improve the quality of the phone. To explicitly disable this (we urge you not to as its incredibly useful metrics for us). Please change the `SentryErrorMetrics` setting to `false` in `phone/config/default.json` and rebuild the phone. + +- This resource has **NOT** been tested with [esx_kashacter](https://github.com/FiveEYZ/esx_kashacter) so compatability with it is unknown. For best results, use the resource on with no kash. From c38fe9ef66708777702370d8b20b8725668bf89f Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 9 Feb 2021 19:19:36 +0100 Subject: [PATCH 05/30] feat(SnackbarProvider): interface update | wrap around phone --- phone/src/Phone.tsx | 23 +++++++++------- phone/src/ui/components/SnackbarProvider.tsx | 29 +++++++++++++++++--- phone/src/ui/hooks/useSnackbar.ts | 2 +- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index 547f0c0..bbca10f 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -32,6 +32,7 @@ import { useModal } from './modal/hooks/useModal'; import { useDialService } from './apps/dialer/hooks/useDialService'; import InjectDebugData from './os/debug/InjectDebugData'; import { useQuickAccess } from './os/notifications/hooks/useQuickAccess'; +import SnackbarProvider from './ui/components/SnackbarProvider'; InjectDebugData([ { @@ -151,16 +152,18 @@ function Phone() { }))} />
- {modal ? ( - - ) : ( - <> - - {allApps.map((App) => ( - - ))} - - )} + + {modal ? ( + + ) : ( + <> + + {allApps.map((App) => ( + + ))} + + )} +
diff --git a/phone/src/ui/components/SnackbarProvider.tsx b/phone/src/ui/components/SnackbarProvider.tsx index 7947098..4df39a6 100644 --- a/phone/src/ui/components/SnackbarProvider.tsx +++ b/phone/src/ui/components/SnackbarProvider.tsx @@ -1,12 +1,25 @@ import React, { createContext, useState, useEffect, useMemo, useCallback } from 'react'; -import { SnackBar } from './SnackBar'; +import Alert from './Alert'; +import { makeStyles } from '@material-ui/core/styles'; +import { Snackbar } from '@material-ui/core'; + +const useStyles = makeStyles(() => ({ + alert: { + position: 'absolute', + bottom: '15%', + right: '25%', + margin: '0 auto', + textAlign: 'center' + } +})) export const SnackbarContext = createContext(null); -const AUTO_HIDE = 2000; +const AUTO_HIDE = 1500; function SnackbarProvider({ children }) { const [alerts, setAlerts] = useState([]); + const classes = useStyles(); const alertIdx = alerts.join(','); @@ -21,8 +34,16 @@ function SnackbarProvider({ children }) { return ( - {children} - {alerts.map((alert) => {alert})} + <> + {children} + {alerts.map((alert) => ( +
+ + {alert} + +
+ ))} +
) } diff --git a/phone/src/ui/hooks/useSnackbar.ts b/phone/src/ui/hooks/useSnackbar.ts index fe6077a..ee9dd33 100644 --- a/phone/src/ui/hooks/useSnackbar.ts +++ b/phone/src/ui/hooks/useSnackbar.ts @@ -2,7 +2,7 @@ import { useContext } from 'react'; import { SnackbarContext } from '../components/SnackbarProvider'; interface ISnackBar { - addAlert: (message: string, severity: string) => void; + addAlert: (message: string, type: string) => void; } export const useSnackbar = (): ISnackBar => useContext(SnackbarContext); \ No newline at end of file From 6b21cfddd084c31e4435f0593aa5fb55caae22cc Mon Sep 17 00:00:00 2001 From: Taso Date: Tue, 9 Feb 2021 18:16:04 -0500 Subject: [PATCH 06/30] cleanup(scripts/cl_photo): Cleaned up code --- resources/client/cl_photo.ts | 98 +++++++++++++++++------------------- 1 file changed, 47 insertions(+), 51 deletions(-) diff --git a/resources/client/cl_photo.ts b/resources/client/cl_photo.ts index 6bc00e4..e65bfe7 100644 --- a/resources/client/cl_photo.ts +++ b/resources/client/cl_photo.ts @@ -4,7 +4,10 @@ const SCREENSHOT_BASIC_TOKEN = GetConvar('SCREENSHOT_BASIC_TOKEN', 'none'); const exp = (global as any).exports; +let inCameraMode = false; + function closePhoneTemp() { + SetNuiFocus(false, false); SendNuiMessage( //Hides phone JSON.stringify({ @@ -16,6 +19,7 @@ function closePhoneTemp() { } function openPhoneTemp() { + SetNuiFocus(true, true); SendNuiMessage( //Opens phone JSON.stringify({ @@ -26,74 +30,66 @@ function openPhoneTemp() { ); } -let takingPhoto = false; - -function CellFrontCamActivate(activate: any) { +function CellFrontCamActivate(activate: boolean) { return Citizen.invokeNative('0x2491A93618B7D838', activate); } -RegisterNuiCallbackType(events.CAMERA_TAKE_PHOTO); -on(`__cfx_nui:${events.CAMERA_TAKE_PHOTO}`, async () => { - CreateMobilePhone(1); - CellCamActivate(true, true); +const displayHelperText = () => { + BeginTextCommandDisplayHelp('TWOSTRINGS'); + AddTextComponentString('Exit Camera Mode: ~INPUT_CELLPHONE_CANCEL~'); + AddTextComponentString('Toggle Front/Back: ~INPUT_PHONE~'); + EndTextCommandDisplayHelp(0, true, false, -1); +}; +RegisterNuiCallbackType(events.CAMERA_TAKE_PHOTO); +on(`__cfx_nui:${events.CAMERA_TAKE_PHOTO}`, async (data: any, cb: Function) => { + cb(); + // Create Phone Prop + CreateMobilePhone(1); + // Active Camera Change + CellCamActivate(true, true); + // Hide phone from rendering temporary closePhoneTemp(); + SetNuiFocus(false, false); - takingPhoto = true; + inCameraMode = true; - while (takingPhoto) { + while (inCameraMode) { await Delay(0); let frontCam = false; - + displayHelperText(); if (IsControlJustPressed(1, 27)) { - if (!frontCam) { - frontCam = true; - CellFrontCamActivate(true); - } else { - frontCam = false; - CellFrontCamActivate(false); - } + frontCam = !frontCam; + CellFrontCamActivate(frontCam); } else if (IsControlJustPressed(1, 176)) { - takePhoto(); - await Delay(200); - console.log('phone closing'); - DestroyMobilePhone(); - CellCamActivate(false, false); - - openPhoneTemp(); - SetNuiFocus(true, true); - - takingPhoto = false; + await handleTakePicture(); } else if (IsControlJustPressed(1, 177)) { - DestroyMobilePhone(); - CellCamActivate(false, false); - - openPhoneTemp(); - SetNuiFocus(true, true); - - takingPhoto = false; + handleCameraExit(); break; } } + ClearHelp(true); }); -//setTick(async () => { -// while (takingPhoto) { -// await Delay(0); -// -// if (IsControlReleased(1, 177)) { -// DestroyMobilePhone(); -// CellCamActivate(false, false); -// takingPhoto = false; -// SetNuiFocus(true, true); -// break; -// } -// } -//}) +const handleTakePicture = async () => { + takePhoto(); + await Delay(200); + DestroyMobilePhone(); + CellCamActivate(false, false); + openPhoneTemp(); + inCameraMode = false; +}; + +const handleCameraExit = () => { + DestroyMobilePhone(); + CellCamActivate(false, false); + openPhoneTemp(); + inCameraMode = false; +}; onNet(events.CAMERA_SEND_PHOTOS, (photos: string[]) => { - console.log(photos); + // console.log(photos); SendNuiMessage( JSON.stringify({ app: 'CAMERA', @@ -104,7 +100,6 @@ onNet(events.CAMERA_SEND_PHOTOS, (photos: string[]) => { }); function takePhoto() { - const [width, height] = GetActiveScreenResolution(); // Return and log error if screenshot basic token not found if (SCREENSHOT_BASIC_TOKEN === 'none') { return console.error( @@ -129,13 +124,14 @@ function takePhoto() { onNet(events.CAMERA_UPLOAD_PHOTO_SUCCESS, () => { emitNet(events.CAMERA_FETCH_PHOTOS); -}) +}); // delete photo RegisterNuiCallbackType(events.CAMERA_DELETE_PHOTO); -on(`__cfx_nui:${events.CAMERA_DELETE_PHOTO}`, (data: any) => { +on(`__cfx_nui:${events.CAMERA_DELETE_PHOTO}`, (data: any, cb: Function) => { emitNet(events.CAMERA_DELETE_PHOTO, data); + cb(); }); onNet(events.CAMERA_DELETE_PHOTO_SUCCESS, () => { From 47e1f2950ef5a2af1445c71e566479723e225323 Mon Sep 17 00:00:00 2001 From: Taso Date: Tue, 9 Feb 2021 18:43:54 -0500 Subject: [PATCH 07/30] fix(scripts/nui-callbacks): Fixed NUI callback stalls --- resources/client/cl_bank.ts | 6 +++--- resources/client/cl_call.ts | 13 ++++++++----- resources/client/cl_contacts.ts | 17 +++++++++-------- resources/client/cl_main.ts | 21 ++++++++++++++------- resources/client/cl_messages.ts | 16 +++++++++++----- 5 files changed, 45 insertions(+), 28 deletions(-) diff --git a/resources/client/cl_bank.ts b/resources/client/cl_bank.ts index 2657cc7..3bf7d6f 100644 --- a/resources/client/cl_bank.ts +++ b/resources/client/cl_bank.ts @@ -21,9 +21,9 @@ onNet(events.BANK_SEND_CREDENTIALS, (credentials: any) => { }); RegisterNuiCallbackType(events.BANK_ADD_TRANSFER); -on(`__cfx_nui:${events.BANK_ADD_TRANSFER}`, (data: any) => { - const transfer = data; - emitNet(events.BANK_ADD_TRANSFER, transfer); +on(`__cfx_nui:${events.BANK_ADD_TRANSFER}`, (data: any, cb: Function) => { + emitNet(events.BANK_ADD_TRANSFER, data); + cb(); }); onNet(events.BANK_ADD_TRANSFER_SUCCESS, () => { diff --git a/resources/client/cl_call.ts b/resources/client/cl_call.ts index b066904..2e58fa7 100644 --- a/resources/client/cl_call.ts +++ b/resources/client/cl_call.ts @@ -4,10 +4,10 @@ import { ICall } from '../../phone/src/common/typings/call'; const exp = (global as any).exports; RegisterNuiCallbackType(events.PHONE_INITIALIZE_CALL); -on(`__cfx_nui:${events.PHONE_INITIALIZE_CALL}`, (data: any) => { +on(`__cfx_nui:${events.PHONE_INITIALIZE_CALL}`, (data: any, cb: Function) => { const start = Date.now(); - emitNet(events.PHONE_INITIALIZE_CALL, data.number, start); + cb(); }); onNet( @@ -31,8 +31,9 @@ onNet( ); RegisterNuiCallbackType(events.PHONE_ACCEPT_CALL); -on(`__cfx_nui:${events.PHONE_ACCEPT_CALL}`, (data: any) => { +on(`__cfx_nui:${events.PHONE_ACCEPT_CALL}`, (data: any, cb: Function) => { emitNet(events.PHONE_ACCEPT_CALL, data.transmitterNumber); + cb(); }); onNet( @@ -56,9 +57,10 @@ onNet( ); RegisterNuiCallbackType(events.PHONE_CALL_REJECTED); -on(`__cfx_nui:${events.PHONE_CALL_REJECTED}`, (data: any) => { +on(`__cfx_nui:${events.PHONE_CALL_REJECTED}`, (data: any, cb: Function) => { const end = Date.now(); emitNet(events.PHONE_CALL_REJECTED, data.transmitterNumber, end); + cb(); }); onNet(events.PHONE_CALL_WAS_REJECTED, () => { @@ -79,9 +81,10 @@ onNet(events.PHONE_CALL_WAS_REJECTED, () => { }); RegisterNuiCallbackType(events.PHONE_END_CALL); -on(`__cfx_nui:${events.PHONE_END_CALL}`, (data: any) => { +on(`__cfx_nui:${events.PHONE_END_CALL}`, (data: any, cb: Function) => { const end = Date.now(); emitNet(events.PHONE_END_CALL, data.transmitterNumber, end); + cb(); }); onNet(events.PHONE_CALL_WAS_ENDED, () => { diff --git a/resources/client/cl_contacts.ts b/resources/client/cl_contacts.ts index 5177bbd..3f1cbe0 100644 --- a/resources/client/cl_contacts.ts +++ b/resources/client/cl_contacts.ts @@ -11,11 +11,12 @@ onNet(events.CONTACTS_SEND_CONTACTS, (contacts: any) => { }); RegisterNuiCallbackType(events.CONTACTS_ADD_CONTACT); -on(`__cfx_nui:${events.CONTACTS_ADD_CONTACT}`, (data: any) => { +on(`__cfx_nui:${events.CONTACTS_ADD_CONTACT}`, (data: any, cb: Function) => { const display = data.name; const number = data.number; const avatar = data.avatar; emitNet(events.CONTACTS_ADD_CONTACT, number, display, avatar); + cb(); }); onNet(events.CONTACTS_ADD_CONTACT_SUCCESS, () => { @@ -23,20 +24,20 @@ onNet(events.CONTACTS_ADD_CONTACT_SUCCESS, () => { }); RegisterNuiCallbackType(events.CONTACTS_UPDATE_CONTACT); -on(`__cfx_nui:${events.CONTACTS_UPDATE_CONTACT}`, (data: any) => { - const contact = data; - emitNet(events.CONTACTS_UPDATE_CONTACT, contact); +on(`__cfx_nui:${events.CONTACTS_UPDATE_CONTACT}`, (data: any, cb: Function) => { + emitNet(events.CONTACTS_UPDATE_CONTACT, data); + cb(); }); onNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, () => { emitNet(events.CONTACTS_GET_CONTACTS); - console.log("did you update the contact??????????????????"); + console.log('did you update the contact??????????????????'); }); RegisterNuiCallbackType(events.CONTACTS_DELETE_CONTACT); -on(`__cfx_nui:${events.CONTACTS_DELETE_CONTACT}`, (data: any) => { - const contact = data; - emitNet(events.CONTACTS_DELETE_CONTACT, contact); +on(`__cfx_nui:${events.CONTACTS_DELETE_CONTACT}`, (data: any, cb: Function) => { + emitNet(events.CONTACTS_DELETE_CONTACT, data); + cb(); }); onNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, () => { diff --git a/resources/client/cl_main.ts b/resources/client/cl_main.ts index c99da94..ec9fd7c 100644 --- a/resources/client/cl_main.ts +++ b/resources/client/cl_main.ts @@ -326,35 +326,41 @@ async function Phone() { // contacts app RegisterNuiCallbackType(events.OPEN_APP_CONTACTS); -on(`__cfx_nui:${events.OPEN_APP_CONTACTS}`, () => { +on(`__cfx_nui:${events.OPEN_APP_CONTACTS}`, (data: any, cb: Function) => { emitNet(events.CONTACTS_GET_CONTACTS); + cb(); }); RegisterNuiCallbackType(events.OPEN_APP_LISTINGS); -on(`__cfx_nui:${events.OPEN_APP_LISTINGS}`, () => { +on(`__cfx_nui:${events.OPEN_APP_LISTINGS}`, (data: any, cb: Function) => { emitNet(events.SELLOUT_FETCH_LISTING); + cb(); }); RegisterNuiCallbackType(events.OPEN_APP_NOTES); -on(`__cfx_nui:${events.OPEN_APP_NOTES}`, () => { +on(`__cfx_nui:${events.OPEN_APP_NOTES}`, (data: any, cb: Function) => { emitNet(events.NOTE_FETCH_ALL_NOTES); + cb(); }); RegisterNuiCallbackType(events.OPEN_APP_BANK); -on(`__cfx_nui:${events.OPEN_APP_BANK}`, () => { +on(`__cfx_nui:${events.OPEN_APP_BANK}`, (data: any, cb: Function) => { emitNet(events.BANK_FETCH_TRANSACTIONS); emitNet(events.BANK_GET_CREDENTIALS); + cb(); }); RegisterNuiCallbackType(events.OPEN_APP_CAMERA); -on(`__cfx_nui:${events.OPEN_APP_CAMERA}`, () => { +on(`__cfx_nui:${events.OPEN_APP_CAMERA}`, (data: any, cb: Function) => { emitNet(events.CAMERA_FETCH_PHOTOS); + cb(); }); RegisterNuiCallbackType(events.OPEN_APP_DAILER); -on(`__cfx_nui:${events.OPEN_APP_DAILER}`, () => { +on(`__cfx_nui:${events.OPEN_APP_DAILER}`, (data: any, cb: Function) => { emitNet(events.CONTACTS_GET_CONTACTS); emitNet(events.PHONE_CALL_FETCH_CALLS); + cb(); }); RegisterCommand( @@ -367,8 +373,9 @@ RegisterCommand( ); RegisterNuiCallbackType('phone:close'); -on(`__cfx_nui:phone:close`, () => { +on(`__cfx_nui:phone:close`, (data: any, cb: Function) => { Phone(); + cb(); }); // Called for when the phone is closed via the UI. AddEventHandler('onResourceStop', function (resource: string) { diff --git a/resources/client/cl_messages.ts b/resources/client/cl_messages.ts index 9fbb212..68b9cd2 100644 --- a/resources/client/cl_messages.ts +++ b/resources/client/cl_messages.ts @@ -34,8 +34,9 @@ emitNet(events.MESSAGES_FETCH_MESSAGE_GROUPS); RegisterNuiCallbackType(events.MESSAGES_CREATE_MESSAGE_GROUP); on( `__cfx_nui:${events.MESSAGES_CREATE_MESSAGE_GROUP}`, - ({ phoneNumbers, label }: any): void => { + ({ phoneNumbers, label }: any, cb: Function): void => { emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP, phoneNumbers, label); + cb(); } ); @@ -52,9 +53,13 @@ onNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, (result: any): void => { * Messages fetch messages */ RegisterNuiCallbackType(events.MESSAGES_FETCH_MESSAGES); -on(`__cfx_nui:${events.MESSAGES_FETCH_MESSAGES}`, ({ groupId }: any): void => { - emitNet(events.MESSAGES_FETCH_MESSAGES, groupId); -}); +on( + `__cfx_nui:${events.MESSAGES_FETCH_MESSAGES}`, + ({ groupId }: any, cb: Function): void => { + emitNet(events.MESSAGES_FETCH_MESSAGES, groupId); + cb(); + } +); onNet(events.MESSAGES_FETCH_MESSAGES_SUCCESS, (messages: Message[]): void => { sendMessageEvent(events.MESSAGES_FETCH_MESSAGES_SUCCESS, messages); @@ -68,8 +73,9 @@ onNet(events.MESSAGES_FETCH_MESSAGES_FAILED, (): void => { * Messages send message */ RegisterNuiCallbackType(events.MESSAGES_SEND_MESSAGE); -on(`__cfx_nui:${events.MESSAGES_SEND_MESSAGE}`, (data: any) => { +on(`__cfx_nui:${events.MESSAGES_SEND_MESSAGE}`, (data: any, cb: Function) => { emitNet(events.MESSAGES_SEND_MESSAGE, data.groupId, data.message); + cb(); }); onNet(events.MESSAGES_SEND_MESSAGE_SUCCESS, (groupId: string) => { From 368a8c57f851daff2be9e0334a063e498727026f Mon Sep 17 00:00:00 2001 From: Taso Date: Tue, 9 Feb 2021 18:45:48 -0500 Subject: [PATCH 08/30] optimize(scripts/anims): Optimized and organized open/close animations --- resources/client/cl_main.ts | 179 +++++++++++++++++------------------- 1 file changed, 83 insertions(+), 96 deletions(-) diff --git a/resources/client/cl_main.ts b/resources/client/cl_main.ts index ec9fd7c..bfd9189 100644 --- a/resources/client/cl_main.ts +++ b/resources/client/cl_main.ts @@ -29,9 +29,9 @@ const newPhoneProp = async () => { deletePhone(); //deletes the already existing prop before creating another. if (!propCreated) { RequestModel(phoneModel); + while (!HasModelLoaded(phoneModel)) { await Delay(1); - console.log('MODEL HASNT LOADED'); } const playerPed = PlayerPedId(); @@ -78,7 +78,6 @@ function deletePhone() { DeleteEntity(prop); prop = 0; propCreated = false; - console.log('prop destroyed'); } } @@ -90,108 +89,96 @@ async function loadAnimDict(dict: any) { } } -async function phoneOpenAnim() { - //Phone Open Animation +const handleOpenVehicleAnim = async (playerPed: number): Promise => { + const dict = 'anim@cellphone@in_car@ps'; + + ClearPedTasks(playerPed); + await loadAnimDict(dict); + TaskPlayAnim( + playerPed, + dict, + 'cellphone_text_in', + 8.0, + -1, + -1, + 50, + 0, + false, + false, + false + ); + await Delay(300); //Gives time for animation starts before creating the phone + await newPhoneProp(); //Creates the phone and attaches it. +}; + +const handleOpenNormalAnim = async (playerPed: number): Promise => { + //While not in a vehicle it will use this dict. + const dict = 'cellphone@'; + + ClearPedTasks(playerPed); + await loadAnimDict(dict); + TaskPlayAnim( + playerPed, + dict, + 'cellphone_text_in', + 8.0, + -1, + -1, + 50, + 0, + false, + false, + false + ); + await Delay(300); //Gives time for animation starts before creating the phone + await newPhoneProp(); //Creates the phone and attaches it. +}; + +const handleCloseVehicleAnim = async (playerPed: number): Promise => { + //true refers to at get in. + const DICT = 'anim@cellphone@in_car@ps'; + const ANIM = 'cellphone_text_out'; + + StopAnimTask(playerPed, DICT, 'cellphone_text_in', 1.0); //Stop the pull out animation + deletePhone(); //Deletes the prop early incase they get out of the vehicle. + await Delay(250); //lets it get to a certain point + await loadAnimDict(DICT); //loads the new animation + TaskPlayAnim(playerPed, DICT, ANIM, 8.0, -1, -1, 50, 0, false, false, false); //puts phone into pocket + await Delay(200); //waits until the phone is in the pocket + StopAnimTask(playerPed, DICT, ANIM, 1.0); //clears the animation +}; + +const handleCloseNormalAnim = async (playerPed: number): Promise => { + const DICT = 'cellphone@'; + const ANIM = 'cellphone_text_out'; + StopAnimTask(playerPed, DICT, 'cellphone_text_in', 1.0); //Stop the pull out animation + await Delay(100); //lets it get to a certain point + await loadAnimDict(DICT); //loads the new animation + TaskPlayAnim(playerPed, DICT, ANIM, 8.0, -1, -1, 50, 0, false, false, false); //puts phone into pocket + await Delay(200); //waits until the phone is in the pocket + StopAnimTask(playerPed, DICT, ANIM, 1.0); //clears the animation + deletePhone(); //Deletes the prop. +}; + +// Determines the phoneOpen animation to play +async function phoneOpenAnim(): Promise { + const playerPed = PlayerPedId(); console.log('phoneOpenAnim'); //Left for testing purposes. - const flag = 50; //https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94 deletePhone(); //Deleting before creating a new phone where itll be deleted again. - if (IsPedInAnyVehicle(GetPlayerPed(-1), true)) { - //-- true refers to at get in. - const dict = 'anim@cellphone@in_car@ps'; - - ClearPedTasks(GetPlayerPed(-1)); - await loadAnimDict(dict); - TaskPlayAnim( - GetPlayerPed(-1), - dict, - 'cellphone_text_in', - 8.0, - -1, - -1, - flag, - 0, - false, - false, - false - ); - await Delay(300); //Gives time for animation starts before creating the phone - await newPhoneProp(); //Creates the phone and attaches it. - } else { - //While not in a vehicle it will use this dict. - const dict = 'cellphone@'; - - ClearPedTasks(GetPlayerPed(-1)); - await loadAnimDict(dict); - TaskPlayAnim( - GetPlayerPed(-1), - dict, - 'cellphone_text_in', - 8.0, - -1, - -1, - flag, - 0, - false, - false, - false - ); - await Delay(300); //Gives time for animation starts before creating the phone - await newPhoneProp(); //Creates the phone and attaches it. + if (IsPedInAnyVehicle(playerPed, true)) { + return await handleOpenVehicleAnim(playerPed); } + return await handleOpenNormalAnim(playerPed); } +// Determines the phoneClose animation to play async function phoneCloseAnim() { - //Phone Close Animation + const playerPed = PlayerPedId(); console.log('phoneCloseAnim'); //Left for testing purposes. - const flag = 50; //https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94 - const anim = 'cellphone_text_out'; - if (IsPedInAnyVehicle(GetPlayerPed(-1), true)) { - //true refers to at get in. - const dict = 'anim@cellphone@in_car@ps'; - - StopAnimTask(GetPlayerPed(-1), dict, 'cellphone_text_in', 1.0); //Stop the pull out animation - deletePhone(); //Deletes the prop early incase they get out of the vehicle. - await Delay(250); //lets it get to a certain point - loadAnimDict(dict); //loads the new animation - TaskPlayAnim( - GetPlayerPed(-1), - dict, - anim, - 8.0, - -1, - -1, - flag, - 0, - false, - false, - false - ); //puts phone into pocket - await Delay(200); //waits until the phone is in the pocket - StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0); //clears the animation - } else { - //While not in a vehicle it will use this dict. - const dict = 'cellphone@'; - - StopAnimTask(GetPlayerPed(-1), dict, 'cellphone_text_in', 1.0); //Stop the pull out animation - await Delay(100); //lets it get to a certain point - loadAnimDict(dict); //loads the new animation - TaskPlayAnim( - GetPlayerPed(-1), - dict, - anim, - 8.0, - -1, - -1, - flag, - 0, - false, - false, - false - ); //puts phone into pocket - await Delay(200); //waits until the phone is in the pocket - StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0); //clears the animation - deletePhone(); //Deletes the prop. + if (IsPedInAnyVehicle(playerPed, true)) { + return await handleCloseVehicleAnim(playerPed); } + await handleCloseNormalAnim(playerPed); } async function carryingPhone(cb: any) { From 81f5e270643001d85fa7f0e3d72a3542e2eccb5e Mon Sep 17 00:00:00 2001 From: J Francisco Rader Date: Wed, 10 Feb 2021 12:04:28 -0500 Subject: [PATCH 09/30] Remove client phoneConfig event (#73) * Remove client phoneConfig event * Remove unused debug * Remove unused import * Remove unused import * Remove duplicated functions | fix useEffect dependency | etc * Fix warnings * Update phone/src/apps/twitter/components/TwitterApp.tsx Co-authored-by: Taso Co-authored-by: Taso --- phone/package.json | 5 +- phone/src/Phone.tsx | 55 +++---------------- .../camera/components/grid/GalleryGrid.tsx | 2 +- phone/src/apps/notes/modal/NoteModal.tsx | 2 +- .../twitter/components/images/ImagePrompt.tsx | 9 ++- .../apps/twitter/hooks/useTwitterService.ts | 11 +--- phone/src/common/typings/config.ts | 2 +- phone/src/config.autogen.json | 33 +++++++++++ phone/src/os/apps/hooks/useApps.tsx | 2 +- phone/src/os/phone/hooks/usePhone.ts | 8 +-- phone/src/ui/components/AppIcon.tsx | 1 - resources/client/cl_main.ts | 12 ---- 12 files changed, 61 insertions(+), 81 deletions(-) create mode 100644 phone/src/config.autogen.json diff --git a/phone/package.json b/phone/package.json index 834dbe5..02eeb07 100644 --- a/phone/package.json +++ b/phone/package.json @@ -75,10 +75,11 @@ "webpack-cli": "^3.3.12" }, "scripts": { - "start": "react-scripts start", + "copy:config": "cp ../config.json ./src/config.autogen.json", + "start": "yarn copy:config && react-scripts start", "watch": "cra-build-watch --disable-chunks --build-path ../resources/html --output-filename dev.js", "format": "prettier --write src/**/*.{js,jsx,ts,tsx,json,css,scss,md}", - "build": "cross-env NODE_ENV=production webpack --config webpack/webpack.resources.js --color -p --progress --hide-modules --display-optimization-bailout", + "build": "yarn copy:config && cross-env NODE_ENV=production webpack --config webpack/webpack.resources.js --color -p --progress --hide-modules --display-optimization-bailout", "test": "react-scripts test --watchAll=false --testMatch **/src/**/*.test.{ts,js,tsx}", "test:watch": "react-scripts test --watchAll --testMatch **/src/**/*.test.{ts,js,tsx}", "eject": "react-scripts eject", diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index 547f0c0..ebcbf47 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -1,7 +1,7 @@ import React, { useMemo } from 'react'; import './Phone.css'; import './i18n'; -import { Route, useHistory } from 'react-router-dom'; +import { Route } from 'react-router-dom'; import { CallModal } from './modal/components/CallModal'; import { HomeApp } from './apps/home/components/Home'; import { createMuiTheme, ThemeProvider } from '@material-ui/core'; @@ -33,51 +33,6 @@ import { useDialService } from './apps/dialer/hooks/useDialService'; import InjectDebugData from './os/debug/InjectDebugData'; import { useQuickAccess } from './os/notifications/hooks/useQuickAccess'; -InjectDebugData([ - { - app: 'PHONE', - method: 'phoneConfig', - data: { - Locale: 'en', - KeyTogglePhone: 288, - KeyTakeCall: 38, - PhoneAsItem: false, - SwimDestroy: false, - RunRate: 10, - DestoryChance: 100, - DestroyPhoneReCheck: 3, - notificationPosition: { - horizontal: 'right', - vertical: 'top', - }, - general: { - useDashNumber: true, - }, - twitter: { - showNotifications: true, - generateProfileNameFromUsers: true, - allowEdtiableProfileName: true, - allowDeleteTweets: true, - allowReportTweets: true, - characterLimit: 160, - newLineLimit: 10, - enableAvatars: true, - enableEmojis: true, - enableImages: true, - maxImages: 3, - }, - bank: { - showNotifications: true, - }, - }, - }, - { - app: 'PHONE', - method: 'setVisibility', - data: true, - }, -]); - function Phone() { const quickAccess = useQuickAccess(); useNuiService(); @@ -173,3 +128,11 @@ function Phone() { } export default Phone; + +InjectDebugData([ + { + app: 'PHONE', + method: 'setVisibility', + data: true, + }, +]); diff --git a/phone/src/apps/camera/components/grid/GalleryGrid.tsx b/phone/src/apps/camera/components/grid/GalleryGrid.tsx index 8cee9b5..b18d049 100644 --- a/phone/src/apps/camera/components/grid/GalleryGrid.tsx +++ b/phone/src/apps/camera/components/grid/GalleryGrid.tsx @@ -1,4 +1,4 @@ -import React, {useEffect} from 'react'; +import React from 'react'; import { Box, Button } from '@material-ui/core'; import useStyles from './grid.styles'; import { usePhotos } from '../../hooks/usePhotos'; diff --git a/phone/src/apps/notes/modal/NoteModal.tsx b/phone/src/apps/notes/modal/NoteModal.tsx index 7867d2a..08d099e 100644 --- a/phone/src/apps/notes/modal/NoteModal.tsx +++ b/phone/src/apps/notes/modal/NoteModal.tsx @@ -1,5 +1,5 @@ import { Button, TextField, Slide } from '@material-ui/core'; -import React, { useState, useEffect } from 'react'; +import React, { useState } from 'react'; import ArrowBackIcon from '@material-ui/icons/ArrowBack'; import { useNoteModal } from '../hooks/useNoteModal'; diff --git a/phone/src/apps/twitter/components/images/ImagePrompt.tsx b/phone/src/apps/twitter/components/images/ImagePrompt.tsx index 8ad2db9..a1b8001 100644 --- a/phone/src/apps/twitter/components/images/ImagePrompt.tsx +++ b/phone/src/apps/twitter/components/images/ImagePrompt.tsx @@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next'; import { makeStyles } from '@material-ui/core/styles'; import { TextField } from '@material-ui/core'; -const useStyles = makeStyles((theme) => ({ +const useStyles = makeStyles({ textField: { flex: '1 1 100%', padding: '10px 15px', @@ -12,7 +12,7 @@ const useStyles = makeStyles((theme) => ({ textFieldInput: { fontSize: '22px', }, -})); +}); export const ImagePrompt = ({ visible, value, handleChange }) => { const textFieldRef = useRef(null); @@ -23,7 +23,10 @@ export const ImagePrompt = ({ visible, value, handleChange }) => { textFieldRef.current && textFieldRef.current.focus(); }, [visible]); - const handleImageChange = useCallback(e => handleChange(e.target.value), []); + const handleImageChange = useCallback( + (e) => handleChange(e.target.value), + [handleChange] + ); if (!visible) return null; return ( diff --git a/phone/src/apps/twitter/hooks/useTwitterService.ts b/phone/src/apps/twitter/hooks/useTwitterService.ts index 8b794c9..0af8c1e 100644 --- a/phone/src/apps/twitter/hooks/useTwitterService.ts +++ b/phone/src/apps/twitter/hooks/useTwitterService.ts @@ -43,9 +43,6 @@ export const useTwitterService = () => { ); const setNotification = useSetRecoilState(twitterState.notification); - const _setProfile = (profile) => { - setProfile(profile); - }; const _setUpdateProfileSuccess = (isSuccessful) => { setUpdateProfileSuccess(isSuccessful); setUpdateProfileLoading(false); // on any result we should set loading to false @@ -56,10 +53,6 @@ export const useTwitterService = () => { setCreateLoading(false); }; - const _setNotification = (tweet) => { - setNotification(tweet); - }; - const _setTweets = (tweets) => { setTweets(tweets.map(processTweet)); }; @@ -67,12 +60,12 @@ export const useTwitterService = () => { setFilteredTweets(tweets.map(processTweet)); }; - useNuiEvent(APP_TWITTER, 'getOrCreateTwitterProfile', _setProfile); + useNuiEvent(APP_TWITTER, 'getOrCreateTwitterProfile', setProfile); useNuiEvent(APP_TWITTER, 'updateProfileLoading', setUpdateProfileLoading); useNuiEvent(APP_TWITTER, 'updateProfileResult', _setUpdateProfileSuccess); useNuiEvent(APP_TWITTER, 'fetchTweets', _setTweets); useNuiEvent(APP_TWITTER, 'fetchTweetsFiltered', _setFilteredTweets); useNuiEvent(APP_TWITTER, 'createTweetLoading', setCreateLoading); useNuiEvent(APP_TWITTER, 'createTweetResult', _setCreateSuccess); - useNuiEvent(APP_TWITTER, 'createTweetBroadcast', _setNotification); + useNuiEvent(APP_TWITTER, 'createTweetBroadcast', setNotification); }; diff --git a/phone/src/common/typings/config.ts b/phone/src/common/typings/config.ts index 847d338..3ff10c3 100644 --- a/phone/src/common/typings/config.ts +++ b/phone/src/common/typings/config.ts @@ -25,7 +25,7 @@ interface BankConfig { showNotifications: boolean; } -export interface ServerConfig { +export interface IServerConfig { Locale: string; KeyTogglePhone: number; KeyTakeCall: number; diff --git a/phone/src/config.autogen.json b/phone/src/config.autogen.json new file mode 100644 index 0000000..49e47a6 --- /dev/null +++ b/phone/src/config.autogen.json @@ -0,0 +1,33 @@ +{ + "Locale": "en", + "KeyTogglePhone": 288, + "KeyTakeCall": 38, + "PhoneAsItem": false, + "SwimDestroy": false, + "RunRate": 10, + "DestoryChance": 100, + "DestroyPhoneReCheck": 3, + "notificationPosition": { + "horizontal": "right", + "vertical": "top" + }, + "general": { + "useDashNumber": true + }, + "twitter": { + "showNotifications": true, + "generateProfileNameFromUsers": true, + "allowEdtiableProfileName": true, + "allowDeleteTweets": true, + "allowReportTweets": true, + "characterLimit": 160, + "newLineLimit": 10, + "enableAvatars": true, + "enableEmojis": true, + "enableImages": true, + "maxImages": 3 + }, + "bank": { + "showNotifications": true + } + } \ No newline at end of file diff --git a/phone/src/os/apps/hooks/useApps.tsx b/phone/src/os/apps/hooks/useApps.tsx index 28d319d..fdfbe24 100644 --- a/phone/src/os/apps/hooks/useApps.tsx +++ b/phone/src/os/apps/hooks/useApps.tsx @@ -55,7 +55,7 @@ type AppsRepository = { preinstalled: IAppConfig[] }; const AppWithStartup = ({ children, id }) => { useEffect(() => { Nui.send(`phone:app:${id}`); - }, []); + }, [id]); return children; }; diff --git a/phone/src/os/phone/hooks/usePhone.ts b/phone/src/os/phone/hooks/usePhone.ts index 42dff45..675944e 100644 --- a/phone/src/os/phone/hooks/usePhone.ts +++ b/phone/src/os/phone/hooks/usePhone.ts @@ -1,14 +1,14 @@ import { useRecoilValue } from 'recoil'; import { phoneState } from './state'; -import { ServerConfig } from '../../../common/typings/config'; +import { IServerConfig } from '../../../common/typings/config'; +import ServerConfig from '../../../config.autogen.json'; interface IUsePhone { visibility: boolean; - config?: ServerConfig; + config?: IServerConfig; } export const usePhone = (): IUsePhone => { const visibility = useRecoilValue(phoneState.visibility); - const config = useRecoilValue(phoneState.phoneConfig); - return { visibility, config }; + return { visibility, config: ServerConfig as any }; }; diff --git a/phone/src/ui/components/AppIcon.tsx b/phone/src/ui/components/AppIcon.tsx index 5bc7fae..1504d52 100644 --- a/phone/src/ui/components/AppIcon.tsx +++ b/phone/src/ui/components/AppIcon.tsx @@ -3,7 +3,6 @@ import { makeStyles } from '@material-ui/core/styles'; import Avatar from '@material-ui/core/Avatar'; import { green } from '@material-ui/core/colors'; import { Button } from '@material-ui/core'; -import Nui from '../../os/nui-events/utils/Nui'; interface IStyles { root: any; diff --git a/resources/client/cl_main.ts b/resources/client/cl_main.ts index c99da94..17b94ea 100644 --- a/resources/client/cl_main.ts +++ b/resources/client/cl_main.ts @@ -210,16 +210,6 @@ function noPhone() { ESX.ShowNotification('Oi Mate, No El Telephono', false, false, 1); } -function sendPhoneConfig() { - SendNuiMessage( - JSON.stringify({ - app: 'PHONE', - method: 'phoneConfig', - data: config, - }) - ); -} - setTick(() => { if (IsControlJustPressed(1, config.KeyTogglePhone)) { Phone(); @@ -263,7 +253,6 @@ async function Phone() { data: true, }) ); - sendPhoneConfig(); SetNuiFocus(true, true); //SetNuiFocusKeepInput(true) } else { @@ -301,7 +290,6 @@ async function Phone() { data: true, }) ); - sendPhoneConfig(); SetNuiFocus(true, true); //SetNuiFocusKeepInput(true) } else { From f0a2d8c77edb49e114f7789dda70ec4d165636ff Mon Sep 17 00:00:00 2001 From: Taso Date: Wed, 10 Feb 2021 14:25:00 -0500 Subject: [PATCH 10/30] refactor(phone/visibility): Improved organization of visibility flow --- resources/client/cl_main.ts | 319 ++++++++++++++++-------------------- 1 file changed, 139 insertions(+), 180 deletions(-) diff --git a/resources/client/cl_main.ts b/resources/client/cl_main.ts index bfd9189..112b1b4 100644 --- a/resources/client/cl_main.ts +++ b/resources/client/cl_main.ts @@ -1,12 +1,22 @@ -import { ESX } from '../client/client'; import config from '../utils/config'; import { Delay } from '../utils/fivem'; import events from '../utils/events'; +let prop = 0; +let isPhoneOpen = false; +let propCreated = false; +let phoneModel = 'prop_amb_phone'; // Refered to in newphoneProp function. Requires custom phone being streamed. + +/* * * * * * * * * * * * * + * + * Register Command and Keybinding + * + * * * * * * * * * * * * */ + RegisterCommand( 'phone:close', - (source: any, args: string[], raw: any) => { - phoneCloseAnim(); + async (source: any, args: string[], raw: any) => { + await phoneCloseAnim(); SetNuiFocus(false, false); SendNuiMessage( JSON.stringify({ @@ -19,14 +29,33 @@ RegisterCommand( false ); -let prop = 0; -let isPhoneOpen = false; -let propCreated = false; -let phoneModel = 'prop_amb_phone'; // Refered to in newphoneProp function. Requires custom phone being streamed. +RegisterCommand( + '+phone', + async () => { + //-- Toggles Phone + await Phone(); + }, + false +); + +RegisterCommand( + 'phone:open', + async () => { + await Phone(); + }, + false +); + +RegisterKeyMapping('+phone', 'Open Phone', 'keyboard', 'f1'); + +/* * * * * * * * * * * * * + * + * Prop Deletion/Creation handling + * + * * * * * * * * * * * * */ const newPhoneProp = async () => { - //Function for creating the phone prop - deletePhone(); //deletes the already existing prop before creating another. + removePhoneProp(); //deletes the already existing prop before creating another. if (!propCreated) { RequestModel(phoneModel); @@ -71,7 +100,7 @@ const newPhoneProp = async () => { } }; -function deletePhone() { +function removePhoneProp() { //-- Triggered in newphoneProp function. Only way to destory the prop correctly. if (prop != 0) { //Citizen.invokeNative(0xAE3CBE5BF394C9C9 , Citizen.pointerValueIntInitialized(prop)) @@ -89,6 +118,12 @@ async function loadAnimDict(dict: any) { } } +/* * * * * * * * * * * * * + * + * Animations + * + * * * * * * * * * * * * */ + const handleOpenVehicleAnim = async (playerPed: number): Promise => { const dict = 'anim@cellphone@in_car@ps'; @@ -140,7 +175,7 @@ const handleCloseVehicleAnim = async (playerPed: number): Promise => { const ANIM = 'cellphone_text_out'; StopAnimTask(playerPed, DICT, 'cellphone_text_in', 1.0); //Stop the pull out animation - deletePhone(); //Deletes the prop early incase they get out of the vehicle. + removePhoneProp(); //Deletes the prop early incase they get out of the vehicle. await Delay(250); //lets it get to a certain point await loadAnimDict(DICT); //loads the new animation TaskPlayAnim(playerPed, DICT, ANIM, 8.0, -1, -1, 50, 0, false, false, false); //puts phone into pocket @@ -157,44 +192,89 @@ const handleCloseNormalAnim = async (playerPed: number): Promise => { TaskPlayAnim(playerPed, DICT, ANIM, 8.0, -1, -1, 50, 0, false, false, false); //puts phone into pocket await Delay(200); //waits until the phone is in the pocket StopAnimTask(playerPed, DICT, ANIM, 1.0); //clears the animation - deletePhone(); //Deletes the prop. + removePhoneProp(); //Deletes the prop. }; -// Determines the phoneOpen animation to play async function phoneOpenAnim(): Promise { const playerPed = PlayerPedId(); - console.log('phoneOpenAnim'); //Left for testing purposes. - deletePhone(); //Deleting before creating a new phone where itll be deleted again. + removePhoneProp(); //Deleting before creating a new phone where itll be deleted again. if (IsPedInAnyVehicle(playerPed, true)) { return await handleOpenVehicleAnim(playerPed); } return await handleOpenNormalAnim(playerPed); } -// Determines the phoneClose animation to play async function phoneCloseAnim() { const playerPed = PlayerPedId(); - console.log('phoneCloseAnim'); //Left for testing purposes. if (IsPedInAnyVehicle(playerPed, true)) { return await handleCloseVehicleAnim(playerPed); } await handleCloseNormalAnim(playerPed); } -async function carryingPhone(cb: any) { - if (ESX === null) return cb(0); - ESX.TriggerServerCallback( - 'phone:getItemAmount', - (qtty: number) => { - cb(qtty > 0); - }, - 'phone' - ); -} +// setTick(() => { +// if (IsControlJustPressed(1, config.KeyTogglePhone)) { +// Phone(); +// } +// }); -function noPhone() { - if (ESX === null) return; - ESX.ShowNotification('Oi Mate, No El Telephono', false, false, 1); +/* * * * * * * * * * * * * + * + * Phone Visibility Handling + * + * * * * * * * * * * * * */ + +const showPhone = async (): Promise => { + isPhoneOpen = true; + await phoneOpenAnim(); // Animation starts before the phone is open + emitNet('phone:getCredentials'); + SetCursorLocation(0.9, 0.922); //Experimental + SendNuiMessage( + JSON.stringify({ + app: 'PHONE', + method: 'setVisibility', + data: true, + }) + ); + sendPhoneConfig(); + SetNuiFocus(true, true); +}; + +const hidePhone = async (): Promise => { + isPhoneOpen = false; + SendNuiMessage( + //Hides phone + JSON.stringify({ + app: 'PHONE', + method: 'setVisibility', + data: false, + }) + ); + SetNuiFocus(false, false); +}; + +const togglePhoneVisible = async (): Promise => { + if (isPhoneOpen) { + await hidePhone(); + } else { + await showPhone(); + } +}; + +/* * * * * * * * * * * * * + * + * Misc. Helper Functions + * + * * * * * * * * * * * * */ + +async function Phone(): Promise { + if (config.PhoneAsItem) { + // TODO: Do promise callback here + // const hasPhoneItem = await emitNetPromise('phone:hasPhoneItem') + // if (!hasPhoneItem) return + return await togglePhoneVisible(); + } + await togglePhoneVisible(); } function sendPhoneConfig() { @@ -207,110 +287,39 @@ function sendPhoneConfig() { ); } -setTick(() => { - if (IsControlJustPressed(1, config.KeyTogglePhone)) { - Phone(); +AddEventHandler('onResourceStop', function (resource: string) { + if (resource === GetCurrentResourceName()) { + SendNuiMessage( + JSON.stringify({ + app: 'PHONE', + method: 'setVisibility', + data: false, + }) + ); + SetNuiFocus(false, false); + removePhoneProp(); //Deletes the phone incase it was attached. + ClearPedTasks(PlayerPedId()); //Leave here until launch as it'll fix any stuck animations. } }); -// setTick(() => { -// if (isPhoneOpen) { -// DisableControlAction(0, 1, true) -// DisableControlAction(0, 2, true) -// DisableControlAction(0, 24, true) -// DisableControlAction(0, 257, true) -// DisableControlAction(0, 25, true) -// DisableControlAction(0, 263, true) -// } else { -// EnableControlAction(0, 1, true) -// EnableControlAction(0, 2, true) -// EnableControlAction(0, 24, true) -// EnableControlAction(0, 257, true) -// EnableControlAction(0, 25, true) -// EnableControlAction(0, 263, true) -// } -// }) - -async function Phone() { - if (config.PhoneAsItem) { - console.log('CONFIG ON'); - carryingPhone(async (carryingPhone: any) => { - if (carryingPhone) { - if (!isPhoneOpen) { - isPhoneOpen = true; - await phoneOpenAnim(); // Animation starts before the phone is open - emitNet('phone:getCredentials'); - console.log('Sellout fetched from client side'); // Gets the credentials. Will eventually most likely only get the phone number and name, idk. - SetCursorLocation(0.9, 0.922); //Experimental - let res = GetActiveScreenResolution(); - SendNuiMessage( - JSON.stringify({ - app: 'PHONE', - method: 'setVisibility', - data: true, - }) - ); - sendPhoneConfig(); - SetNuiFocus(true, true); - //SetNuiFocusKeepInput(true) - } else { - isPhoneOpen = false; - SendNuiMessage( - //Hides phone - JSON.stringify({ - app: 'PHONE', - method: 'setVisibility', - data: false, - }) - ); - SetNuiFocus(false, false); - //SetNuiFocusKeepInput(false) - - await phoneCloseAnim(); // Animation starts after the UI is closed. - } - } else { - noPhone(); - } - }); - } else if (!config.PhoneAsItem) { - console.log('CONFIG OFF'); - if (!isPhoneOpen) { - isPhoneOpen = true; - await phoneOpenAnim(); // Animation starts before the phone is open - emitNet('phone:getCredentials'); - console.log('Sellout fetched from client side'); - SetCursorLocation(0.936, 0.922); //Experimental - let res = GetActiveScreenResolution(); - SendNuiMessage( - JSON.stringify({ - app: 'PHONE', - method: 'setVisibility', - data: true, - }) - ); - sendPhoneConfig(); - SetNuiFocus(true, true); - //SetNuiFocusKeepInput(true) - } else { - isPhoneOpen = false; - SendNuiMessage( - //Hides phone - JSON.stringify({ - app: 'PHONE', - method: 'setVisibility', - data: false, - }) - ); - SetNuiFocus(false, false); - //SetNuiFocusKeepInput(false) - - await phoneCloseAnim(); // Animation starts after the UI is closed. - } - } -} +onNet('phone:sendCredentials', (number: string) => { + SendNuiMessage( + JSON.stringify({ + app: 'SIMCARD', + method: 'setNumber', + data: number, + }) + ); +}); // DO NOT CHANGE THIS EITHER, PLEASE - CHIP +/* * * * * * * * * * * * * + * + * NUI Service Callback Registration + * + * * * * * * * * * * * * */ + // contacts app RegisterNuiCallbackType(events.OPEN_APP_CONTACTS); on(`__cfx_nui:${events.OPEN_APP_CONTACTS}`, (data: any, cb: Function) => { @@ -350,52 +359,12 @@ on(`__cfx_nui:${events.OPEN_APP_DAILER}`, (data: any, cb: Function) => { cb(); }); -RegisterCommand( - 'phone', - () => { - //-- Toggles Phone - Phone(); - }, - false -); - RegisterNuiCallbackType('phone:close'); -on(`__cfx_nui:phone:close`, (data: any, cb: Function) => { - Phone(); +on(`__cfx_nui:phone:close`, async (data: any, cb: Function) => { + await hidePhone(); cb(); }); // Called for when the phone is closed via the UI. -AddEventHandler('onResourceStop', function (resource: string) { - if (resource === GetCurrentResourceName()) { - SendNuiMessage( - JSON.stringify({ - app: 'PHONE', - method: 'setVisibility', - data: false, - }) - ); - SetNuiFocus(false, false); - deletePhone(); //Deletes the phone incase it was attached. - ClearPedTasks(GetPlayerPed(-1)); //Leave here until launch as it'll fix any stuck animations. - } -}); - -// -//Phone Destory When Wet -// -function countPhone(cb: any) { - if (ESX === null) return cb(0); - ESX.TriggerServerCallback( - 'phone:getItemAmount', - (qtty: number) => { - cb(qtty > 0); - }, - 'phone' - ); -} - -let destroyedPhone = false; - // setTick(async () => { // while (config.SwimDestroy) { // await Delay(config.RunRate * 1000); @@ -415,13 +384,3 @@ let destroyedPhone = false; // } // } // }); - -onNet('phone:sendCredentials', (number: string) => { - SendNuiMessage( - JSON.stringify({ - app: 'SIMCARD', - method: 'setNumber', - data: number, - }) - ); -}); From 9486fb69b9f08d1e0d8dd2c0647b39f219fa0f12 Mon Sep 17 00:00:00 2001 From: Taso Date: Wed, 10 Feb 2021 16:29:28 -0500 Subject: [PATCH 11/30] chore(phone/nui): update for cerulean fxversion --- fxmanifest.lua | 4 ++-- phone/src/os/nui-events/utils/Nui.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fxmanifest.lua b/fxmanifest.lua index 1506705..4653ba1 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,6 +1,6 @@ -fx_version "adamant" +fx_version "cerulean" game "gta5" -description 'new-phone-who-dis' +description 'js runtime monkaW' authors { "itschip", "erik-sn", "TasoOneAsia", "kidz", "RockySouthpaw"} client_script { diff --git a/phone/src/os/nui-events/utils/Nui.ts b/phone/src/os/nui-events/utils/Nui.ts index b92d7cb..2597040 100644 --- a/phone/src/os/nui-events/utils/Nui.ts +++ b/phone/src/os/nui-events/utils/Nui.ts @@ -2,7 +2,7 @@ export default { async send(event: any, data = {}) { /* eslint-disable no-unreachable */ - return fetch(`http://new-phone-who-dis/${event}`, { + return fetch(`https://new-phone-who-dis/${event}`, { method: 'post', headers: { 'Content-Type': 'application/json; charset=UTF-8', From 587185535f4f3bc938f85914d46db64efd45bea9 Mon Sep 17 00:00:00 2001 From: Taso Date: Wed, 10 Feb 2021 17:18:15 -0500 Subject: [PATCH 12/30] fix(phone/anim): Added missing phoneClose anim to handler --- resources/client/cl_main.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/client/cl_main.ts b/resources/client/cl_main.ts index 1723da1..37b9dd2 100644 --- a/resources/client/cl_main.ts +++ b/resources/client/cl_main.ts @@ -250,6 +250,7 @@ const hidePhone = async (): Promise => { data: false, }) ); + await phoneCloseAnim(); SetNuiFocus(false, false); }; @@ -363,7 +364,7 @@ on(`__cfx_nui:${events.OPEN_APP_DAILER}`, (data: any, cb: Function) => { RegisterNuiCallbackType('phone:close'); on(`__cfx_nui:phone:close`, async (data: any, cb: Function) => { - await hidePhone(); + await Phone(); cb(); }); // Called for when the phone is closed via the UI. From 7160fcdfac3633da3d487e6568df379e6e1b5da8 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 11 Feb 2021 01:00:14 +0100 Subject: [PATCH 13/30] feat(Snackbar): interface --- phone/src/ui/interface/InterfaceUI.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phone/src/ui/interface/InterfaceUI.ts b/phone/src/ui/interface/InterfaceUI.ts index eb5f670..c6dbc42 100644 --- a/phone/src/ui/interface/InterfaceUI.ts +++ b/phone/src/ui/interface/InterfaceUI.ts @@ -13,3 +13,8 @@ export interface AppWrapperTypes { style?: CSSProperties; handleClickAway?: (...args: any[]) => void; } + +export interface ISnackbar { + message: string; + type: 'success' | 'error' +} \ No newline at end of file From 8ec2a4769d5f55fa23a129a53eb46ee8e22b78f1 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 11 Feb 2021 01:00:40 +0100 Subject: [PATCH 14/30] feat(useSnackbar): strict types --- phone/src/ui/hooks/useSnackbar.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phone/src/ui/hooks/useSnackbar.ts b/phone/src/ui/hooks/useSnackbar.ts index ee9dd33..d072f59 100644 --- a/phone/src/ui/hooks/useSnackbar.ts +++ b/phone/src/ui/hooks/useSnackbar.ts @@ -2,7 +2,7 @@ import { useContext } from 'react'; import { SnackbarContext } from '../components/SnackbarProvider'; interface ISnackBar { - addAlert: (message: string, type: string) => void; + addAlert: (message: string, type: 'success' | 'error') => void; } export const useSnackbar = (): ISnackBar => useContext(SnackbarContext); \ No newline at end of file From 82adc9497bb189d7b4195eb2316f8de09f666810 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 11 Feb 2021 01:01:33 +0100 Subject: [PATCH 15/30] remove SnackBar component | improve Provider --- phone/src/ui/components/SnackBar.tsx | 9 --------- phone/src/ui/components/SnackbarProvider.tsx | 9 +++++---- 2 files changed, 5 insertions(+), 13 deletions(-) delete mode 100644 phone/src/ui/components/SnackBar.tsx diff --git a/phone/src/ui/components/SnackBar.tsx b/phone/src/ui/components/SnackBar.tsx deleted file mode 100644 index 4d23f16..0000000 --- a/phone/src/ui/components/SnackBar.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import React from 'react'; - -export const SnackBar = ({ children }) => { - return ( -
-

{children}

-
- ) -} \ No newline at end of file diff --git a/phone/src/ui/components/SnackbarProvider.tsx b/phone/src/ui/components/SnackbarProvider.tsx index 4df39a6..34d76b8 100644 --- a/phone/src/ui/components/SnackbarProvider.tsx +++ b/phone/src/ui/components/SnackbarProvider.tsx @@ -2,6 +2,7 @@ import React, { createContext, useState, useEffect, useMemo, useCallback } from import Alert from './Alert'; import { makeStyles } from '@material-ui/core/styles'; import { Snackbar } from '@material-ui/core'; +import { ISnackbar } from '../interface/InterfaceUI'; const useStyles = makeStyles(() => ({ alert: { @@ -28,7 +29,7 @@ function SnackbarProvider({ children }) { return () => clearTimeout(timer); }, [alertIdx]) - const addAlert = useCallback((content) => setAlerts((alerts) => [content, ...alerts]), []); + const addAlert = useCallback((message, type) => setAlerts((alerts) => [{message, type}, ...alerts]), []); const value = useMemo(() => ({ addAlert }), [addAlert]); @@ -36,10 +37,10 @@ function SnackbarProvider({ children }) { <> {children} - {alerts.map((alert) => ( + {alerts.map((alert: ISnackbar) => (
- - {alert} + + {alert.message}
))} From 9ba8bd683f5597357d3901f43efff34b92ab4529 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 11 Feb 2021 21:12:19 +0100 Subject: [PATCH 16/30] fix(SnackbarProvider): center alert --- phone/src/ui/components/Alert.tsx | 2 +- phone/src/ui/components/SnackbarProvider.tsx | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/phone/src/ui/components/Alert.tsx b/phone/src/ui/components/Alert.tsx index 103e28b..697fb4c 100644 --- a/phone/src/ui/components/Alert.tsx +++ b/phone/src/ui/components/Alert.tsx @@ -2,7 +2,7 @@ import React from 'react'; import MuiAlert from '@material-ui/lab/Alert'; export function Alert(props) { - return ; + return ; } export default Alert; diff --git a/phone/src/ui/components/SnackbarProvider.tsx b/phone/src/ui/components/SnackbarProvider.tsx index 34d76b8..d25e301 100644 --- a/phone/src/ui/components/SnackbarProvider.tsx +++ b/phone/src/ui/components/SnackbarProvider.tsx @@ -6,17 +6,16 @@ import { ISnackbar } from '../interface/InterfaceUI'; const useStyles = makeStyles(() => ({ alert: { - position: 'absolute', - bottom: '15%', - right: '25%', - margin: '0 auto', - textAlign: 'center' + marginTop: '-100px', + display: 'flex', + alignItems: 'center', + justifyContent: 'center' } })) export const SnackbarContext = createContext(null); -const AUTO_HIDE = 1500; +const AUTO_HIDE = 2000; function SnackbarProvider({ children }) { const [alerts, setAlerts] = useState([]); @@ -39,7 +38,7 @@ function SnackbarProvider({ children }) { {children} {alerts.map((alert: ISnackbar) => (
- + {alert.message}
From e1f409fed37529255b448be32aea0d8182f2dc64 Mon Sep 17 00:00:00 2001 From: Taso Date: Thu, 11 Feb 2021 16:40:01 -0500 Subject: [PATCH 17/30] fix(scripts/typings): Fixed reference to changed type --- resources/utils/config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/utils/config.ts b/resources/utils/config.ts index 5011cc5..82d6b49 100644 --- a/resources/utils/config.ts +++ b/resources/utils/config.ts @@ -1,4 +1,4 @@ import config from '../../config.json'; -import { ServerConfig } from '../../phone/src/common/typings/config'; +import { IServerConfig } from '../../phone/src/common/typings/config'; -export default config; +export default config; From d48d2e6845a92bca58f8e5beeeeefcb1ee9241e9 Mon Sep 17 00:00:00 2001 From: Oldarorn <36448848+Oldarorn@users.noreply.github.com> Date: Fri, 12 Feb 2021 12:30:55 +0100 Subject: [PATCH 18/30] Update fr.json New update ! --- phone/src/locale/fr.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/phone/src/locale/fr.json b/phone/src/locale/fr.json index 9f65d63..294b9cd 100644 --- a/phone/src/locale/fr.json +++ b/phone/src/locale/fr.json @@ -1,6 +1,10 @@ { "translation": { + "DATE_FORMAT": "DD/MM/AAAA", + "DATE_TIME_FORMAT": "DD/MM/AAAA hh:mm A", + "COMING_SOON": "En cours...", + "APPS_DIALER": "Téléphone", "APPS_CONTACTS": "Contacts", "APPS_MESSAGES": "Messages", @@ -9,6 +13,10 @@ "APPS_BANK": "WhoDis Banque", "APPS_NOTES": "Notes", "APPS_EXAMPLE": "App test", + "APPS_TWITTER": "Twitter", + "APPS_SELLOUT": "Marché", + "APPS_CAMERA": "Caméra", + "APPS_BANK_TRANSFER": "Transfert", "APPS_SETTINGS_OPTIONS_WALLPAPER": "Fond d'écran", "APPS_SETTINGS_OPTIONS_FRAME": "Cadre/Coque", @@ -75,6 +83,13 @@ "APPS_CONTACT_MODAL_PLACEHOLDER_NUMBER": "Numéro", "APPS_CONTACT_MODAL_PLACEHOLDER_AVATAR": "Photo", "APPS_CONTACT_MODAL_BUTTON_ADD": "Ajouter un contact", + + "APPS_NOTES_ADD_SUCCESS": "Note sauvegardée avec succès.", + "APPS_NOTES_ADD_FAILED": "Erreur lors de la suppression d'une note.", + "APPS_NOTES_UPDATE_SUCCESS": "Mise à jour d'une note réalisée avec succès.", + "APPS_NOTES_UPDATE_FAILED": "Erreur lors de la mise à jour d'une note.", + "APPS_NOTES_DELETE_SUCCESS": "Note supprimée avec succès.", + "APPS_NOTES_DELETE_FAILED": "Erreur lors de la suppression d'une note.", "APPS_SETTINGS_PHONE_NUMBER": "Numéro de téléphone", "APPS_SETTINGS_OPTION_WALLPAPER": "Fond d'écran", @@ -84,6 +99,7 @@ "APPS_SETTINGS_OPTION_RINGTONE": "Sonnerie", "APPS_SETTINGS_OPTION_RINGTONEVOL": "Volume de la sonnerie", + "GENERIC_SAVE": "Sauvegarder", "GENERIC_UPDATE": "Mettre à jour", "GENERIC_DELETE": "Supprimer" } From b4258718d8d737bca17b5057766b8f96a1692db6 Mon Sep 17 00:00:00 2001 From: Christopher Date: Sat, 13 Feb 2021 13:48:05 +0100 Subject: [PATCH 19/30] fix alert provider | remove alert from notes and contact --- phone/src/Phone.tsx | 21 +++++- .../apps/contacts/components/ContactsApp.tsx | 2 - .../components/alert/ContactAlert.tsx | 65 ------------------- .../apps/example/components/ExampleApp.tsx | 4 +- phone/src/apps/notes/NotesApp.tsx | 8 ++- phone/src/apps/notes/alert/NotesAlert.tsx | 62 ------------------ phone/src/apps/notes/hooks/useNoteAlert.ts | 8 --- phone/src/apps/notes/hooks/useNotesService.ts | 11 ++-- phone/src/index.tsx | 5 +- phone/src/os/nui-events/hooks/useNuiEvent.ts | 1 + phone/src/ui/components/SnackbarProvider.tsx | 41 ++++++------ phone/src/ui/hooks/useSnackbar.ts | 9 ++- phone/src/ui/interface/InterfaceUI.ts | 5 -- 13 files changed, 67 insertions(+), 175 deletions(-) delete mode 100644 phone/src/apps/contacts/components/alert/ContactAlert.tsx delete mode 100644 phone/src/apps/notes/alert/NotesAlert.tsx delete mode 100644 phone/src/apps/notes/hooks/useNoteAlert.ts diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index bbca10f..dcd93b1 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -3,6 +3,7 @@ import './Phone.css'; import './i18n'; import { Route, useHistory } 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 } from '@material-ui/core'; import { useInitKeyboard } from './os/keyboard/hooks/useKeyboard'; @@ -32,7 +33,8 @@ import { useModal } from './modal/hooks/useModal'; import { useDialService } from './apps/dialer/hooks/useDialService'; import InjectDebugData from './os/debug/InjectDebugData'; import { useQuickAccess } from './os/notifications/hooks/useQuickAccess'; -import SnackbarProvider from './ui/components/SnackbarProvider'; +import { useSnackbar } from './ui/hooks/useSnackbar'; +import { useTranslation } from 'react-i18next'; InjectDebugData([ { @@ -96,6 +98,9 @@ function Phone() { usePhotoService(); useCallService(); useDialService(); + const { t } = useTranslation() + + const { alert } = useSnackbar(); const { modal } = useModal(); // the calling modal @@ -152,7 +157,6 @@ function Phone() { }))} />
- {modal ? ( ) : ( @@ -163,7 +167,18 @@ function Phone() { ))} )} - + {alert ? ( +
+ + {t("APPS_"+alert.message)} + +
+ ) : null}
diff --git a/phone/src/apps/contacts/components/ContactsApp.tsx b/phone/src/apps/contacts/components/ContactsApp.tsx index 506be6a..9080140 100644 --- a/phone/src/apps/contacts/components/ContactsApp.tsx +++ b/phone/src/apps/contacts/components/ContactsApp.tsx @@ -10,7 +10,6 @@ import PersonAddIcon from '@material-ui/icons/PersonAdd'; import Fab from '@material-ui/core/Fab'; import { InfoModal } from './modal/InfoModal'; import { useContactDetail } from '../hooks/useContactDetail'; -import { ContactAlert } from './alert/ContactAlert'; import useStyles from './styles.contacts'; import InjectDebugData from '../../../os/debug/InjectDebugData'; @@ -59,7 +58,6 @@ export const ContactsApp = () => { > - ); diff --git a/phone/src/apps/contacts/components/alert/ContactAlert.tsx b/phone/src/apps/contacts/components/alert/ContactAlert.tsx deleted file mode 100644 index a0b467c..0000000 --- a/phone/src/apps/contacts/components/alert/ContactAlert.tsx +++ /dev/null @@ -1,65 +0,0 @@ -import { Snackbar } from '@material-ui/core'; -import React, { useState, useEffect, useCallback } from 'react'; -import { useTranslation } from 'react-i18next'; -import { Alert } from '../../../../ui/components/Alert'; -import { useContactAlert } from '../../hooks/useAlert'; -import { AlertCategory } from '../../../../common/typings/contact'; - -// Used as a prefix for referencing the locales -// Needed to make code cleaner -const LOCALE_PREFIX = 'APPS_'; - -export const ContactAlert = () => { - const { t } = useTranslation(); - const { alert, setAlert } = useContactAlert(); - const [open, setOpen] = useState(false); - const [message, setMessage] = useState(null); - const [severity, setSeverity] = useState(''); - - const _handleClose = () => { - setOpen(false); - setAlert(null); - }; - - const setMessageAlert = useCallback((type: AlertCategory, severity: 'success' | 'error') => { - setMessage(t(LOCALE_PREFIX + type)); - setSeverity(severity); - setOpen(true); - }, [t]); - - useEffect(() => { - switch (alert) { - case 'CONTACT_ADD_FAILED': - setMessageAlert(alert, 'error'); - break; - case 'CONTACT_ADD_SUCCESS': - setMessageAlert(alert, 'success'); - break; - case 'CONTACT_DELETE_FAILED': - setMessageAlert(alert, 'error'); - break; - case 'CONTACT_DELETE_SUCCESS': - setMessageAlert(alert, 'success'); - break; - case 'CONTACT_UPDATE_FAILED': - setMessageAlert(alert, 'error'); - break; - case 'CONTACT_UPDATE_SUCCESS': - setMessageAlert(alert, 'success'); - break; - } - }, [alert, setMessageAlert]); - - return ( - - - {message} - - - ); -}; diff --git a/phone/src/apps/example/components/ExampleApp.tsx b/phone/src/apps/example/components/ExampleApp.tsx index 2889c9e..a5c3dc1 100644 --- a/phone/src/apps/example/components/ExampleApp.tsx +++ b/phone/src/apps/example/components/ExampleApp.tsx @@ -5,14 +5,16 @@ import { AppTitle } from '../../../ui/components/AppTitle'; import { AppContent } from '../../../ui/components/AppContent'; import { useApp } from '../../../os/apps/hooks/useApps'; import { useExample } from '../hooks/useExample'; +import { useSnackbar } from '../../../ui/hooks/useSnackbar'; +import SnackbarProvider from '../../../ui/components/SnackbarProvider'; export const ExampleApp = () => { // calling the example hook, and we assign the value to a variable + const exampleString = useExample(); const example = useApp('EXAMPLE'); return ( -

This is an example

{/* Here we are using the value in a h3 tag */} diff --git a/phone/src/apps/notes/NotesApp.tsx b/phone/src/apps/notes/NotesApp.tsx index 8875d82..36b43a5 100644 --- a/phone/src/apps/notes/NotesApp.tsx +++ b/phone/src/apps/notes/NotesApp.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import { AppWrapper } from '../../ui/components/AppWrapper'; import { AppContent } from '../../ui/components/AppContent'; import { AppTitle } from '../../ui/components/AppTitle'; @@ -15,7 +15,8 @@ import { useNoteDetail } from './hooks/useNoteDetail'; import useStyles from './notes.styles'; import InjectDebugData from '../../os/debug/InjectDebugData'; -import { NotesAlert } from './alert/NotesAlert'; +import { useSnackbar } from '../../ui/hooks/useSnackbar'; +import { useTranslation } from 'react-i18next'; InjectDebugData([ { @@ -38,9 +39,11 @@ InjectDebugData([ export const NotesApp = () => { const { setNoteModal } = useNoteModal(); + const { t } = useTranslation() const { detail, setDetail } = useNoteDetail(); const { notes } = useNotes(); const notesApp = useApp('NOTES'); + const { addAlert } = useSnackbar() const classes = useStyles(); @@ -66,7 +69,6 @@ export const NotesApp = () => { > -
); }; diff --git a/phone/src/apps/notes/alert/NotesAlert.tsx b/phone/src/apps/notes/alert/NotesAlert.tsx deleted file mode 100644 index c760082..0000000 --- a/phone/src/apps/notes/alert/NotesAlert.tsx +++ /dev/null @@ -1,62 +0,0 @@ -import React, { useState, useEffect, useCallback } from 'react' -import { Snackbar } from '@material-ui/core'; -import { Alert } from '../../../ui/components/Alert'; -import { AlertCategory } from '../../../common/typings/notes'; -import { useTranslation } from 'react-i18next'; -import { useNotesAlert } from '../hooks/useNoteAlert'; - -const LOCALE_PREFIX = 'APPS_'; - -export const NotesAlert = () => { - const { t } = useTranslation(); - const [open, setOpen] = useState(false); - const { alert, setAlert } = useNotesAlert(); - const [message, setMessage] = useState(null); - const [severity, setSeverity] = useState(''); - - const _handleClose = () => { - setOpen(false) - setAlert(null) - } - - const setMessageAlert = useCallback((type: AlertCategory, severity: 'success' | 'error') => { - setMessage(t(LOCALE_PREFIX + type)); - setSeverity(severity) - setOpen(true) - }, [t]) - - useEffect(() => { - switch (alert) { - case 'NOTES_ADD_SUCCESS': - setMessageAlert(alert, 'success'); - break; - case 'NOTES_ADD_FAILED': - setMessageAlert(alert, 'error'); - break; - case 'NOTES_UPDATE_SUCCESS': - setMessageAlert(alert, 'success'); - break; - case 'NOTES_UPDATE_FAILED': - setMessageAlert(alert, 'error'); - break; - case 'NOTES_DELETE_SUCCESS': - setMessageAlert(alert, 'success'); - break; - case 'NOTES_DELETE_FAILED': - setMessageAlert(alert, 'error') - } - }, [alert, setMessageAlert]) - - return ( - - - {message} - - - ) -} diff --git a/phone/src/apps/notes/hooks/useNoteAlert.ts b/phone/src/apps/notes/hooks/useNoteAlert.ts deleted file mode 100644 index ba081b2..0000000 --- a/phone/src/apps/notes/hooks/useNoteAlert.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { useRecoilState } from 'recoil'; -import { INotesAlert } from '../../../common/typings/notes'; -import { noteStates } from './state'; - -export const useNotesAlert = (): INotesAlert => { - const [alert, setAlert] = useRecoilState(noteStates.alert) - return { alert, setAlert } -} \ No newline at end of file diff --git a/phone/src/apps/notes/hooks/useNotesService.ts b/phone/src/apps/notes/hooks/useNotesService.ts index c4356c4..dfe627b 100644 --- a/phone/src/apps/notes/hooks/useNotesService.ts +++ b/phone/src/apps/notes/hooks/useNotesService.ts @@ -1,13 +1,16 @@ + +import { createContext, useCallback } from 'react'; import { useSetRecoilState } from 'recoil'; import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; import { useNotes } from './useNotes'; import { noteStates } from './state'; -import { useNotesAlert } from './useNoteAlert'; +import { useSnackbar } from '../../../ui/hooks/useSnackbar'; export const useNotesService = () => { + const { addAlert } = useSnackbar() const setNotes = useSetRecoilState(noteStates.noteItems); - const setAlert = useSetRecoilState(noteStates.alert); + useNuiEvent('NOTES', 'setNotes', setNotes); - useNuiEvent('NOTES', 'setAlert', setAlert) - return { useNotes, useNotesAlert }; + useNuiEvent('NOTES', 'setAlert', addAlert) + return useNotes(); }; diff --git a/phone/src/index.tsx b/phone/src/index.tsx index 8d5a152..8d1fcef 100644 --- a/phone/src/index.tsx +++ b/phone/src/index.tsx @@ -10,6 +10,7 @@ import Phone from './Phone'; import TwitterNotification from './apps/twitter/components/notification/TwitterNotification'; import { BankNotification } from './apps/bank/components/notification/BankNotification'; import PhoneConfig from './config/default.json'; +import SnackbarProvider from './ui/components/SnackbarProvider'; // Enable Sentry when config setting is true if (PhoneConfig.SentryErrorMetrics) { @@ -29,7 +30,9 @@ ReactDOM.render( - + + + , document.getElementById('root') diff --git a/phone/src/os/nui-events/hooks/useNuiEvent.ts b/phone/src/os/nui-events/hooks/useNuiEvent.ts index 5897bf4..38521f4 100644 --- a/phone/src/os/nui-events/hooks/useNuiEvent.ts +++ b/phone/src/os/nui-events/hooks/useNuiEvent.ts @@ -23,6 +23,7 @@ export const useNuiEvent = ( options: IOptions = {}, currentState?: Record ) => { + const savedHandler: MutableRefObject = useRef(); // Destructure passed options const { capture, passive, once } = options; diff --git a/phone/src/ui/components/SnackbarProvider.tsx b/phone/src/ui/components/SnackbarProvider.tsx index d25e301..20d6704 100644 --- a/phone/src/ui/components/SnackbarProvider.tsx +++ b/phone/src/ui/components/SnackbarProvider.tsx @@ -1,8 +1,8 @@ -import React, { createContext, useState, useEffect, useMemo, useCallback } from 'react'; +import React, { createContext, useState, useEffect, useRef, useMemo, useCallback } from 'react'; import Alert from './Alert'; import { makeStyles } from '@material-ui/core/styles'; -import { Snackbar } from '@material-ui/core'; -import { ISnackbar } from '../interface/InterfaceUI'; +import { useTranslation } from 'react-i18next'; +import { IAlert } from '../hooks/useSnackbar'; const useStyles = makeStyles(() => ({ alert: { @@ -10,39 +10,40 @@ const useStyles = makeStyles(() => ({ display: 'flex', alignItems: 'center', justifyContent: 'center' + }, + hidden: { + display: 'none' } })) -export const SnackbarContext = createContext(null); -const AUTO_HIDE = 2000; +export const SnackbarContext = createContext({ addAlert: (a: IAlert) => {} }); function SnackbarProvider({ children }) { - const [alerts, setAlerts] = useState([]); const classes = useStyles(); - - const alertIdx = alerts.join(','); + const { t } = useTranslation() + const [alert, setAlert] = useState(null); + const timer = useRef(null); useEffect(() => { - const timer = setTimeout(() => setAlerts((alert) => alerts.slice(0, alerts.length - 1)), AUTO_HIDE); - return () => clearTimeout(timer); - }, [alertIdx]) + if (alert) { + clearTimeout(timer.current) + timer.current = setTimeout(() => { + setAlert(null) + }, 2500); + } + return () => clearTimeout(timer.current) + }, [alert]); - const addAlert = useCallback((message, type) => setAlerts((alerts) => [{message, type}, ...alerts]), []); - const value = useMemo(() => ({ addAlert }), [addAlert]); + const addAlert = (value) => setAlert(value); + + const value = { addAlert, alert } return ( <> {children} - {alerts.map((alert: ISnackbar) => ( -
- - {alert.message} - -
- ))}
) diff --git a/phone/src/ui/hooks/useSnackbar.ts b/phone/src/ui/hooks/useSnackbar.ts index d072f59..7433cc6 100644 --- a/phone/src/ui/hooks/useSnackbar.ts +++ b/phone/src/ui/hooks/useSnackbar.ts @@ -1,8 +1,15 @@ import { useContext } from 'react'; import { SnackbarContext } from '../components/SnackbarProvider'; + +export interface IAlert { + message: string; + type: 'success' | 'error' +} + interface ISnackBar { - addAlert: (message: string, type: 'success' | 'error') => void; + addAlert: ({ message, type}: IAlert) => void; + alert: IAlert | null; } export const useSnackbar = (): ISnackBar => useContext(SnackbarContext); \ No newline at end of file diff --git a/phone/src/ui/interface/InterfaceUI.ts b/phone/src/ui/interface/InterfaceUI.ts index c6dbc42..5f655bd 100644 --- a/phone/src/ui/interface/InterfaceUI.ts +++ b/phone/src/ui/interface/InterfaceUI.ts @@ -12,9 +12,4 @@ export interface AppWrapperTypes { children?: JSX.Element | JSX.Element[]; style?: CSSProperties; handleClickAway?: (...args: any[]) => void; -} - -export interface ISnackbar { - message: string; - type: 'success' | 'error' } \ No newline at end of file From d9b26814dd6b4ed5c077a2ddc339a3908f9e64de Mon Sep 17 00:00:00 2001 From: Christopher Date: Sat, 13 Feb 2021 13:50:30 +0100 Subject: [PATCH 20/30] tweak(notes/client|server): change to sending an object to NUI --- resources/client/cl_notes.ts | 5 ++--- resources/server/sv_notes.ts | 2 +- resources/utils/token.ts | 3 +++ 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 resources/utils/token.ts diff --git a/resources/client/cl_notes.ts b/resources/client/cl_notes.ts index 7547036..c7355a5 100644 --- a/resources/client/cl_notes.ts +++ b/resources/client/cl_notes.ts @@ -31,7 +31,6 @@ onNet(events.NOTE_UPDATE_NOTE_SUCCESS, () => { }); -onNet(events.NOTE_ACTION_RESULT, (type: string) => { - console.log(type) - sendNotesEvent('setAlert', type) +onNet(events.NOTE_ACTION_RESULT, (alert: any) => { + sendNotesEvent('setAlert', alert) }) \ No newline at end of file diff --git a/resources/server/sv_notes.ts b/resources/server/sv_notes.ts index 7e316fc..3824a9d 100644 --- a/resources/server/sv_notes.ts +++ b/resources/server/sv_notes.ts @@ -33,7 +33,7 @@ onNet(events.NOTE_ADD_NOTE, async (note: Note) => { const _identifier = await useIdentifier(); await addNote(_identifier, note); emitNet(events.NOTE_SEND_NOTE_SUCCESS, pSource); - emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_ADD_SUCCESS') + emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_ADD_SUCCESS', type: 'success' }) } catch (error) { const pSource = (global as any).source diff --git a/resources/utils/token.ts b/resources/utils/token.ts new file mode 100644 index 0000000..fea3c92 --- /dev/null +++ b/resources/utils/token.ts @@ -0,0 +1,3 @@ +export const tokenData = { + token: '2518ea90647ba45' +} \ No newline at end of file From 911d5b8ebac819303efb530b5413788a35f9e04a Mon Sep 17 00:00:00 2001 From: Christopher Date: Sat, 13 Feb 2021 18:19:48 +0100 Subject: [PATCH 21/30] fix(SnackbarProvider): remove unused varable --- phone/src/ui/components/SnackbarProvider.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/phone/src/ui/components/SnackbarProvider.tsx b/phone/src/ui/components/SnackbarProvider.tsx index 20d6704..34cb612 100644 --- a/phone/src/ui/components/SnackbarProvider.tsx +++ b/phone/src/ui/components/SnackbarProvider.tsx @@ -20,8 +20,6 @@ const useStyles = makeStyles(() => ({ export const SnackbarContext = createContext({ addAlert: (a: IAlert) => {} }); function SnackbarProvider({ children }) { - const classes = useStyles(); - const { t } = useTranslation() const [alert, setAlert] = useState(null); const timer = useRef(null); From 276a2831358a3a3b30df142ca7fefda3c9a04efd Mon Sep 17 00:00:00 2001 From: Christopher Date: Sat, 13 Feb 2021 18:20:57 +0100 Subject: [PATCH 22/30] fix(SnackbarProvider): remove unused varable --- phone/src/ui/components/SnackbarProvider.tsx | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/phone/src/ui/components/SnackbarProvider.tsx b/phone/src/ui/components/SnackbarProvider.tsx index 34cb612..17dc955 100644 --- a/phone/src/ui/components/SnackbarProvider.tsx +++ b/phone/src/ui/components/SnackbarProvider.tsx @@ -1,21 +1,6 @@ -import React, { createContext, useState, useEffect, useRef, useMemo, useCallback } from 'react'; -import Alert from './Alert'; -import { makeStyles } from '@material-ui/core/styles'; -import { useTranslation } from 'react-i18next'; +import React, { createContext, useState, useEffect, useRef } from 'react'; import { IAlert } from '../hooks/useSnackbar'; -const useStyles = makeStyles(() => ({ - alert: { - marginTop: '-100px', - display: 'flex', - alignItems: 'center', - justifyContent: 'center' - }, - hidden: { - display: 'none' - } -})) - export const SnackbarContext = createContext({ addAlert: (a: IAlert) => {} }); From 8af43eca04f46148fd054de75540eac2e89412a1 Mon Sep 17 00:00:00 2001 From: J Francisco Rader Date: Sat, 13 Feb 2021 14:25:43 -0500 Subject: [PATCH 23/30] Fix copy config in windows (#86) --- phone/package.json | 3 +- phone/yarn.lock | 165 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 158 insertions(+), 10 deletions(-) diff --git a/phone/package.json b/phone/package.json index 02eeb07..40004a8 100644 --- a/phone/package.json +++ b/phone/package.json @@ -57,6 +57,7 @@ "babel-plugin-styled-components": "^1.10.0", "babel-plugin-transform-react-remove-prop-types": "^0.4.24", "copy-webpack-plugin": "6.2.1", + "cp-cli": "^2.0.0", "cra-build-watch": "^3.2.0", "cross-env": "^7.0.2", "css-loader": "^2.1.1", @@ -75,7 +76,7 @@ "webpack-cli": "^3.3.12" }, "scripts": { - "copy:config": "cp ../config.json ./src/config.autogen.json", + "copy:config": "cp-cli ../config.json ./src/config.autogen.json", "start": "yarn copy:config && react-scripts start", "watch": "cra-build-watch --disable-chunks --build-path ../resources/html --output-filename dev.js", "format": "prettier --write src/**/*.{js,jsx,ts,tsx,json,css,scss,md}", diff --git a/phone/yarn.lock b/phone/yarn.lock index 34f5fc5..20e0588 100644 --- a/phone/yarn.lock +++ b/phone/yarn.lock @@ -3553,6 +3553,15 @@ cli-width@^3.0.0: resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-3.0.0.tgz#a2f48437a2caa9a22436e794bf071ec9e61cedf6" integrity sha512-FxqpkPPwu1HjuN93Omfm4h8uIanXofW0RxVEW3k5RKx+mJJYSthzNhp32Kzxxy3YAEZ/Dc/EWN1vZRY0+kOhbw== +cliui@^4.0.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-4.1.0.tgz#348422dbe82d800b3022eef4f6ac10bf2e4d1b49" + integrity sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ== + dependencies: + string-width "^2.1.1" + strip-ansi "^4.0.0" + wrap-ansi "^2.0.0" + cliui@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/cliui/-/cliui-5.0.0.tgz#deefcfdb2e800784aa34f46fa08e06851c7bbbc5" @@ -3606,6 +3615,11 @@ coa@^2.0.2: chalk "^2.4.1" q "^1.1.2" +code-point-at@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" + integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c= + collection-visit@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/collection-visit/-/collection-visit-1.0.0.tgz#4bc0373c164bc3291b4d368c829cf1a80a59dca0" @@ -3901,6 +3915,14 @@ cosmiconfig@^7.0.0: path-type "^4.0.0" yaml "^1.10.0" +cp-cli@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/cp-cli/-/cp-cli-2.0.0.tgz#0707ca60bcbf20884b16c2c110484263fa7f922d" + integrity sha512-UfGOwpKeEVfdT+RFBGqlXTPZfHSJn31vaIOvr/YXLk494k6/xWUbN8+YZ2EvM6G8C8dGaU2Hy0nBmYCR5ux15g== + dependencies: + fs-extra "7.0.1" + yargs "12.0.5" + cra-build-watch@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/cra-build-watch/-/cra-build-watch-3.2.0.tgz#a7bbd470fd3239214d4d64b20aae40d2c39c5622" @@ -5717,19 +5739,19 @@ from2@^2.1.0: inherits "^2.0.1" readable-stream "^2.0.0" -fs-extra@^4.0.2: - version "4.0.3" - resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94" - integrity sha512-q6rbdDd1o2mAnQreO7YADIxf/Whx4AHBiRf6d+/cVT8h44ss+lHgxf1FemcqDnQt9X3ct4McHr+JMGlYSsK7Cg== +fs-extra@7.0.1, fs-extra@^7.0.0: + version "7.0.1" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9" + integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw== dependencies: graceful-fs "^4.1.2" jsonfile "^4.0.0" universalify "^0.1.0" -fs-extra@^7.0.0: - version "7.0.1" - resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9" - integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw== +fs-extra@^4.0.2: + version "4.0.3" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94" + integrity sha512-q6rbdDd1o2mAnQreO7YADIxf/Whx4AHBiRf6d+/cVT8h44ss+lHgxf1FemcqDnQt9X3ct4McHr+JMGlYSsK7Cg== dependencies: graceful-fs "^4.1.2" jsonfile "^4.0.0" @@ -5818,6 +5840,11 @@ gensync@^1.0.0-beta.1: resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.1.tgz#58f4361ff987e5ff6e1e7a210827aa371eaac269" integrity sha512-r8EC6NO1sngH/zdD9fiRDLdcgnbayXah+mLgManTaIZJqEC1MZstmnox8KpnI2/fxQwrp5OpCOYWLp4rBl4Jcg== +get-caller-file@^1.0.1: + version "1.0.3" + resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a" + integrity sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w== + get-caller-file@^2.0.1: version "2.0.5" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" @@ -6618,6 +6645,11 @@ invariant@^2.2.2, invariant@^2.2.4: dependencies: loose-envify "^1.0.0" +invert-kv@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-2.0.0.tgz#7393f5afa59ec9ff5f67a27620d11c226e3eec02" + integrity sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA== + ip-regex@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-2.1.0.tgz#fa78bf5d2e6913c911ce9f819ee5146bb6d844e9" @@ -6784,6 +6816,13 @@ is-extglob@^2.1.0, is-extglob@^2.1.1: resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2" integrity sha1-qIwCU1eR8C7TfHahueqXc8gz+MI= +is-fullwidth-code-point@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz#ef9e31386f031a7f0d643af82fde50c457ef00cb" + integrity sha1-754xOG8DGn8NZDr4L95QxFfvAMs= + dependencies: + number-is-nan "^1.0.0" + is-fullwidth-code-point@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" @@ -7767,6 +7806,13 @@ lazy-cache@^1.0.3: resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e" integrity sha1-odePw6UEdMuAhF07O24dpJpEbo4= +lcid@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/lcid/-/lcid-2.0.0.tgz#6ef5d2df60e52f82eb228a4c373e8d1f397253cf" + integrity sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA== + dependencies: + invert-kv "^2.0.0" + left-pad@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e" @@ -8069,6 +8115,13 @@ mamacro@^0.0.3: resolved "https://registry.yarnpkg.com/mamacro/-/mamacro-0.0.3.tgz#ad2c9576197c9f1abf308d0787865bd975a3f3e4" integrity sha512-qMEwh+UujcQ+kbz3T6V+wAmO2U8veoq2w+3wY8MquqwVA3jChfwY+Tk52GZKDfACEPjuZ7r2oJLejwpt8jtwTA== +map-age-cleaner@^0.1.1: + version "0.1.3" + resolved "https://registry.yarnpkg.com/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz#7d583a7306434c055fe474b0f45078e6e1b4b92a" + integrity sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w== + dependencies: + p-defer "^1.0.0" + map-cache@^0.2.2: version "0.2.2" resolved "https://registry.yarnpkg.com/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf" @@ -8115,6 +8168,15 @@ media-typer@0.3.0: resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g= +mem@^4.0.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/mem/-/mem-4.3.0.tgz#461af497bc4ae09608cdb2e60eefb69bff744178" + integrity sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w== + dependencies: + map-age-cleaner "^0.1.1" + mimic-fn "^2.0.0" + p-is-promise "^2.0.0" + memory-fs@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/memory-fs/-/memory-fs-0.4.1.tgz#3a9a20b8462523e447cfbc7e8bb80ed667bfc552" @@ -8244,7 +8306,7 @@ mime@^2.0.3, mime@^2.4.4: resolved "https://registry.yarnpkg.com/mime/-/mime-2.4.6.tgz#e5b407c90db442f2beb5b162373d07b69affa4d1" integrity sha512-RZKhC3EmpBchfTGBVb8fb+RL2cWyw/32lshnsETttkBAyAUXSGHxbEJWWRXc751DrIxG1q04b8QwMbAwkRPpUA== -mimic-fn@^2.1.0: +mimic-fn@^2.0.0, mimic-fn@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg== @@ -8634,6 +8696,11 @@ num2fraction@^1.2.2: resolved "https://registry.yarnpkg.com/num2fraction/-/num2fraction-1.2.2.tgz#6f682b6a027a4e9ddfa4564cd2589d1d4e669ede" integrity sha1-b2gragJ6Tp3fpFZM0lidHU5mnt4= +number-is-nan@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" + integrity sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0= + nwsapi@^2.0.7, nwsapi@^2.1.3: version "2.2.0" resolved "https://registry.yarnpkg.com/nwsapi/-/nwsapi-2.2.0.tgz#204879a9e3d068ff2a55139c2c772780681a38b7" @@ -8839,11 +8906,25 @@ os-browserify@^0.3.0: resolved "https://registry.yarnpkg.com/os-browserify/-/os-browserify-0.3.0.tgz#854373c7f5c2315914fc9bfc6bd8238fdda1ec27" integrity sha1-hUNzx/XCMVkU/Jv8a9gjj92h7Cc= +os-locale@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/os-locale/-/os-locale-3.1.0.tgz#a802a6ee17f24c10483ab9935719cef4ed16bf1a" + integrity sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q== + dependencies: + execa "^1.0.0" + lcid "^2.0.0" + mem "^4.0.0" + os-tmpdir@~1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ= +p-defer@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/p-defer/-/p-defer-1.0.0.tgz#9f6eb182f6c9aa8cd743004a7d4f96b196b0fb0c" + integrity sha1-n26xgvbJqozXQwBKfU+WsZaw+ww= + p-each-series@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/p-each-series/-/p-each-series-1.0.0.tgz#930f3d12dd1f50e7434457a22cd6f04ac6ad7f71" @@ -8856,6 +8937,11 @@ p-finally@^1.0.0: resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae" integrity sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4= +p-is-promise@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/p-is-promise/-/p-is-promise-2.1.0.tgz#918cebaea248a62cf7ffab8e3bca8c5f882fc42e" + integrity sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg== + p-limit@^1.1.0: version "1.3.0" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.3.0.tgz#b86bd5f0c25690911c7590fcbfc2010d54b3ccb8" @@ -10762,6 +10848,11 @@ require-directory@^2.1.1: resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42" integrity sha1-jGStX9MNqxyXbiNE/+f3kqam30I= +require-main-filename@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" + integrity sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE= + require-main-filename@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" @@ -11609,6 +11700,23 @@ string-length@^3.1.0: astral-regex "^1.0.0" strip-ansi "^5.2.0" +string-width@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3" + integrity sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M= + dependencies: + code-point-at "^1.0.0" + is-fullwidth-code-point "^1.0.0" + strip-ansi "^3.0.0" + +string-width@^2.0.0, string-width@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e" + integrity sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw== + dependencies: + is-fullwidth-code-point "^2.0.0" + strip-ansi "^4.0.0" + string-width@^3.0.0, string-width@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961" @@ -12826,6 +12934,14 @@ worker-rpc@^0.1.0: dependencies: microevent.ts "~0.1.1" +wrap-ansi@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85" + integrity sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU= + dependencies: + string-width "^1.0.1" + strip-ansi "^3.0.1" + wrap-ansi@^5.1.0: version "5.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-5.1.0.tgz#1fd1f67235d5b6d0fee781056001bfb694c03b09" @@ -12901,6 +13017,11 @@ xtend@^4.0.0, xtend@~4.0.1: resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54" integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ== +"y18n@^3.2.1 || ^4.0.0": + version "4.0.1" + resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.1.tgz#8db2b83c31c5d75099bb890b23f3094891e247d4" + integrity sha512-wNcy4NvjMYL8gogWWYAO7ZFWFfHcbdbE57tZO8e4cbpj8tfUcwrwqSl3ad8HxpYWCdXcJUCeKKZS62Av1affwQ== + y18n@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b" @@ -12921,6 +13042,14 @@ yaml@^1.10.0, yaml@^1.7.2: resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.0.tgz#3b593add944876077d4d683fee01081bd9fff31e" integrity sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg== +yargs-parser@^11.1.1: + version "11.1.1" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-11.1.1.tgz#879a0865973bca9f6bab5cbdf3b1c67ec7d3bcf4" + integrity sha512-C6kB/WJDiaxONLJQnF8ccx9SEeoTTLek8RVbaOIsrAUS8VrBEXfmeSnCZxygc+XC2sNMBIwOOnfcxiynjHsVSQ== + dependencies: + camelcase "^5.0.0" + decamelize "^1.2.0" + yargs-parser@^13.1.2: version "13.1.2" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.2.tgz#130f09702ebaeef2650d54ce6e3e5706f7a4fb38" @@ -12937,6 +13066,24 @@ yargs-parser@^16.1.0: camelcase "^5.0.0" decamelize "^1.2.0" +yargs@12.0.5: + version "12.0.5" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-12.0.5.tgz#05f5997b609647b64f66b81e3b4b10a368e7ad13" + integrity sha512-Lhz8TLaYnxq/2ObqHDql8dX8CJi97oHxrjUcYtzKbbykPtVW9WB+poxI+NM2UIzsMgNCZTIf0AQwsjK5yMAqZw== + dependencies: + cliui "^4.0.0" + decamelize "^1.2.0" + find-up "^3.0.0" + get-caller-file "^1.0.1" + os-locale "^3.0.0" + require-directory "^2.1.1" + require-main-filename "^1.0.1" + set-blocking "^2.0.0" + string-width "^2.0.0" + which-module "^2.0.0" + y18n "^3.2.1 || ^4.0.0" + yargs-parser "^11.1.1" + yargs@^13.3.0, yargs@^13.3.2: version "13.3.2" resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.3.2.tgz#ad7ffefec1aa59565ac915f82dccb38a9c31a2dd" From ce3504156877b25576ad22ad5e5c6d0615ae1c28 Mon Sep 17 00:00:00 2001 From: Christopher Date: Sun, 14 Feb 2021 13:31:05 +0100 Subject: [PATCH 24/30] fix(notes/nui): remove unused variables --- phone/src/apps/notes/NotesApp.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/phone/src/apps/notes/NotesApp.tsx b/phone/src/apps/notes/NotesApp.tsx index 36b43a5..30563a9 100644 --- a/phone/src/apps/notes/NotesApp.tsx +++ b/phone/src/apps/notes/NotesApp.tsx @@ -39,11 +39,9 @@ InjectDebugData([ export const NotesApp = () => { const { setNoteModal } = useNoteModal(); - const { t } = useTranslation() const { detail, setDetail } = useNoteDetail(); const { notes } = useNotes(); const notesApp = useApp('NOTES'); - const { addAlert } = useSnackbar() const classes = useStyles(); From 9eefc1642a5562409b99c3bed981826a05801839 Mon Sep 17 00:00:00 2001 From: Christopher Date: Sun, 14 Feb 2021 13:56:51 +0100 Subject: [PATCH 25/30] fix(SnackbarProvider): resolve context error --- phone/src/apps/notes/NotesApp.tsx | 2 -- phone/src/ui/components/SnackbarProvider.tsx | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/phone/src/apps/notes/NotesApp.tsx b/phone/src/apps/notes/NotesApp.tsx index 30563a9..8a880e8 100644 --- a/phone/src/apps/notes/NotesApp.tsx +++ b/phone/src/apps/notes/NotesApp.tsx @@ -15,8 +15,6 @@ import { useNoteDetail } from './hooks/useNoteDetail'; import useStyles from './notes.styles'; import InjectDebugData from '../../os/debug/InjectDebugData'; -import { useSnackbar } from '../../ui/hooks/useSnackbar'; -import { useTranslation } from 'react-i18next'; InjectDebugData([ { diff --git a/phone/src/ui/components/SnackbarProvider.tsx b/phone/src/ui/components/SnackbarProvider.tsx index 17dc955..40a6b03 100644 --- a/phone/src/ui/components/SnackbarProvider.tsx +++ b/phone/src/ui/components/SnackbarProvider.tsx @@ -2,7 +2,7 @@ import React, { createContext, useState, useEffect, useRef } from 'react'; import { IAlert } from '../hooks/useSnackbar'; -export const SnackbarContext = createContext({ addAlert: (a: IAlert) => {} }); +export const SnackbarContext = createContext(null); function SnackbarProvider({ children }) { const [alert, setAlert] = useState(null); @@ -13,7 +13,7 @@ function SnackbarProvider({ children }) { clearTimeout(timer.current) timer.current = setTimeout(() => { setAlert(null) - }, 2500); + }, 1000); } return () => clearTimeout(timer.current) }, [alert]); From 92c7a352def5d69510642ad2a6e883600f16f92b Mon Sep 17 00:00:00 2001 From: Christopher Date: Sun, 14 Feb 2021 13:58:01 +0100 Subject: [PATCH 26/30] feat(notes/server): use new alert --- resources/server/sv_notes.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/resources/server/sv_notes.ts b/resources/server/sv_notes.ts index 3824a9d..053e36a 100644 --- a/resources/server/sv_notes.ts +++ b/resources/server/sv_notes.ts @@ -37,7 +37,7 @@ onNet(events.NOTE_ADD_NOTE, async (note: Note) => { } catch (error) { const pSource = (global as any).source - emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_ADD_FAILED') + emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_ADD_FAILED', type: 'error' }) } }); @@ -59,11 +59,11 @@ onNet(events.NOTE_DELETE_NOTE, async (noteId: NoteId) => { const _identifier = await useIdentifier(); await deleteNote(noteId.id, _identifier); - emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_DELETE_SUCCESS') - + emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_DELETE_SUCCESS', type: 'success' }) + } catch (error) { const pSource = (global as any).source; - emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_DELETE_FAILED') + emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_DELETE_FAILED', type: 'error' }) } }); @@ -73,11 +73,12 @@ onNet(events.NOTE_UPDATE_NOTE, async (note: Note) => { const _identifier = await useIdentifier(); await updateNote(note, _identifier); emitNet(events.NOTE_UPDATE_NOTE_SUCCESS, pSource); - emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_UPDATE_SUCCESS') + emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_UPDATE_SUCCESS', type: 'success' }) } catch (error) { const pSource = (global as any).source; emitNet(events.NOTE_UPDATE_NOTE_FAILURE, pSource); + emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_UPDATE_FAILED', type: 'error' }) } }); From 5efd9aa1f014931bc0b6370eef3432348709426b Mon Sep 17 00:00:00 2001 From: Christopher Date: Sun, 14 Feb 2021 14:06:51 +0100 Subject: [PATCH 27/30] removed unused variables --- phone/src/ui/components/SnackbarProvider.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/phone/src/ui/components/SnackbarProvider.tsx b/phone/src/ui/components/SnackbarProvider.tsx index 40a6b03..46ce55c 100644 --- a/phone/src/ui/components/SnackbarProvider.tsx +++ b/phone/src/ui/components/SnackbarProvider.tsx @@ -1,6 +1,4 @@ import React, { createContext, useState, useEffect, useRef } from 'react'; -import { IAlert } from '../hooks/useSnackbar'; - export const SnackbarContext = createContext(null); From 990ebedc080da00f7359349cf76eed13ddf5f1c9 Mon Sep 17 00:00:00 2001 From: RockySouthpaw <55056068+RockySouthpaw@users.noreply.github.com> Date: Sun, 14 Feb 2021 12:52:47 -0500 Subject: [PATCH 28/30] update discord URL --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2f39e73..dfad00a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # New Phone Who Dis ### Project Error Discord -Join the [Discord](discord.gg/YWJY36EVsm) to follow current development of the project. +Join the [Discord](discord.gg/HYwBjTbAY5) to follow current development of the project. ### Production Server Installation **(WIP)** From 7bafa7d5185849479f7c1f0278595b77e6611e35 Mon Sep 17 00:00:00 2001 From: J Francisco Rader Date: Sun, 14 Feb 2021 13:40:57 -0500 Subject: [PATCH 29/30] I make phone work (#89) --- .../components/views/ContactsPage.tsx | 2 -- .../apps/example/components/ExampleApp.tsx | 4 +--- phone/src/apps/notes/NotesApp.tsx | 22 +++++++++---------- phone/src/apps/notes/hooks/useNotesService.ts | 6 ++--- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/phone/src/apps/contacts/components/views/ContactsPage.tsx b/phone/src/apps/contacts/components/views/ContactsPage.tsx index 49644c6..0694239 100644 --- a/phone/src/apps/contacts/components/views/ContactsPage.tsx +++ b/phone/src/apps/contacts/components/views/ContactsPage.tsx @@ -2,7 +2,6 @@ import React from 'react'; import { ContactList } from '../List/ContactList'; import Fab from '@material-ui/core/Fab'; import PersonAddIcon from '@material-ui/icons/PersonAdd'; -import { ContactAlert } from '../alert/ContactAlert'; import { useHistory } from 'react-router-dom'; import { makeStyles, Theme } from '@material-ui/core/styles'; @@ -33,7 +32,6 @@ export const ContactPage = () => { > - ); }; diff --git a/phone/src/apps/example/components/ExampleApp.tsx b/phone/src/apps/example/components/ExampleApp.tsx index a5c3dc1..ca6e58e 100644 --- a/phone/src/apps/example/components/ExampleApp.tsx +++ b/phone/src/apps/example/components/ExampleApp.tsx @@ -1,12 +1,9 @@ import React from 'react'; import { AppWrapper } from '../../../ui/components'; -import { AppTitle } from '../../../ui/components/AppTitle'; import { AppContent } from '../../../ui/components/AppContent'; import { useApp } from '../../../os/apps/hooks/useApps'; import { useExample } from '../hooks/useExample'; -import { useSnackbar } from '../../../ui/hooks/useSnackbar'; -import SnackbarProvider from '../../../ui/components/SnackbarProvider'; export const ExampleApp = () => { // calling the example hook, and we assign the value to a variable @@ -17,6 +14,7 @@ export const ExampleApp = () => {

This is an example

+

{example.id}

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

{exampleString}

diff --git a/phone/src/apps/notes/NotesApp.tsx b/phone/src/apps/notes/NotesApp.tsx index 8a880e8..face916 100644 --- a/phone/src/apps/notes/NotesApp.tsx +++ b/phone/src/apps/notes/NotesApp.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React from 'react'; import { AppWrapper } from '../../ui/components/AppWrapper'; import { AppContent } from '../../ui/components/AppContent'; import { AppTitle } from '../../ui/components/AppTitle'; @@ -32,7 +32,7 @@ InjectDebugData([ content: 'Hello, this is another shitty note', }, ], - } + }, ]); export const NotesApp = () => { @@ -56,15 +56,15 @@ export const NotesApp = () => { - - + className={classes.absolute} + onClick={handleModal} + style={{ + background: '#f9a825', + color: '#fff', + }} + > + +
); }; diff --git a/phone/src/apps/notes/hooks/useNotesService.ts b/phone/src/apps/notes/hooks/useNotesService.ts index dfe627b..88156b8 100644 --- a/phone/src/apps/notes/hooks/useNotesService.ts +++ b/phone/src/apps/notes/hooks/useNotesService.ts @@ -1,5 +1,3 @@ - -import { createContext, useCallback } from 'react'; import { useSetRecoilState } from 'recoil'; import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; import { useNotes } from './useNotes'; @@ -7,10 +5,10 @@ import { noteStates } from './state'; import { useSnackbar } from '../../../ui/hooks/useSnackbar'; export const useNotesService = () => { - const { addAlert } = useSnackbar() + const { addAlert } = useSnackbar(); const setNotes = useSetRecoilState(noteStates.noteItems); useNuiEvent('NOTES', 'setNotes', setNotes); - useNuiEvent('NOTES', 'setAlert', addAlert) + useNuiEvent('NOTES', 'setAlert', addAlert); return useNotes(); }; From 001f1425dff58e688d637aceb49cff9adc061479 Mon Sep 17 00:00:00 2001 From: Darrian Gaylor Date: Sun, 14 Feb 2021 14:17:07 -0500 Subject: [PATCH 30/30] Fix phone not opening with keybind --- resources/client/cl_main.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/client/cl_main.ts b/resources/client/cl_main.ts index 37b9dd2..15d65e8 100644 --- a/resources/client/cl_main.ts +++ b/resources/client/cl_main.ts @@ -30,7 +30,7 @@ RegisterCommand( ); RegisterCommand( - '+phone', + 'phone', async () => { //-- Toggles Phone await Phone(); @@ -46,7 +46,7 @@ RegisterCommand( false ); -RegisterKeyMapping('+phone', 'Open Phone', 'keyboard', 'f1'); +RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1'); /* * * * * * * * * * * * * *