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: "", }, 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} 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%" }} 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) => { 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( 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/functions.ts b/resources/server/functions.ts index c9f7c0a..709f5fc 100644 --- a/resources/server/functions.ts +++ b/resources/server/functions.ts @@ -1,9 +1,12 @@ import { pool } from './db'; -import { ESX, getSource } from './server'; -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 result = await pool.query(query, [identifier]); - - return result + const [results] = await pool.query(query, [identifier]); + const phoneNumber = results; + return phoneNumber[0].phone_number; } \ No newline at end of file diff --git a/resources/server/sv_sellout.ts b/resources/server/sv_sellout.ts index bbf1667..7682f8a 100644 --- a/resources/server/sv_sellout.ts +++ b/resources/server/sv_sellout.ts @@ -1,51 +1,59 @@ + 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; + 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, async (listing: Listing) => { + try { + const xPlayer = ESX.GetPlayerFromId(getSource()) + const _identifier = xPlayer.getIdentifier() + const name = xPlayer.getName() + + const phoneNumber = await usePhoneNumber(_identifier) + addListing(_identifier, name, phoneNumber, listing) + } catch (error) { + console.log("Failed to add contact: ", error) + } }) \ No newline at end of file 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' }