mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
Feat(Contacts): Mapping contacts from DB
This commit is contained in:
1 parent
9e8442491b
commit
3a213ea308
9 files changed
+110
-83
No files matched your search
+58
-41
@@ -16,19 +16,39 @@ import { useSimcardService } from "./os/simcard/hooks/useSimcardService";
|
|||||||
import { usePhoneService } from "./os/phone/hooks/usePhoneService";
|
import { usePhoneService } from "./os/phone/hooks/usePhoneService";
|
||||||
import { useApps } from "./os/apps/hooks/useApps";
|
import { useApps } from "./os/apps/hooks/useApps";
|
||||||
|
|
||||||
|
import { useContactsService } from "./apps/contacts/hooks/useContactsService";
|
||||||
|
|
||||||
// @TODO: Remove this testing shit
|
// @TODO: Remove this testing shit
|
||||||
// Used for testing NUI events while we work on clientside
|
// Used for testing NUI events while we work on clientside
|
||||||
setTimeout(() => {
|
//setTimeout(() => {
|
||||||
window.dispatchEvent(
|
// window.dispatchEvent(
|
||||||
new MessageEvent("message", {
|
// new MessageEvent("message", {
|
||||||
data: {
|
// data: {
|
||||||
app: "SIMCARD",
|
// app: "SIMCARD",
|
||||||
method: "setNumber",
|
// method: "setNumber",
|
||||||
data: "111-1111",
|
// data: "111-1134",
|
||||||
},
|
// },
|
||||||
})
|
// })
|
||||||
);
|
// );
|
||||||
}, 1000);
|
//}, 1000);
|
||||||
|
|
||||||
|
//setTimeout(() => {
|
||||||
|
// window.dispatchEvent(
|
||||||
|
// new MessageEvent("message", {
|
||||||
|
// data: {
|
||||||
|
// app: "BANK",
|
||||||
|
// method: "setContacts",
|
||||||
|
// data: [
|
||||||
|
// {
|
||||||
|
// id: 1,
|
||||||
|
// number: '345-4366',
|
||||||
|
// display: 'Kevin'
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// },
|
||||||
|
// })
|
||||||
|
// );
|
||||||
|
//}, 1000);
|
||||||
|
|
||||||
//setTimeout(() => {
|
//setTimeout(() => {
|
||||||
// window.dispatchEvent(
|
// window.dispatchEvent(
|
||||||
@@ -36,7 +56,7 @@ setTimeout(() => {
|
|||||||
// data: {
|
// data: {
|
||||||
// app: "PHONE",
|
// app: "PHONE",
|
||||||
// method: "setVisibility",
|
// method: "setVisibility",
|
||||||
// data: true,
|
// data: false,
|
||||||
// },
|
// },
|
||||||
// })
|
// })
|
||||||
// );
|
// );
|
||||||
@@ -44,24 +64,17 @@ setTimeout(() => {
|
|||||||
|
|
||||||
function Phone() {
|
function Phone() {
|
||||||
useNuiService();
|
useNuiService();
|
||||||
const { visibility, powerOff } = usePhoneService();
|
const { visibility } = usePhoneService();
|
||||||
const { settings, currentTheme } = useSettings();
|
const { settings, currentTheme } = useSettings();
|
||||||
const { allApps } = useApps();
|
const { allApps } = useApps();
|
||||||
useSimcardService();
|
useSimcardService();
|
||||||
|
useContactsService();
|
||||||
useInitKeyboard();
|
useInitKeyboard();
|
||||||
|
|
||||||
if (visibility === false) {
|
if (visibility === false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const screenStyle = powerOff
|
|
||||||
? {
|
|
||||||
backgroundColor: "black",
|
|
||||||
}
|
|
||||||
: {
|
|
||||||
backgroundImage: `url(${process.env.PUBLIC_URL}/media/backgrounds/${settings.wallpaper})`,
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ThemeProvider theme={currentTheme()}>
|
<ThemeProvider theme={currentTheme()}>
|
||||||
<div className="PhoneWrapper">
|
<div className="PhoneWrapper">
|
||||||
@@ -73,26 +86,30 @@ function Phone() {
|
|||||||
backgroundImage: `url(${process.env.PUBLIC_URL}/media/frames/${settings.frame})`,
|
backgroundImage: `url(${process.env.PUBLIC_URL}/media/frames/${settings.frame})`,
|
||||||
}}
|
}}
|
||||||
></div>
|
></div>
|
||||||
<div id="phone" className="PhoneScreen" style={screenStyle}>
|
<div
|
||||||
{!powerOff && (
|
id="phone"
|
||||||
<>
|
className="PhoneScreen"
|
||||||
<NotificationBar
|
style={{
|
||||||
notifications={[
|
backgroundImage: `${process.env.PUBLIC_URL}url(/media/backgrounds/${settings.wallpaper})`,
|
||||||
{
|
}}
|
||||||
key: "newMessage",
|
>
|
||||||
icon: <NotificationIcon Icon={MessageIcon} />,
|
<>
|
||||||
},
|
<NotificationBar
|
||||||
]}
|
notifications={[
|
||||||
/>
|
{
|
||||||
<div className="PhoneAppContainer">
|
key: "newMessage",
|
||||||
<Route exact path="/" component={HomeApp} />
|
icon: <NotificationIcon Icon={MessageIcon} />,
|
||||||
{allApps.map((App) => (
|
},
|
||||||
<App.Route key={App.id} />
|
]}
|
||||||
))}
|
/>
|
||||||
</div>
|
<div className="PhoneAppContainer">
|
||||||
<Navigation />
|
<Route exact path="/" component={HomeApp} />
|
||||||
</>
|
{allApps.map((App) => (
|
||||||
)}
|
<App.Route key={App.id} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<Navigation />
|
||||||
|
</>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,20 +6,19 @@ import PhoneIcon from "@material-ui/icons/Phone";
|
|||||||
import ChatIcon from "@material-ui/icons/Chat";
|
import ChatIcon from "@material-ui/icons/Chat";
|
||||||
import { List } from "../../../ui/components/List";
|
import { List } from "../../../ui/components/List";
|
||||||
import { ListItem } from "../../../ui/components/ListItem";
|
import { ListItem } from "../../../ui/components/ListItem";
|
||||||
|
import { useContacts } from "../hooks/useContacts";
|
||||||
|
|
||||||
export const ContactList = ({ contacts, onCall, onMessage }) => {
|
export const ContactList = () => {
|
||||||
|
const contacts = useContacts();
|
||||||
return (
|
return (
|
||||||
<List>
|
<List>
|
||||||
{contacts.map((contact) => (
|
{contacts.contacts.map((contact) => (
|
||||||
<ListItem key={contact.id} divider>
|
<ListItem key={contact.id} divider>
|
||||||
<ListItemText
|
<ListItemText primary={contact.display} secondary={contact.number} />
|
||||||
primary={contact.display}
|
<Button>
|
||||||
secondary={contact.phoneNumber}
|
|
||||||
/>
|
|
||||||
<Button onClick={() => onCall(contact.display)}>
|
|
||||||
<PhoneIcon />
|
<PhoneIcon />
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={onMessage}>
|
<Button>
|
||||||
<ChatIcon />
|
<ChatIcon />
|
||||||
</Button>
|
</Button>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
|||||||
@@ -2,22 +2,16 @@ import React from "react";
|
|||||||
import { AppWrapper } from "../../../ui/components";
|
import { AppWrapper } from "../../../ui/components";
|
||||||
import { AppTitle } from "../../../ui/components/AppTitle";
|
import { AppTitle } from "../../../ui/components/AppTitle";
|
||||||
import { AppContent } from "../../../ui/components/AppContent";
|
import { AppContent } from "../../../ui/components/AppContent";
|
||||||
import { useContacts } from "../hooks/useContacts";
|
|
||||||
import { ContactList } from "./ContactList";
|
import { ContactList } from "./ContactList";
|
||||||
import { useApp } from "../../../os/apps/hooks/useApps";
|
import { useApp } from "../../../os/apps/hooks/useApps";
|
||||||
|
|
||||||
export const ContactsApp = () => {
|
export const ContactsApp = () => {
|
||||||
const { contactList } = useContacts();
|
|
||||||
const contacts = useApp("CONTACTS");
|
const contacts = useApp("CONTACTS");
|
||||||
return (
|
return (
|
||||||
<AppWrapper>
|
<AppWrapper>
|
||||||
<AppTitle app={contacts} />
|
<AppTitle app={contacts} />
|
||||||
<AppContent>
|
<AppContent>
|
||||||
<ContactList
|
<ContactList />
|
||||||
contacts={contactList}
|
|
||||||
onCall={(contact) => console.log(contact)}
|
|
||||||
onMessage={() => console.log("Opening messages")}
|
|
||||||
/>
|
|
||||||
</AppContent>
|
</AppContent>
|
||||||
</AppWrapper>
|
</AppWrapper>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { atom } from "recoil";
|
||||||
|
|
||||||
|
export const contactsState = {
|
||||||
|
contacts: atom({
|
||||||
|
key: "contactsList",
|
||||||
|
default: [],
|
||||||
|
}),
|
||||||
|
};
|
||||||
@@ -1,22 +1,28 @@
|
|||||||
import { useRecoilState, atom } from "recoil";
|
import { useRecoilValue } from "recoil";
|
||||||
|
import { contactsState } from "./state";
|
||||||
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 = () => {
|
export const useContacts = () => {
|
||||||
const [contactList, setContactList] = useRecoilState(contactListState);
|
const contacts = useRecoilValue(contactsState.contacts);
|
||||||
return { contactList, setContactList };
|
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();
|
||||||
|
};
|
||||||
@@ -5,8 +5,4 @@ export const phoneState = {
|
|||||||
key: "phoneVisibility",
|
key: "phoneVisibility",
|
||||||
default: false,
|
default: false,
|
||||||
}),
|
}),
|
||||||
powerOff: atom({
|
|
||||||
key: "phonePowerOff",
|
|
||||||
default: true,
|
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
@@ -3,6 +3,5 @@ import { phoneState } from "./state";
|
|||||||
|
|
||||||
export const usePhone = () => {
|
export const usePhone = () => {
|
||||||
const visibility = useRecoilValue(phoneState.visibility);
|
const visibility = useRecoilValue(phoneState.visibility);
|
||||||
const powerOff = useRecoilValue(phoneState.powerOff);
|
return { visibility };
|
||||||
return { visibility, powerOff };
|
|
||||||
};
|
};
|
||||||
@@ -5,8 +5,6 @@ import { usePhone } from "./usePhone";
|
|||||||
|
|
||||||
export const usePhoneService = () => {
|
export const usePhoneService = () => {
|
||||||
const setVisibility = useSetRecoilState(phoneState.visibility);
|
const setVisibility = useSetRecoilState(phoneState.visibility);
|
||||||
const setPowerOff = useSetRecoilState(phoneState.powerOff);
|
|
||||||
useNuiEvent("PHONE", "setPowerOff", setPowerOff);
|
|
||||||
useNuiEvent("PHONE", "setVisibility", setVisibility);
|
useNuiEvent("PHONE", "setVisibility", setVisibility);
|
||||||
return usePhone();
|
return usePhone();
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user