Merge pull request #11 from Re-Ignited-Development/tweak/contacts-app

Tweak/contacts app
This commit is contained in:
Christopher Gjelten authored and GitHub committed 2020-10-16 20:21:23 +02:00
commit 9d7430f573
15 files changed
+399 -134

No files matched your search

+3
View File
@@ -6,11 +6,13 @@
"@babel/polyfill": "^7.4.4",
"@fortawesome/fontawesome-free": "^5.15.1",
"@fortawesome/fontawesome-svg-core": "^1.2.32",
"@fortawesome/free-brands-svg-icons": "^5.15.1",
"@fortawesome/free-solid-svg-icons": "^5.15.1",
"@fortawesome/react-fontawesome": "^0.1.11",
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.56",
"@popperjs/core": "^2.5.3",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
@@ -26,6 +28,7 @@
"react-dom": "^16.13.1",
"react-hotkeys": "^2.0.0",
"react-i18next": "^11.7.1",
"react-popper": "^2.2.3",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.3",
"recoil": "^0.0.10",
+11 -3
View File
@@ -43,12 +43,20 @@ setTimeout(() => {
{
id: 1,
number: "345-4366",
display: "Kevin",
display: "Gjelten",
img: 'https://i.imgur.com/Qpw6j8D.png'
},
{
id: 2,
number: "345-4366",
display: "Kevin",
number: "456-4366",
display: "Loyd",
img: ''
},
{
id: 3,
number: "123-4366",
display: "Fabian",
img: 'https://i.imgur.com/B8ta5Aa.jpeg'
},
],
},
@@ -1,10 +0,0 @@
.display-block {
/*Sets modal to center*/
display: flex;
justify-content: center;
align-items: center;
}
.display-none {
display: none;
}
@@ -1,46 +0,0 @@
import React from "react";
import ListItemText from "@material-ui/core/ListItemText";
import { Button } from "@material-ui/core";
import PhoneIcon from "@material-ui/icons/Phone";
import ChatIcon from "@material-ui/icons/Chat";
import DeleteIcon from "@material-ui/icons/Delete";
import { List } from "../../../ui/components/List";
import { ListItem } from "../../../ui/components/ListItem";
import { useContacts } from "../hooks/useContacts";
import Nui from "../../../os/nui-events/utils/Nui";
export const ContactList = () => {
const contacts = useContacts();
const startCall = (number) => {
console.log(number);
Nui.send("phone:startCall", {
number,
});
};
return (
<List>
{contacts.contacts.map((contact) => (
<ListItem key={contact.id} divider>
<ListItemText primary={contact.display} secondary={contact.number} />
<Button onClick={() => startCall(contact.number)}>
<PhoneIcon />
</Button>
<Button
onClick={() =>
console.log("Message: " + contact.display, contact.number)
}
>
<ChatIcon />
</Button>
<Button>
<DeleteIcon />
</Button>
</ListItem>
))}
</List>
);
};
@@ -1,11 +1,18 @@
import React, { useState } from "react";
import { makeStyles } from "@material-ui/core/styles";
import { Button, TextField, Paper } from "@material-ui/core";
import { makeStyles, Theme } from "@material-ui/core/styles";
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 ClearIcon from '@material-ui/icons/Clear';
import PersonIcon from '@material-ui/icons/Person';
import PhoneIcon from '@material-ui/icons/Phone';
import AccountCircleIcon from '@material-ui/icons/AccountCircle';
const useStyles = makeStyles((theme) => ({
const useStyles = makeStyles((theme: Theme) => ({
button: {
margin: 5,
marginTop: 20,
@@ -18,23 +25,42 @@ const useStyles = makeStyles((theme) => ({
marginLeft: "-4em",
height: "20%",
},
displayBlock: {
/*Sets modal to center*/
display: "flex",
justifyContent: "center",
alignItems: "center",
clearButton: {
width: '10%',
position: 'absolute',
right: 0
},
displayNone: {
display: "none",
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 const AddContactModal = ({ handleClose, show }) => {
export const AddContactModal = () => {
const [name, setName] = useState("");
const [number, setNumber] = useState("");
const [avatar, setAvatar] = useState("");
const classes = useStyles();
const showHideClassName = show ? classes.displayBlock : classes.displayNone;
const { showModal, setShowModal } = useModal();
const addContact = () => {
if (name === "" || number === "") {
@@ -43,37 +69,57 @@ export const AddContactModal = ({ handleClose, show }) => {
Nui.send("contacts:add", {
name,
number,
avatar
});
console.log(name, number);
console.log(name, number, avatar);
}
};
const _handleClose = () => {
setShowModal(false)
}
return (
<div className={showHideClassName}>
<Paper className={classes.root}>
<List>
<ListItem>
<TextField
value={name}
onChange={(e) => setName(e.target.value)}
style={{ fontSize: "18px" }}
fullWidth
placeholder="Name"
/>
</ListItem>
<ListItem>
<TextField
value={number}
onChange={(e) => setNumber(e.target.value)}
fullWidth
placeholder="Number"
type="number"
/>
</ListItem>
<Modal visible={showModal} handleClose={_handleClose}>
<Button onClick={_handleClose} className={classes.clearButton}><ClearIcon /></Button>
<List style={{ marginTop: 30 }}>
<ListItem>
<PersonIcon className={classes.icons} />
<TextField
value={name}
inputProps={{ className: classes.textInputField}}
onChange={(e) => setName(e.target.value)}
fullWidth
variant="standard"
placeholder="Name"
/>
</ListItem>
<ListItem>
<PhoneIcon className={classes.icons} />
<TextField
value={number}
inputProps={{ className: classes.textInputField}}
onChange={(e) => setNumber(e.target.value)}
fullWidth
placeholder="Number"
variant="standard"
type="number"
/>
</ListItem>
<ListItem>
<AccountCircleIcon className={classes.icons} />
<TextField
value={avatar}
inputProps={{ className: classes.textInputField}}
onChange={(e) => setAvatar(e.target.value)}
fullWidth
placeholder="Avatar URL"
variant="standard"
type="text"
/>
</ListItem>
</List>
<Button onClick={addContact}>Add</Button>
<Button onClick={handleClose}>Close</Button>
</Paper>
</div>
<Button className={classes.addBtn} onClick={addContact}>Add Contact</Button>
</Modal>
);
};
@@ -0,0 +1,32 @@
import React from 'react'
import { makeStyles, createStyles, Theme } from "@material-ui/core/styles";
import Paper from "@material-ui/core/Paper";
import ContactsIcon from "@material-ui/icons/Contacts";
const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
height: "60px",
width: "100%",
display: "flex",
flexFlow: "row nowrap",
justifyContent: "center",
alignItems: "center",
background: "#424242",
},
icon: {
color: "#fff",
fontSize: 30,
},
})
);
export const ContactTitle = () => {
const classes = useStyles();
return (
<Paper className={classes.root} square variant="outlined" elevation={24}>
<ContactsIcon className={classes.icon} />
</Paper>
)
}
@@ -1,38 +1,60 @@
import React, { useState } from "react";
import React from "react";
import { AppWrapper } from "../../../ui/components";
import { makeStyles, createStyles, Theme } from "@material-ui/core/styles";
import { AppTitle } from "../../../ui/components/AppTitle";
import { AppContent } from "../../../ui/components/AppContent";
import { ContactList } from "./ContactList";
import { ContactList } from "./List/ContactList";
import { useApp } from "../../../os/apps/hooks/useApps";
import AddCircleIcon from "@material-ui/icons/AddCircle";
import { AddContactModal } from "./ContactModal";
import { Button } from "@material-ui/core";
import { useModal } from '../hooks/useModal';
import { SearchContacts } from "./List/SearchContacts";
import PersonAddIcon from '@material-ui/icons/PersonAdd'
import Fab from '@material-ui/core/Fab';
const useStyles = makeStyles((theme: Theme) =>
createStyles({
backgroundModal: {
background: "black",
opacity: "0.6",
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
zIndex: 5,
},
absolute: {
position: 'sticky',
bottom: theme.spacing(2),
left: theme.spacing(3),
},
})
);
export const ContactsApp = () => {
const [modal, setModal] = useState(false);
const classes = useStyles();
const { showModal, setShowModal } = useModal();
const contacts = useApp("CONTACTS");
const openModal = () => {
setModal(true);
setShowModal(true);
};
const closeModal = () => {
setModal(false);
};
return (
<AppWrapper>
<AppWrapper id="contact-app">
<AppTitle app={contacts}></AppTitle>
<Button
onClick={openModal}
variant="contained"
style={{ backgroundColor: "#232323" }}
>
<AddCircleIcon color="action" />
</Button>
<SearchContacts />
<AddContactModal/>
<div className={showModal ? classes.backgroundModal : undefined} />
<AppContent>
<AddContactModal show={modal} handleClose={closeModal} />
<ContactList />
<Fab onClick={openModal} style={{backgroundColor: '#2196f3', color: '#fff'}} className={classes.absolute}>
<PersonAddIcon />
</Fab>
</AppContent>
</AppWrapper>
);
@@ -0,0 +1,64 @@
import React from "react";
import ListItemText from "@material-ui/core/ListItemText";
import {
Button,
ListItemAvatar,
Avatar as MuiAvatar
} from "@material-ui/core";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faPen } from "@fortawesome/free-solid-svg-icons";
import { useFilteredContacts } from '../../hooks/useFilteredContacts';
import PhoneIcon from "@material-ui/icons/Phone";
import ChatIcon from "@material-ui/icons/Chat";
import { List } from "../../../../ui/components/List";
import { ListItem } from "../../../../ui/components/ListItem";
import { useContacts } from "../../hooks/useContacts";
import Nui from "../../../../os/nui-events/utils/Nui";
export const ContactList = () => {
const { filteredContacts } = useFilteredContacts();
const contacts = useContacts();
const startCall = (number) => {
console.log(number);
Nui.send("phone:startCall", {
number,
});
};
return (
<List>
{contacts.contacts.filter(contact => contact.display.includes(filteredContacts) || contact.number.includes(filteredContacts)).map((contact) => (
<ListItem key={contact.id} divider>
<ListItemAvatar>
{contact.img ? (
<MuiAvatar src={contact.img} />
): (
<MuiAvatar>{contact.display.slice(0, 1)}</MuiAvatar>
)}
</ListItemAvatar>
<ListItemText primary={contact.display} secondary={contact.number} />
<Button onClick={() => startCall(contact.number)}>
<PhoneIcon />
</Button>
<Button
onClick={() =>
console.log("Message: " + contact.display, contact.number)
}
>
<ChatIcon />
</Button>
<Button>
<FontAwesomeIcon icon={faPen} size="lg"/>
</Button>
</ListItem>
))}
</List>
);
};
@@ -0,0 +1,95 @@
import React, { useState } from 'react'
import { InputBase } from "@material-ui/core";
import SearchIcon from '@material-ui/icons/Search';
import { createStyles, fade, Theme, makeStyles } from '@material-ui/core/styles';
import { useFilteredContacts } from '../../hooks/useFilteredContacts';
const useStyles = makeStyles((theme: Theme) =>
createStyles({
bg: {
backgroundColor: "#232323",
display: 'flex',
height: 60,
justifyContent: 'center',
alignItems: 'center'
},
textFieldInput: {
fontSize: 20
},
inputRoot: {
color: '#fff',
fontSize: 18
},
inputInput: {
padding: theme.spacing(1, 4, 1, 4),
// vertical padding + font size from searchIcon
transition: theme.transitions.create('width'),
width: '100%',
[theme.breakpoints.up('sm')]: {
width: '13ch',
'&:focus': {
width: '20ch',
},
},
},
search: {
position: 'relative',
borderRadius: theme.shape.borderRadius,
backgroundColor: fade(theme.palette.common.white, 0.15),
'&:hover': {
backgroundColor: fade(theme.palette.common.white, 0.25),
},
marginLeft: 0,
width: '100%',
[theme.breakpoints.up('sm')]: {
marginLeft: theme.spacing(1),
width: 'auto',
},
},
searchIcon: {
padding: theme.spacing(0, 0.5),
height: '100%',
position: 'absolute',
pointerEvents: 'none',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
},
})
);
export const SearchContacts = () => {
const { setFilteredContacts } = useFilteredContacts();
const classes = useStyles();
const [ searchValue, setSearchValue ] = useState('')
const handleChange = (e) => {
setSearchValue(e.target.value)
setFilteredContacts(e.target.value)
}
return (
<div className={classes.bg}>
<div className={classes.search}>
<div className={classes.searchIcon}>
<SearchIcon style={{ color: '#fff' }} />
</div>
<InputBase
onChange={handleChange}
placeholder="Search contacts..."
classes={{
root: classes.inputRoot,
input: classes.inputInput
}}
inputProps={{ 'aria-label': 'search' }}
/>
</div>
</div>
)
}
+8
View File
@@ -5,4 +5,12 @@ export const contactsState = {
key: "contactsList",
default: [],
}),
showModal: atom({
key: 'showModal',
default: false
}),
filterContacts: atom({
key: 'filterContacts',
default: ""
})
};
@@ -5,6 +5,7 @@ interface Contact {
id: string;
display: string;
number: string;
img?: string
}
interface IUseContacts {
@@ -0,0 +1,7 @@
import { useRecoilState } from 'recoil';
import { contactsState } from './state';
export const useFilteredContacts = () => {
const [ filteredContacts, setFilteredContacts ] = useRecoilState(contactsState.filterContacts);
return { filteredContacts, setFilteredContacts };
}
@@ -0,0 +1,7 @@
import { useRecoilState } from 'recoil';
import { contactsState } from './state';
export const useModal = () => {
const [ showModal, setShowModal ] = useRecoilState(contactsState.showModal);
return { showModal, setShowModal };
}
+14 -18
View File
@@ -5,21 +5,17 @@ import {
common,
grey,
green,
orange,
purple,
red,
amber,
} from "@material-ui/core/colors";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faAd } from "@fortawesome/free-solid-svg-icons";
import { faAd, faPlaneArrival, faPhoneAlt, faLandmark } from "@fortawesome/free-solid-svg-icons";
import { faTwitter } from '@fortawesome/free-brands-svg-icons'
import ContactsIcon from "@material-ui/icons/Contacts";
import SettingsIcon from "@material-ui/icons/Settings";
import PhoneIcon from "@material-ui/icons/Phone";
import CalendarTodayIcon from "@material-ui/icons/CalendarToday";
import AccountBalanceIcon from "@material-ui/icons/AccountBalance";
import MessageIcon from "@material-ui/icons/Message";
import TwitterIcon from "@material-ui/icons/Twitter";
import { atom } from "recoil";
import { CalculatorIcon } from "../../../apps/calculator/components/CalculatorIcon";
import { Route } from "react-router-dom";
@@ -40,18 +36,18 @@ const appsState = atom({
{
id: "DIALER",
nameLocale: "APPS_DIALER",
icon: <PhoneIcon />,
backgroundColor: green[400],
color: green[50],
icon: <FontAwesomeIcon icon={faPhoneAlt} size="xs" />,
backgroundColor: green[600],
color: common.white,
path: "/phone",
Route: () => <Route path="/phone" component={DialerApp} />,
},
{
id: "MESSAGES",
nameLocale: "APPS_MESSAGES",
icon: <MessageIcon />,
backgroundColor: amber[400],
color: amber[50],
icon: <MessageIcon fontSize="default" />,
backgroundColor: amber[700],
color: common.white,
path: "/messages",
Route: () => <Route path="/messages" component={MessagesApp} />,
},
@@ -60,7 +56,7 @@ const appsState = atom({
nameLocale: "APPS_CONTACTS",
icon: <ContactsIcon />,
backgroundColor: blue[500],
color: blue[50],
color: common.white,
path: "/contacts",
Route: () => <Route path="/contacts" component={ContactsApp} />,
},
@@ -85,16 +81,16 @@ const appsState = atom({
{
id: "BANK",
nameLocale: "APPS_BANK",
icon: <AccountBalanceIcon />,
backgroundColor: orange[600],
color: orange[50],
icon: <FontAwesomeIcon icon={faLandmark} size="xs" />,
backgroundColor: blue[900],
color: common.white,
path: "/bank",
Route: () => <Route path="/bank" component={BankApp} />,
},
{
id: "TWITTER",
nameLocale: "APPS_TWITTER",
icon: <TwitterIcon />,
icon: <FontAwesomeIcon icon={faTwitter} fixedWidth size="xs"/>,
backgroundColor: blue[600],
color: common.white,
path: "/twitter",
@@ -112,7 +108,7 @@ const appsState = atom({
{
id: "EXAMPLE",
nameLocale: "APPS_EXAMPLE",
icon: <CalendarTodayIcon />,
icon: <FontAwesomeIcon icon={faPlaneArrival} size="sm" />,
backgroundColor: blue[500],
color: blue[50],
path: "/example",
+32
View File
@@ -1234,6 +1234,13 @@
dependencies:
"@fortawesome/fontawesome-common-types" "^0.2.32"
"@fortawesome/free-brands-svg-icons@^5.15.1":
version "5.15.1"
resolved "https://registry.yarnpkg.com/@fortawesome/free-brands-svg-icons/-/free-brands-svg-icons-5.15.1.tgz#1dc0563f4036639e53d24b8e532ea78a53ca2250"
integrity sha512-pkTZIWn7iuliCCgV+huDfZmZb2UjslalXGDA2PcqOVUYJmYL11y6ooFiMJkJvUZu+xgAc1gZgQe+Px12mZF0CA==
dependencies:
"@fortawesome/fontawesome-common-types" "^0.2.32"
"@fortawesome/free-solid-svg-icons@^5.15.1":
version "5.15.1"
resolved "https://registry.yarnpkg.com/@fortawesome/free-solid-svg-icons/-/free-solid-svg-icons-5.15.1.tgz#e1432676ddd43108b41197fee9f86d910ad458ef"
@@ -1544,6 +1551,11 @@
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b"
integrity sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==
"@popperjs/core@^2.5.3":
version "2.5.3"
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.5.3.tgz#4982b0b66b7a4cf949b86f5d25a8cf757d3cfd9d"
integrity sha512-RFwCobxsvZ6j7twS7dHIZQZituMIDJJNHS/qY6iuthVebxS3zhRY+jaC2roEKiAYaVuTcGmX6Luc6YBcf6zJVg==
"@sheerun/mutationobserver-shim@^0.3.2":
version "0.3.3"
resolved "https://registry.yarnpkg.com/@sheerun/mutationobserver-shim/-/mutationobserver-shim-0.3.3.tgz#5405ee8e444ed212db44e79351f0c70a582aae25"
@@ -9838,6 +9850,11 @@ react-error-overlay@^6.0.7:
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.7.tgz#1dcfb459ab671d53f660a991513cb2f0a0553108"
integrity sha512-TAv1KJFh3RhqxNvhzxj6LeT5NWklP6rDr2a0jaTfsZ5wSZWHOGeqQyejUp3xxLfPt2UpyJEcVQB/zyPcmonNFA==
react-fast-compare@^3.0.1:
version "3.2.0"
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.0.tgz#641a9da81b6a6320f270e89724fb45a0b39e43bb"
integrity sha512-rtGImPZ0YyLrscKI9xTpV8psd6I8VAtjKCzQDlzyDvqJA8XOW78TXYQwNRNd8g8JZnDu8q9Fu/1v4HPAVwVdHA==
react-hotkeys@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/react-hotkeys/-/react-hotkeys-2.0.0.tgz#a7719c7340cbba888b0e9184f806a9ec0ac2c53f"
@@ -9858,6 +9875,14 @@ react-is@^16.12.0, react-is@^16.13.1, react-is@^16.6.0, react-is@^16.7.0, react-
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
react-popper@^2.2.3:
version "2.2.3"
resolved "https://registry.yarnpkg.com/react-popper/-/react-popper-2.2.3.tgz#33d425fa6975d4bd54d9acd64897a89d904b9d97"
integrity sha512-mOEiMNT1249js0jJvkrOjyHsGvqcJd3aGW/agkiMoZk3bZ1fXN1wQszIQSjHIai48fE67+zwF8Cs+C4fWqlfjw==
dependencies:
react-fast-compare "^3.0.1"
warning "^4.0.2"
react-router-dom@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-5.2.0.tgz#9e65a4d0c45e13289e66c7b17c7e175d0ea15662"
@@ -11860,6 +11885,13 @@ walker@^1.0.7, walker@~1.0.5:
dependencies:
makeerror "1.0.x"
warning@^4.0.2:
version "4.0.3"
resolved "https://registry.yarnpkg.com/warning/-/warning-4.0.3.tgz#16e9e077eb8a86d6af7d64aa1e05fd85b4678ca3"
integrity sha512-rpJyN222KWIvHJ/F53XSZv0Zl/accqHR8et1kpaMTD/fLCRxtV8iX8czMzY7sVZupTI3zcUTg8eycS2kNF9l6w==
dependencies:
loose-envify "^1.0.0"
watchpack-chokidar2@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/watchpack-chokidar2/-/watchpack-chokidar2-2.0.0.tgz#9948a1866cbbd6cb824dea13a7ed691f6c8ddff0"