Feat(Contacts | Components): Contact modal | Input compoent | New dependency

This commit is contained in:
chip committed 2020-09-01 21:37:53 +02:00
1 parent 0312d2c4a6
commit dde1bd6931
8 files changed
+245 -72

No files matched your search

@@ -15,10 +15,18 @@ export const ContactList = () => {
{contacts.contacts.map((contact) => (
<ListItem key={contact.id} divider>
<ListItemText primary={contact.display} secondary={contact.number} />
<Button>
<Button
onClick={() =>
console.log("Call: " + contact.display, contact.number)
}
>
<PhoneIcon />
</Button>
<Button>
<Button
onClick={() =>
console.log("Message: " + contact.display, contact.number)
}
>
<ChatIcon />
</Button>
</ListItem>
@@ -0,0 +1,103 @@
import React, { useState } from "react";
import { makeStyles } from "@material-ui/core/styles";
import AddCircleIcon from "@material-ui/icons/AddCircle";
import { AppContent } from "../../../ui/components/AppContent";
import { Container, Button } from "@material-ui/core";
import Nui from "../../../os/nui-events/utils/Nui";
import { TextInput } from "../../../ui/components/Input";
const useStyles = makeStyles((theme) => ({
modal: {
display: "flex",
alignItems: "center",
justifyContent: "center",
},
paper: {
backgroundColor: theme.palette.background.paper,
boxShadow: theme.shadows[5],
padding: theme.spacing(2, 4, 3),
},
modalContainer: {
backgroundColor: "#232323",
width: "80%",
height: "30vh",
},
button: {
margin: 5,
marginTop: 20,
},
}));
export const AddContactModal = () => {
const [modal, setModal] = useState(false);
const Modal = (props) => {
const [name, setName] = useState("");
const [number, setNumber] = useState("");
const addContact = () => {
if (name === "" || number === "") {
console.log("You need to pass in values");
} else {
Nui.send("contacts:add", {
name,
number,
});
console.log(name, number);
}
};
const classes = useStyles();
return (
<Container
fixed
className={classes.modalContainer}
style={{
visibility: props.show ? "visible" : "hidden",
}}
>
<h2 style={{ textAlign: "center" }}>New contact:</h2>
<TextInput
style={{ display: "flex" }}
placeholder="Name"
value={name}
onChange={(e) => setName(e.target.value)}
/>
<TextInput
style={{ display: "flex" }}
placeholder="Phone number"
value={number}
onChange={(e) => setNumber(e.target.value)}
id="number-basic"
type="number"
label="Phone Number"
color="primary"
/>
<Button
onClick={addContact}
variant="contained"
style={{ backgroundColor: "#fff", color: "#000" }}
className={classes.button}
>
Add
</Button>
<Button
onClick={() => setModal(false)}
variant="contained"
style={{ backgroundColor: "#c0392b", color: "#fff" }}
className={classes.button}
>
Cancel
</Button>
</Container>
);
};
return (
<AppContent>
<Button fullWidth onClick={() => setModal(true)}>
<AddCircleIcon />
</Button>
<Modal show={modal} />
</AppContent>
);
};
@@ -4,8 +4,7 @@ import { AppTitle } from "../../../ui/components/AppTitle";
import { AppContent } from "../../../ui/components/AppContent";
import { ContactList } from "./ContactList";
import { useApp } from "../../../os/apps/hooks/useApps";
import { Button } from "../../../ui/components/Button";
import AddCircleIcon from "@material-ui/icons/AddCircle";
import { AddContactModal } from "./ContactModal";
export const ContactsApp = () => {
const contacts = useApp("CONTACTS");
@@ -14,9 +13,7 @@ export const ContactsApp = () => {
<AppTitle app={contacts} />
<AppContent>
<ContactList />
<Button fullWidth>
<AddCircleIcon />
</Button>
<AddContactModal />
</AppContent>
</AppWrapper>
);
@@ -5,24 +5,3 @@ export const useContacts = () => {
const contacts = useRecoilValue(contactsState.contacts);
return { contacts };
};
//const contactListState = atom({
// key: "contactList",
// default: [
// {
// id: 0,
// display: "Test Contact",
// phoneNumber: "000-1111",
// },
// {
// id: 1,
// display: "Test Contact 2",
// phoneNumber: "000-1112",
// },
// ],
//});
//
//export const useContacts = () => {
// const [contactList, setContactList] = useRecoilState//(contactListState);
// return { contactList, setContactList };
//};