mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 14:38:45 +00:00
Merge pull request #26 from Re-Ignited-Development/wrap/contacts
Wrap up contact app
This commit is contained in:
12 files changed
+325
-81
No files matched your search
+1
-1
@@ -135,7 +135,7 @@ setTimeout(() => {
|
||||
id: 1,
|
||||
number: "345-4366",
|
||||
display: "chip",
|
||||
avatar: 'https://i.imgur.com/Qpw6j8D.png'
|
||||
avatar: 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Rotating_earth_%28large%29.gif/200px-Rotating_earth_%28large%29.gif'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
|
||||
@@ -8,9 +8,11 @@ import { useApp } from "../../../os/apps/hooks/useApps";
|
||||
import { AddContactModal } from "./ContactModal";
|
||||
import { useModal } from "../hooks/useModal";
|
||||
import { SearchContacts } from "./List/SearchContacts";
|
||||
import PersonAddIcon from '@material-ui/icons/PersonAdd'
|
||||
import Fab from '@material-ui/core/Fab';
|
||||
import { useContactModal } from '../hooks/useContactModal';
|
||||
import PersonAddIcon from "@material-ui/icons/PersonAdd";
|
||||
import Fab from "@material-ui/core/Fab";
|
||||
import { useContactModal } from "../hooks/useContactModal";
|
||||
import { InfoModal } from "./modal/InfoModal";
|
||||
import { useContactDetail } from "../hooks/useContactDetail";
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) =>
|
||||
createStyles({
|
||||
@@ -36,7 +38,7 @@ export const ContactsApp = () => {
|
||||
const classes = useStyles();
|
||||
const { showModal, setShowModal } = useModal();
|
||||
const contacts = useApp("CONTACTS");
|
||||
const { showContactModal } = useContactModal();
|
||||
const { contactDetail } = useContactDetail();
|
||||
|
||||
const openModal = () => {
|
||||
setShowModal(true);
|
||||
@@ -47,6 +49,7 @@ export const ContactsApp = () => {
|
||||
<AppTitle app={contacts}></AppTitle>
|
||||
<SearchContacts />
|
||||
<AddContactModal />
|
||||
<InfoModal key={contactDetail?.id} />
|
||||
<div className={showModal ? classes.backgroundModal : undefined} />
|
||||
<AppContent>
|
||||
<ContactList />
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import React from "react";
|
||||
import ListItemText from "@material-ui/core/ListItemText";
|
||||
import {
|
||||
Button,
|
||||
import {
|
||||
Button,
|
||||
ListItemAvatar,
|
||||
Avatar as MuiAvatar,
|
||||
List,
|
||||
ListItem,
|
||||
TextField,
|
||||
Collapse,
|
||||
makeStyles
|
||||
makeStyles,
|
||||
} from "@material-ui/core";
|
||||
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
@@ -18,39 +18,43 @@ import { useFilteredContacts } from "../../hooks/useFilteredContacts";
|
||||
|
||||
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 { useContactModal } from "../../hooks/useContactModal";
|
||||
import { useContactDetail } from "../../hooks/useContactDetail";
|
||||
|
||||
import Nui from "../../../../os/nui-events/utils/Nui";
|
||||
|
||||
import "../Contact.css"
|
||||
import "../Contact.css";
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
updateButton: {
|
||||
margin: 'auto',
|
||||
margin: "auto",
|
||||
fontSize: 14,
|
||||
width: 150,
|
||||
background: "#2196f3",
|
||||
marginBottom: 10,
|
||||
padding: 8
|
||||
padding: 8,
|
||||
},
|
||||
collapseItem: {
|
||||
margin: 'auto',
|
||||
width: '50%'
|
||||
}
|
||||
}))
|
||||
|
||||
margin: "auto",
|
||||
width: "50%",
|
||||
},
|
||||
}));
|
||||
|
||||
export const ContactList = () => {
|
||||
const classes = useStyles()
|
||||
const classes = useStyles();
|
||||
const { filteredContacts } = useFilteredContacts();
|
||||
const { showContactModal, setShowContactModal } = useContactModal();
|
||||
const { setShowContactModal } = useContactModal();
|
||||
const { contactDetail, setContactDetail } = useContactDetail();
|
||||
|
||||
const contacts = useContacts();
|
||||
|
||||
const openContactInfo = () => {
|
||||
setShowContactModal(!showContactModal);
|
||||
}
|
||||
const openContactInfo = (contact) => {
|
||||
setShowContactModal(true);
|
||||
setContactDetail(contact);
|
||||
console.log("CONTACT", contactDetail);
|
||||
};
|
||||
const startCall = (number) => {
|
||||
console.log(number);
|
||||
Nui.send("phone:startCall", {
|
||||
@@ -60,52 +64,47 @@ export const ContactList = () => {
|
||||
|
||||
return (
|
||||
<List>
|
||||
{contacts.contacts.filter(contact => contact.display.includes(filteredContacts) || contact.number.includes(filteredContacts)).map((contact) => (
|
||||
<>
|
||||
<ListItem key={contact.id} divider>
|
||||
<ListItemAvatar>
|
||||
{contact.avatar ? (
|
||||
<MuiAvatar src={contact.avatar} />
|
||||
): (
|
||||
<MuiAvatar>{contact.display.slice(0, 1).toUpperCase()}</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 onClick={openContactInfo}>
|
||||
<FontAwesomeIcon icon={faPen} size="lg"/>
|
||||
</Button>
|
||||
</ListItem>
|
||||
<Collapse in={showContactModal} timeout="auto" unmountOnExit>
|
||||
<List component="div" disablePadding>
|
||||
<ListItem className={classes.collapseItem}>
|
||||
<TextField
|
||||
value={contact.display}
|
||||
{contacts.contacts
|
||||
.filter(
|
||||
(contact) =>
|
||||
contact.display.includes(filteredContacts) ||
|
||||
contact.number.includes(filteredContacts)
|
||||
)
|
||||
.map((contact) => (
|
||||
<>
|
||||
<ListItem key={contact.id} divider>
|
||||
<ListItemAvatar>
|
||||
{contact.avatar ? (
|
||||
<MuiAvatar src={contact.avatar} />
|
||||
) : (
|
||||
<MuiAvatar>
|
||||
{contact.display.slice(0, 1).toUpperCase()}
|
||||
</MuiAvatar>
|
||||
)}
|
||||
</ListItemAvatar>
|
||||
<ListItemText
|
||||
primary={contact.display}
|
||||
secondary={contact.number}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem className={classes.collapseItem}>
|
||||
<TextField
|
||||
value={contact.number}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem className={classes.collapseItem}>
|
||||
<Button className={classes.updateButton}>
|
||||
Update contact
|
||||
<Button onClick={() => startCall(contact.number)}>
|
||||
<PhoneIcon />
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() =>
|
||||
console.log("Message: " + contact.display, contact.number)
|
||||
}
|
||||
>
|
||||
<ChatIcon />
|
||||
</Button>
|
||||
<Button
|
||||
style={{ margin: -15 }}
|
||||
onClick={() => openContactInfo(contact)}
|
||||
>
|
||||
<MoreVertIcon />
|
||||
</Button>
|
||||
</ListItem>
|
||||
</List>
|
||||
</Collapse>
|
||||
</>
|
||||
))}
|
||||
</>
|
||||
))}
|
||||
</List>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,111 @@
|
||||
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 (
|
||||
<Slide direction="up" in={showContactModal}>
|
||||
<Paper
|
||||
className={showContactModal ? classes.modalRoot : classes.modalHide}
|
||||
>
|
||||
<Button style={{ margin: 10 }} onClick={closeModal}>
|
||||
<ArrowBackIcon />
|
||||
</Button>
|
||||
<div className={classes.listContainer}>
|
||||
<MuiAvatar className={classes.avatar} src={avatar} />
|
||||
<TextField
|
||||
className={classes.input}
|
||||
value={display}
|
||||
onChange={(e) => setDisplay(e.target.value)}
|
||||
placeholder={t("APPS_CONTACT_FORM_NAME")}
|
||||
fullWidth
|
||||
inputProps={{
|
||||
className: classes.inputProps,
|
||||
}}
|
||||
/>
|
||||
<TextField
|
||||
className={classes.input}
|
||||
value={number}
|
||||
onChange={(e) => setNumber(e.target.value)}
|
||||
placeholder={t("APPS_CONTACT_FORM_NUMBER")}
|
||||
fullWidth
|
||||
inputProps={{
|
||||
className: classes.inputProps,
|
||||
}}
|
||||
/>
|
||||
<TextField
|
||||
className={classes.input}
|
||||
placeholder={t("APPS_CONTACT_FORM_AVATAR")}
|
||||
fullWidth
|
||||
value={avatar}
|
||||
onChange={(e) => setAvatar(e.target.value)}
|
||||
inputProps={{
|
||||
className: classes.inputProps,
|
||||
}}
|
||||
/>
|
||||
|
||||
<div style={{ display: "block" }}>
|
||||
<Button onClick={updateContact} className={classes.updateButton}>
|
||||
Update
|
||||
</Button>
|
||||
<Button onClick={deleteContact} className={classes.deleteButton}>
|
||||
Delete
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Paper>
|
||||
</Slide>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
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;
|
||||
@@ -16,5 +16,9 @@ export const contactsState = {
|
||||
showContactsModal: atom({
|
||||
key: 'showContactModal',
|
||||
default: false
|
||||
}),
|
||||
contactDetail: atom({
|
||||
key: 'contactDetail',
|
||||
default: null
|
||||
})
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { contactsState } from './state';
|
||||
|
||||
export const useContactDetail = (): any => {
|
||||
const [ contactDetail, setContactDetail ] = useRecoilState(contactsState.contactDetail);
|
||||
return { contactDetail, setContactDetail };
|
||||
}
|
||||
@@ -3,12 +3,6 @@ import { useRecoilState, atom } from "recoil";
|
||||
const dialerHistoryState = atom({
|
||||
key: "dialerHistory",
|
||||
default: [
|
||||
{
|
||||
id: 0,
|
||||
caller: "Kidz",
|
||||
phoneNumber: "000-1111",
|
||||
type: "incoming",
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
caller: "ROCKY",
|
||||
|
||||
@@ -44,6 +44,11 @@
|
||||
"APPS_BANK_ACCOUNT_TITLE": "Account Summary",
|
||||
"APPS_BANK_ACCOUNT_TRANSACTIONS": "Transactions",
|
||||
"APPS_BANK_ACCOUNT_SEE_TRANSACTION": "See all",
|
||||
"APPS_BANK_ACTIONS_TRANSFER": "Transfer"
|
||||
"APPS_BANK_ACTIONS_TRANSFER": "Transfer",
|
||||
|
||||
"APPS_CONTACT_FORM_NAME": "Name",
|
||||
"APPS_CONTACT_FORM_NUMBER": "Number",
|
||||
"APPS_CONTACT_FORM_AVATAR": "Avatar URL"
|
||||
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,29 @@ on(`__cfx_nui:${events.CONTACTS_ADD_CONTACT}`, (data: any) => {
|
||||
const avatar = data.avatar;
|
||||
emitNet(events.CONTACTS_ADD_CONTACT, number, display, avatar);
|
||||
|
||||
setTimeout(() => {
|
||||
emitNet(events.CONTACTS_GET_CONTACTS)
|
||||
}, 500)
|
||||
});
|
||||
|
||||
onNet(events.CONTACTS_ADD_CONTACT_SUCCESS, () => {
|
||||
emitNet(events.CONTACTS_GET_CONTACTS)
|
||||
})
|
||||
|
||||
|
||||
RegisterNuiCallbackType(events.CONTACTS_UPDATE_CONTACT);
|
||||
on(`__cfx_nui:${events.CONTACTS_UPDATE_CONTACT}`, (data: any) => {
|
||||
const contact = data;
|
||||
emitNet(events.CONTACTS_UPDATE_CONTACT, contact)
|
||||
})
|
||||
|
||||
onNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, () => {
|
||||
emitNet(events.CONTACTS_GET_CONTACTS)
|
||||
})
|
||||
|
||||
RegisterNuiCallbackType(events.CONTACTS_DELETE_CONTACT);
|
||||
on(`__cfx_nui:${events.CONTACTS_DELETE_CONTACT}`, (data: any) => {
|
||||
const contact = data;
|
||||
emitNet(events.CONTACTS_DELETE_CONTACT, contact)
|
||||
})
|
||||
|
||||
onNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, () => {
|
||||
emitNet(events.CONTACTS_GET_CONTACTS)
|
||||
})
|
||||
@@ -1,12 +1,20 @@
|
||||
import { ESX } from "./server";
|
||||
import { ESX, getSource } from "./server";
|
||||
import { pool } from "./db";
|
||||
import events from "../utils/events";
|
||||
import { useIdentifier } from './functions'
|
||||
|
||||
interface Contacts {
|
||||
id?: number;
|
||||
display: string;
|
||||
number: string;
|
||||
avatar: string;
|
||||
}
|
||||
|
||||
interface ContactId {
|
||||
id: number;
|
||||
}
|
||||
|
||||
|
||||
async function fetchAllContacts(identifier: string): Promise<Contacts[]> {
|
||||
const query = "SELECT * FROM npwd_phone_contacts WHERE identifier = ?";
|
||||
const [results] = await pool.query(query, [identifier]);
|
||||
@@ -26,6 +34,25 @@ async function addContact(
|
||||
await pool.query(query, [identifier, number, display, avatar]);
|
||||
}
|
||||
|
||||
async function updateContact(contact: Contacts, identifier: string): Promise<any> {
|
||||
const query = "UPDATE npwd_phone_contacts SET number = ?, display = ?, avatar = ? WHERE id = ? AND identifier = ?"
|
||||
await pool.query(query, [
|
||||
contact.number,
|
||||
contact.display,
|
||||
contact.avatar,
|
||||
contact.id,
|
||||
identifier
|
||||
])
|
||||
}
|
||||
|
||||
async function deleteContact(contact: ContactId, identifier: string): Promise<any> {
|
||||
const query = "DELETE FROM npwd_phone_contacts WHERE id = ? AND identifier = ?"
|
||||
await pool.query(query, [
|
||||
contact.id,
|
||||
identifier
|
||||
])
|
||||
}
|
||||
|
||||
onNet(events.CONTACTS_GET_CONTACTS, async () => {
|
||||
try {
|
||||
const _source = (global as any).source;
|
||||
@@ -39,16 +66,36 @@ onNet(events.CONTACTS_GET_CONTACTS, async () => {
|
||||
}
|
||||
})
|
||||
|
||||
onNet(events.CONTACTS_ADD_CONTACT, (number: string, display: string, avatar: string) => {
|
||||
onNet(events.CONTACTS_ADD_CONTACT, async (number: string, display: string, avatar: string) => {
|
||||
try {
|
||||
const _source = (global as any).source;
|
||||
const xPlayer = ESX.GetPlayerFromId(_source);
|
||||
const _identifier = xPlayer.getIdentifier()
|
||||
const _identifier = await useIdentifier()
|
||||
addContact(_identifier, number, display, avatar);
|
||||
//emit(events.CONTACTS_GET_CONTACTS);
|
||||
emitNet(events.CONTACTS_ADD_CONTACT_SUCCESS, _source)
|
||||
|
||||
} catch(error) {
|
||||
console.log("Failed to add contact: ", error);
|
||||
}
|
||||
});
|
||||
|
||||
onNet(events.CONTACTS_UPDATE_CONTACT, async (contact: Contacts) => {
|
||||
try {
|
||||
const _source = (global as any)._source
|
||||
const _identifier = await useIdentifier()
|
||||
updateContact(contact, _identifier)
|
||||
emitNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, _source)
|
||||
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
})
|
||||
|
||||
onNet(events.CONTACTS_DELETE_CONTACT, async (contact: ContactId) => {
|
||||
try {
|
||||
const _identifier = await useIdentifier()
|
||||
deleteContact(contact, _identifier)
|
||||
emitNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, getSource())
|
||||
} catch (error) {
|
||||
console.log("DELETE CONTACT ERROR", error)
|
||||
}
|
||||
})
|
||||
@@ -32,7 +32,11 @@ export default {
|
||||
CONTACTS_GET_CONTACTS: 'phone:getContacts',
|
||||
CONTACTS_ADD_CONTACT_NUI: 'contacts:add',
|
||||
CONTACTS_ADD_CONTACT: 'contacts:add',
|
||||
CONTACTS_UPDATE_CONTACTS: 'phone:updateContacts',
|
||||
CONTACTS_ADD_CONTACT_SUCCESS: 'contacts:addSuccess',
|
||||
CONTACTS_UPDATE_CONTACT: 'phone:updateContact',
|
||||
CONTACTS_DELETE_CONTACT: 'phone:deleteContact',
|
||||
CONTACTS_DELETE_CONTACT_SUCCESS: 'contacts:deleteSuccess',
|
||||
CONTACTS_UPDATE_CONTACT_SUCCESS: 'phone:updateContactSuccess',
|
||||
|
||||
// Sellout
|
||||
SELLOUT_ADD_LISTING: 'phone:addListing',
|
||||
|
||||
Reference in new issue
Block a user