From 0aa38a98a991ed320913f0827ae890542f3d9378 Mon Sep 17 00:00:00 2001 From: chip Date: Tue, 20 Oct 2020 00:45:51 +0200 Subject: [PATCH 01/11] fix(Sellout): Name correction for sending data to client --- phone/src/apps/sellout/components/form/ListingForm.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phone/src/apps/sellout/components/form/ListingForm.tsx b/phone/src/apps/sellout/components/form/ListingForm.tsx index 198a2ce..5064aaf 100644 --- a/phone/src/apps/sellout/components/form/ListingForm.tsx +++ b/phone/src/apps/sellout/components/form/ListingForm.tsx @@ -33,13 +33,13 @@ export const ListingForm = () => { const [ title, setTitle ] = useState(''); const [ url, setUrl ] = useState(''); - const [ desc, setDesc ] = useState(''); + const [ description, setDescription ] = useState(''); const addListing = () => { Nui.send('phone:addListing', { title, url, - desc + description }) } @@ -67,7 +67,7 @@ export const ListingForm = () => { setDesc(e.target.value)} + onChange={e => setDescription(e.target.value)} placeholder="Description" inputProps={{ className: classes.multilineFieldInput }} style={{ width: "80%" }} From c9334512b992e55bfbfeba921dc4a999b581d1bf Mon Sep 17 00:00:00 2001 From: chip Date: Tue, 20 Oct 2020 00:46:23 +0200 Subject: [PATCH 02/11] feat(sellout): new headline for title on item --- .../sellout/components/SelloutList/SelloutItem.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/phone/src/apps/sellout/components/SelloutList/SelloutItem.tsx b/phone/src/apps/sellout/components/SelloutList/SelloutItem.tsx index 4b24873..df59279 100644 --- a/phone/src/apps/sellout/components/SelloutList/SelloutItem.tsx +++ b/phone/src/apps/sellout/components/SelloutList/SelloutItem.tsx @@ -51,16 +51,21 @@ export const SelloutItem = (listing) => { {listing.name} - {/* {listing.number} - */} + + + {listing.title} + {listing.url ? ( - ): null } + ): ( + No image provided🙁 + ) } {listing.description} From 249e0b5db2da9d2dcde67542cb80ff2ecb7c6cf2 Mon Sep 17 00:00:00 2001 From: chip Date: Tue, 20 Oct 2020 00:47:00 +0200 Subject: [PATCH 03/11] tweak(events): change of events name for sellout app --- resources/utils/events.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/utils/events.ts b/resources/utils/events.ts index aaef09d..07a0451 100644 --- a/resources/utils/events.ts +++ b/resources/utils/events.ts @@ -30,6 +30,6 @@ export default { // Sellout SELLOUT_ADD_LISTING: 'phone:addListing', - SELLOUT_FETCH_LISTING: 'phone:fetchAllListing', + SELLOUT_FETCH_LISTING: 'phone:fetchAllListings', SELLOUT_SEND_LISTING: 'phone:sendAllListings' } From 29686b9b06eff162d1051bd81984b911bc7e9951 Mon Sep 17 00:00:00 2001 From: chip Date: Tue, 20 Oct 2020 00:47:34 +0200 Subject: [PATCH 04/11] fix(main): fixed how events are triggerd when opnening the phone --- resources/client/cl_main.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/resources/client/cl_main.ts b/resources/client/cl_main.ts index c54096b..0b2ead5 100644 --- a/resources/client/cl_main.ts +++ b/resources/client/cl_main.ts @@ -234,9 +234,10 @@ async function Phone() { if (!isPhoneOpen) { isPhoneOpen = true; await phoneOpenAnim(); // Animation starts before the phone is open + emitNet('phone:getCredentials') emitNet(events.CONTACTS_GET_CONTACTS); - emitNet(events.SELLOUT_FETCH_LISTING); - emitNet('phone:getCredentials') // Gets the credentials. Will eventually most likely only get the phone number and name, idk. + emitNet(events.SELLOUT_FETCH_LISTING); + console.log("Sellout fetched from client side")// Gets the credentials. Will eventually most likely only get the phone number and name, idk. SetCursorLocation(0.90, 0.922) //Experimental let res = GetActiveScreenResolution() SendNuiMessage( @@ -270,9 +271,10 @@ async function Phone() { if (!isPhoneOpen) { isPhoneOpen = true; await phoneOpenAnim(); // Animation starts before the phone is open + emitNet('phone:getCredentials') emitNet(events.CONTACTS_GET_CONTACTS); emitNet(events.SELLOUT_FETCH_LISTING); - emitNet('phone:getCredentials') + console.log("Sellout fetched from client side") SetCursorLocation(0.936, 0.922) //Experimental let res = GetActiveScreenResolution() SendNuiMessage( From 0d966a0e10e5a03fa3b78a47363099076719dd3e Mon Sep 17 00:00:00 2001 From: chip Date: Tue, 20 Oct 2020 00:48:16 +0200 Subject: [PATCH 05/11] feat(functions:server): New hook for getting phone number from identifier | not done --- resources/server/functions.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/resources/server/functions.ts b/resources/server/functions.ts index c9f7c0a..75bfbe2 100644 --- a/resources/server/functions.ts +++ b/resources/server/functions.ts @@ -1,9 +1,7 @@ import { pool } from './db'; -import { ESX, getSource } from './server'; export const usePhoneNumber = async (identifier: string) => { const query = "SELECT phone_number FROM users WHERE identifier = ?" - const result = await pool.query(query, [identifier]); - - return result + const phoneNumber = await pool.query(query, [identifier]); + return phoneNumber; } \ No newline at end of file From 98176bf5f3f9676a3494a0d1d3b335442607d3c8 Mon Sep 17 00:00:00 2001 From: chip Date: Tue, 20 Oct 2020 00:48:34 +0200 Subject: [PATCH 06/11] more mock data --- phone/src/Phone.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index 2aa27b1..2d4c540 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -87,14 +87,16 @@ setTimeout(() => { id: 1, name: "Some guy", number: "123-4567", + title: "Car", description: "Selling this cool car", - url: "", + url: "https://i.imgur.com/ROmGTwi.jpeg", }, { id: 2, name: "Some other dude", number: "666-6666", + title: "Material", description: "Selling my wife", url: "", }, From fbb9ab2ae80708272da8be6dfd7b040d74d6fb9e Mon Sep 17 00:00:00 2001 From: chip Date: Tue, 20 Oct 2020 00:49:36 +0200 Subject: [PATCH 07/11] fix(sellout:client:server): fixed how stuff gets sent and fetched. --- resources/client/cl_sellout.ts | 24 ++++++++------- resources/server/sv_sellout.ts | 54 ++++++++++++++++++++-------------- 2 files changed, 45 insertions(+), 33 deletions(-) diff --git a/resources/client/cl_sellout.ts b/resources/client/cl_sellout.ts index 6a46c92..ca16fcc 100644 --- a/resources/client/cl_sellout.ts +++ b/resources/client/cl_sellout.ts @@ -1,15 +1,5 @@ import events from '../utils/events'; -RegisterNuiCallbackType(events.SELLOUT_ADD_LISTING); -on(`__cfx_nui:${events.SELLOUT_ADD_LISTING}`, (data: any) => { - emitNet(events.SELLOUT_ADD_LISTING, data) - - setTimeout(() => { - emitNet(events.SELLOUT_FETCH_LISTING); - console.log("Fetched") - }, 500) -}) - onNet(events.SELLOUT_SEND_LISTING, (listing: any) => { SendNuiMessage( JSON.stringify({ @@ -18,4 +8,16 @@ onNet(events.SELLOUT_SEND_LISTING, (listing: any) => { data: listing }) ) -}) \ No newline at end of file +}) + +RegisterNuiCallbackType(events.SELLOUT_ADD_LISTING); +on(`__cfx_nui:${events.SELLOUT_ADD_LISTING}`, (data: any) => { + const listing = data; + emitNet(events.SELLOUT_ADD_LISTING, listing) + + setTimeout(() => { + emitNet(events.SELLOUT_FETCH_LISTING); + console.log("Fetched") + }, 500) +}) + diff --git a/resources/server/sv_sellout.ts b/resources/server/sv_sellout.ts index bbf1667..436b5b7 100644 --- a/resources/server/sv_sellout.ts +++ b/resources/server/sv_sellout.ts @@ -1,51 +1,61 @@ + import events from '../utils/events'; import { ESX, getSource } from './server'; import { pool } from './db'; +import { usePhoneNumber } from './functions'; -interface IListing { +interface Listing { title: string; name: string; url: string; description: string; } -async function addListing(identifier: string, name: string, title: string, url: string, description: string): Promise { - const query = "INSERT INTO npwd_sellout_listings (identifier, name, title, url, description) VALUES (?, ?, ?, ?, ?)" - console.log("hallllllollooooo"); - await pool.query(query, [identifier, name, title, url, description]) -} -async function fetchAllListings(): Promise { +async function fetchAllListings(): Promise { const query = "SELECT * FROM npwd_sellout_listings ORDER BY id DESC"; const [ results ] = await pool.query(query); - const listings = results; + const listings = results; return listings; } -onNet(events.SELLOUT_ADD_LISTING, (data: any) => { - try { - const xPlayer = ESX.GetPlayerFromId(getSource()) - const _identifier = xPlayer.getIdentifier() - const name = xPlayer.getName() - console.log("ADDED") - - addListing(_identifier, name, data.title, data.url, data.desc) - } catch (error) { - console.log(error) - } -}) +async function addListing(identifier: string, name: string, number: any, listing: Listing): Promise { + const query = "INSERT INTO npwd_sellout_listings (identifier, name, number, title, url, description) VALUES (?, ?, ?, ?, ?, ?)" + await pool.query(query, [ + identifier, + name, + number, + listing.title, + listing.url, + listing.description, + ]) +} onNet(events.SELLOUT_FETCH_LISTING, async () => { try { console.log("Fetching all listings") + + const _source = (global as any).source; const listings = await fetchAllListings(); - console.log("ADDED") - emitNet(events.SELLOUT_SEND_LISTING, getSource(), listings) + emitNet(events.SELLOUT_SEND_LISTING, _source, listings) } catch(error) { console.log(error) } +}) + +onNet(events.SELLOUT_ADD_LISTING, (listing: Listing) => { + try { + const xPlayer = ESX.GetPlayerFromId(getSource()) + const _identifier = xPlayer.getIdentifier() + const name = xPlayer.getName() + + const number = "3333333" //usePhoneNumber(_identifier) + addListing(_identifier, name, number, listing) + } catch (error) { + console.log("Failed to add contact: ", error) + } }) \ No newline at end of file From d70558c7e1d350b741f55350d3aa294ad04fbe10 Mon Sep 17 00:00:00 2001 From: chip Date: Tue, 20 Oct 2020 00:50:16 +0200 Subject: [PATCH 08/11] not sure what this is --- resources/client/cl_contacts.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/client/cl_contacts.ts b/resources/client/cl_contacts.ts index df91fde..a052a41 100644 --- a/resources/client/cl_contacts.ts +++ b/resources/client/cl_contacts.ts @@ -1,4 +1,3 @@ -import { ESX } from "../client/client"; import events from "../utils/events"; onNet(events.CONTACTS_SEND_CONTACTS, (contacts: any) => { From 86f574161816f19b18f83927f155187b209270d7 Mon Sep 17 00:00:00 2001 From: chip Date: Tue, 20 Oct 2020 01:20:08 +0200 Subject: [PATCH 09/11] fix(usePhoneNumber): working hook --- resources/server/functions.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/resources/server/functions.ts b/resources/server/functions.ts index 75bfbe2..709f5fc 100644 --- a/resources/server/functions.ts +++ b/resources/server/functions.ts @@ -1,7 +1,12 @@ import { pool } from './db'; -export const usePhoneNumber = async (identifier: string) => { +interface IPhoneNumber { + phone_number: string; +} + +export async function usePhoneNumber(identifier: string): Promise { const query = "SELECT phone_number FROM users WHERE identifier = ?" - const phoneNumber = await pool.query(query, [identifier]); - return phoneNumber; + const [results] = await pool.query(query, [identifier]); + const phoneNumber = results; + return phoneNumber[0].phone_number; } \ No newline at end of file From 2d94b5ec8cdd7ef889439ca223671ee62c464af5 Mon Sep 17 00:00:00 2001 From: chip Date: Tue, 20 Oct 2020 01:20:42 +0200 Subject: [PATCH 10/11] feat(sellout/server): using usePhoneNumber hook --- resources/server/sv_sellout.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/resources/server/sv_sellout.ts b/resources/server/sv_sellout.ts index 436b5b7..49f6bc0 100644 --- a/resources/server/sv_sellout.ts +++ b/resources/server/sv_sellout.ts @@ -8,7 +8,7 @@ import { usePhoneNumber } from './functions'; interface Listing { title: string; name: string; - url: string; + url?: string; description: string; } @@ -47,14 +47,16 @@ onNet(events.SELLOUT_FETCH_LISTING, async () => { } }) -onNet(events.SELLOUT_ADD_LISTING, (listing: Listing) => { +onNet(events.SELLOUT_ADD_LISTING, async (listing: Listing) => { try { const xPlayer = ESX.GetPlayerFromId(getSource()) const _identifier = xPlayer.getIdentifier() const name = xPlayer.getName() - const number = "3333333" //usePhoneNumber(_identifier) - addListing(_identifier, name, number, listing) + const phoneNumber = await usePhoneNumber(_identifier) + console.log(phoneNumber) + const number = "3333333" + addListing(_identifier, name, phoneNumber, listing) } catch (error) { console.log("Failed to add contact: ", error) } From e31c42766ea545c99093352e948af18adb7f59d6 Mon Sep 17 00:00:00 2001 From: chip Date: Tue, 20 Oct 2020 01:23:48 +0200 Subject: [PATCH 11/11] cleanup(sellout/server): rid of logs --- resources/server/sv_sellout.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/resources/server/sv_sellout.ts b/resources/server/sv_sellout.ts index 49f6bc0..7682f8a 100644 --- a/resources/server/sv_sellout.ts +++ b/resources/server/sv_sellout.ts @@ -36,8 +36,6 @@ async function addListing(identifier: string, name: string, number: any, listing onNet(events.SELLOUT_FETCH_LISTING, async () => { try { - console.log("Fetching all listings") - const _source = (global as any).source; const listings = await fetchAllListings(); emitNet(events.SELLOUT_SEND_LISTING, _source, listings) @@ -54,8 +52,6 @@ onNet(events.SELLOUT_ADD_LISTING, async (listing: Listing) => { const name = xPlayer.getName() const phoneNumber = await usePhoneNumber(_identifier) - console.log(phoneNumber) - const number = "3333333" addListing(_identifier, name, phoneNumber, listing) } catch (error) { console.log("Failed to add contact: ", error)