From fcdf03cce4b14d8dca0a0236b45a18696c36a8f0 Mon Sep 17 00:00:00 2001 From: chip Date: Sun, 1 Nov 2020 22:45:13 +0100 Subject: [PATCH 01/11] mock datat --- phone/src/Phone.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index 5d5600f..0865345 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -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, From e4053d3ec28820ae0c188a0878b5897f977af38a Mon Sep 17 00:00:00 2001 From: chip Date: Sun, 1 Nov 2020 22:47:23 +0100 Subject: [PATCH 02/11] feat(contacts/nui): new modal for contact info --- phone/src/apps/contacts/components/ContactsApp.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/phone/src/apps/contacts/components/ContactsApp.tsx b/phone/src/apps/contacts/components/ContactsApp.tsx index fa47d34..7ef050c 100644 --- a/phone/src/apps/contacts/components/ContactsApp.tsx +++ b/phone/src/apps/contacts/components/ContactsApp.tsx @@ -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 = () => { +
From c77a9fc80708465a9aa883e26d1f776bf88f2f2c Mon Sep 17 00:00:00 2001 From: chip Date: Sun, 1 Nov 2020 22:47:43 +0100 Subject: [PATCH 03/11] prettier --- .../contacts/components/List/ContactList.tsx | 119 +++++++++--------- 1 file changed, 59 insertions(+), 60 deletions(-) diff --git a/phone/src/apps/contacts/components/List/ContactList.tsx b/phone/src/apps/contacts/components/List/ContactList.tsx index 699111c..2edfdcf 100644 --- a/phone/src/apps/contacts/components/List/ContactList.tsx +++ b/phone/src/apps/contacts/components/List/ContactList.tsx @@ -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 ( - {contacts.contacts.filter(contact => contact.display.includes(filteredContacts) || contact.number.includes(filteredContacts)).map((contact) => ( - <> - - - {contact.avatar ? ( - - ): ( - {contact.display.slice(0, 1).toUpperCase()} - )} - - - - - - - - - - + contact.display.includes(filteredContacts) || + contact.number.includes(filteredContacts) + ) + .map((contact) => ( + <> + + + {contact.avatar ? ( + + ) : ( + + {contact.display.slice(0, 1).toUpperCase()} + + )} + + - - - - - - + + - - - - ))} + + ))} ); }; From de09800a725b5b4f69a2fef9484cd479dfd534e3 Mon Sep 17 00:00:00 2001 From: chip Date: Sun, 1 Nov 2020 22:48:30 +0100 Subject: [PATCH 04/11] feat(contacts/nui): new state for contact details --- phone/src/apps/contacts/hooks/state.ts | 4 ++++ phone/src/apps/contacts/hooks/useContactDetail.ts | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 phone/src/apps/contacts/hooks/useContactDetail.ts diff --git a/phone/src/apps/contacts/hooks/state.ts b/phone/src/apps/contacts/hooks/state.ts index 8d725c3..0c5321b 100644 --- a/phone/src/apps/contacts/hooks/state.ts +++ b/phone/src/apps/contacts/hooks/state.ts @@ -16,5 +16,9 @@ export const contactsState = { showContactsModal: atom({ key: 'showContactModal', default: false + }), + contactDetail: atom({ + key: 'contactDetail', + default: null }) }; diff --git a/phone/src/apps/contacts/hooks/useContactDetail.ts b/phone/src/apps/contacts/hooks/useContactDetail.ts new file mode 100644 index 0000000..9c064e9 --- /dev/null +++ b/phone/src/apps/contacts/hooks/useContactDetail.ts @@ -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 }; +} \ No newline at end of file From 6733f1247bba4157f00632c508745cbfd2d8b31d Mon Sep 17 00:00:00 2001 From: chip Date: Sun, 1 Nov 2020 22:49:01 +0100 Subject: [PATCH 05/11] feat(contacts/nui): functional modal for contact details --- .../contacts/components/modal/InfoModal.tsx | 111 ++++++++++++++++++ .../contacts/components/modal/modal.styles.ts | 49 ++++++++ 2 files changed, 160 insertions(+) create mode 100644 phone/src/apps/contacts/components/modal/InfoModal.tsx create mode 100644 phone/src/apps/contacts/components/modal/modal.styles.ts diff --git a/phone/src/apps/contacts/components/modal/InfoModal.tsx b/phone/src/apps/contacts/components/modal/InfoModal.tsx new file mode 100644 index 0000000..07456b3 --- /dev/null +++ b/phone/src/apps/contacts/components/modal/InfoModal.tsx @@ -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 ( + + + +
+ + setDisplay(e.target.value)} + placeholder={t("APPS_CONTACT_FORM_NAME")} + fullWidth + inputProps={{ + className: classes.inputProps, + }} + /> + setNumber(e.target.value)} + placeholder={t("APPS_CONTACT_FORM_NUMBER")} + fullWidth + inputProps={{ + className: classes.inputProps, + }} + /> + setAvatar(e.target.value)} + inputProps={{ + className: classes.inputProps, + }} + /> + +
+ + +
+
+
+
+ ); +}; diff --git a/phone/src/apps/contacts/components/modal/modal.styles.ts b/phone/src/apps/contacts/components/modal/modal.styles.ts new file mode 100644 index 0000000..7f0af19 --- /dev/null +++ b/phone/src/apps/contacts/components/modal/modal.styles.ts @@ -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; \ No newline at end of file From e1a24a32f45d28e79208f2a9b4a6c0b540399c90 Mon Sep 17 00:00:00 2001 From: chip Date: Sun, 1 Nov 2020 22:49:26 +0100 Subject: [PATCH 06/11] removed a name we all hate --- phone/src/apps/dialer/hooks/useDialerHistory.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/phone/src/apps/dialer/hooks/useDialerHistory.ts b/phone/src/apps/dialer/hooks/useDialerHistory.ts index cfc6d31..6a8e19a 100644 --- a/phone/src/apps/dialer/hooks/useDialerHistory.ts +++ b/phone/src/apps/dialer/hooks/useDialerHistory.ts @@ -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", From 37232f514cfb14f3433fb9462e6b2a7e02dabcc0 Mon Sep 17 00:00:00 2001 From: chip Date: Sun, 1 Nov 2020 22:49:50 +0100 Subject: [PATCH 07/11] translatin for contacts app | not done --- phone/src/locale/en.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index 6b5bee5..4094108 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -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" + } } From b1835bbd750b4ab985662db2aeaa2d0cfe365e59 Mon Sep 17 00:00:00 2001 From: chip Date: Sun, 1 Nov 2020 22:50:33 +0100 Subject: [PATCH 08/11] feat(contacts/client): update and delete contacts --- resources/client/cl_contacts.ts | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/resources/client/cl_contacts.ts b/resources/client/cl_contacts.ts index a052a41..0f12dc8 100644 --- a/resources/client/cl_contacts.ts +++ b/resources/client/cl_contacts.ts @@ -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) +}) \ No newline at end of file From 0aa26851ae2dff0b8d75c52d6af8c99701ccf6bb Mon Sep 17 00:00:00 2001 From: chip Date: Sun, 1 Nov 2020 22:50:48 +0100 Subject: [PATCH 09/11] feat(contacts/server): update and delete contacts --- resources/server/sv_contacts.ts | 58 ++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/resources/server/sv_contacts.ts b/resources/server/sv_contacts.ts index f0fcfba..e23c87e 100644 --- a/resources/server/sv_contacts.ts +++ b/resources/server/sv_contacts.ts @@ -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 { 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 { + 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 { + 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,37 @@ 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) => { + console.log("ID", contact) + try { + const _identifier = await useIdentifier() + deleteContact(contact, _identifier) + emitNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, getSource()) + } catch (error) { + console.log("DELETE CONTACT ERROR", error) + } +}) From 362581a115765cffbca832954b21573c0552ffef Mon Sep 17 00:00:00 2001 From: chip Date: Sun, 1 Nov 2020 22:51:18 +0100 Subject: [PATCH 10/11] feat(phone/events): events for contact update and deletion --- resources/utils/events.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/resources/utils/events.ts b/resources/utils/events.ts index 7623d9c..0dc62a1 100644 --- a/resources/utils/events.ts +++ b/resources/utils/events.ts @@ -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', From 458d21f4aa86e65d16f7bf2f8d5f8ab914339402 Mon Sep 17 00:00:00 2001 From: chip Date: Sun, 1 Nov 2020 22:52:22 +0100 Subject: [PATCH 11/11] cleanup sv_contacts --- resources/server/sv_contacts.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/server/sv_contacts.ts b/resources/server/sv_contacts.ts index e23c87e..47b6e0c 100644 --- a/resources/server/sv_contacts.ts +++ b/resources/server/sv_contacts.ts @@ -91,7 +91,6 @@ onNet(events.CONTACTS_UPDATE_CONTACT, async (contact: Contacts) => { }) onNet(events.CONTACTS_DELETE_CONTACT, async (contact: ContactId) => { - console.log("ID", contact) try { const _identifier = await useIdentifier() deleteContact(contact, _identifier)