Feat(Contacts): Mapping contacts from DB

This commit is contained in:
chip committed 2020-08-27 23:40:37 +02:00
1 parent 9e8442491b
commit 3a213ea308
9 files changed
+110 -83

No files matched your search

@@ -6,20 +6,19 @@ 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";
export const ContactList = ({ contacts, onCall, onMessage }) => {
export const ContactList = () => {
const contacts = useContacts();
return (
<List>
{contacts.map((contact) => (
{contacts.contacts.map((contact) => (
<ListItem key={contact.id} divider>
<ListItemText
primary={contact.display}
secondary={contact.phoneNumber}
/>
<Button onClick={() => onCall(contact.display)}>
<ListItemText primary={contact.display} secondary={contact.number} />
<Button>
<PhoneIcon />
</Button>
<Button onClick={onMessage}>
<Button>
<ChatIcon />
</Button>
</ListItem>
@@ -2,22 +2,16 @@ import React from "react";
import { AppWrapper } from "../../../ui/components";
import { AppTitle } from "../../../ui/components/AppTitle";
import { AppContent } from "../../../ui/components/AppContent";
import { useContacts } from "../hooks/useContacts";
import { ContactList } from "./ContactList";
import { useApp } from "../../../os/apps/hooks/useApps";
export const ContactsApp = () => {
const { contactList } = useContacts();
const contacts = useApp("CONTACTS");
return (
<AppWrapper>
<AppTitle app={contacts} />
<AppContent>
<ContactList
contacts={contactList}
onCall={(contact) => console.log(contact)}
onMessage={() => console.log("Opening messages")}
/>
<ContactList />
</AppContent>
</AppWrapper>
);
+8
View File
@@ -0,0 +1,8 @@
import { atom } from "recoil";
export const contactsState = {
contacts: atom({
key: "contactsList",
default: [],
}),
};
+25 -19
View File
@@ -1,22 +1,28 @@
import { useRecoilState, atom } from "recoil";
const contactListState = atom({
key: "contactList",
default: [
{
id: 0,
display: "Test Contact",
phoneNumber: "000-1111",
},
{
id: 1,
display: "Test Contact 2",
phoneNumber: "000-1112",
},
],
});
import { useRecoilValue } from "recoil";
import { contactsState } from "./state";
export const useContacts = () => {
const [contactList, setContactList] = useRecoilState(contactListState);
return { contactList, setContactList };
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 };
//};
@@ -0,0 +1,10 @@
import { useNuiEvent } from "../../../os/nui-events/hooks/useNuiEvent";
import { useSetRecoilState } from "recoil";
import { contactsState } from "./state";
import { useContacts } from "./useContacts";
export const useContactsService = () => {
const setContacts = useSetRecoilState(contactsState.contacts);
useNuiEvent("BANK", "setContacts", setContacts);
return useContacts();
};