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; +}