Merge pull request #17 from Re-Ignited-Development/tweak/sellout

Tweak/sellout YEEEET
This commit is contained in:
Christopher Gjelten authored and GitHub committed 2020-10-20 01:42:25 +02:00
commit bc017f8629
9 files changed
+71 -50

No files matched your search

+3 -1
View File
@@ -87,14 +87,16 @@ setTimeout(() => {
id: 1, id: 1,
name: "Some guy", name: "Some guy",
number: "123-4567", number: "123-4567",
title: "Car",
description: description:
"Selling this cool car", "Selling this cool car",
url: "", url: "https://i.imgur.com/ROmGTwi.jpeg",
}, },
{ {
id: 2, id: 2,
name: "Some other dude", name: "Some other dude",
number: "666-6666", number: "666-6666",
title: "Material",
description: "Selling my wife", description: "Selling my wife",
url: "", url: "",
}, },
@@ -51,16 +51,21 @@ export const SelloutItem = (listing) => {
<Typography className={classes.headerTypo} variant="h5"> <Typography className={classes.headerTypo} variant="h5">
{listing.name} {listing.name}
</Typography> </Typography>
{/*<Typography <Typography
className={classes.headerTypo} className={classes.headerTypo}
style={{ borderBottom: "1px solid #f44336" }} style={{ borderBottom: "1px solid #f44336" }}
> >
{listing.number} {listing.number}
</Typography>*/} </Typography>
<Typography variant="h5" style={{ padding: 5}}>
{listing.title}
</Typography>
</div> </div>
{listing.url ? ( {listing.url ? (
<ImageDisplay imgURL={listing.url} /> <ImageDisplay imgURL={listing.url} />
): null } ): (
<Typography style={{ margin: 10 }}>No image provided🙁</Typography>
) }
<Typography variant="h6" className={classes.desc}> <Typography variant="h6" className={classes.desc}>
{listing.description} {listing.description}
</Typography> </Typography>
@@ -33,13 +33,13 @@ export const ListingForm = () => {
const [ title, setTitle ] = useState(''); const [ title, setTitle ] = useState('');
const [ url, setUrl ] = useState(''); const [ url, setUrl ] = useState('');
const [ desc, setDesc ] = useState(''); const [ description, setDescription ] = useState('');
const addListing = () => { const addListing = () => {
Nui.send('phone:addListing', { Nui.send('phone:addListing', {
title, title,
url, url,
desc description
}) })
} }
@@ -67,7 +67,7 @@ export const ListingForm = () => {
<TextField <TextField
className={classes.input} className={classes.input}
onChange={e => setDesc(e.target.value)} onChange={e => setDescription(e.target.value)}
placeholder="Description" placeholder="Description"
inputProps={{ className: classes.multilineFieldInput }} inputProps={{ className: classes.multilineFieldInput }}
style={{ width: "80%" }} style={{ width: "80%" }}
-1
View File
@@ -1,4 +1,3 @@
import { ESX } from "../client/client";
import events from "../utils/events"; import events from "../utils/events";
onNet(events.CONTACTS_SEND_CONTACTS, (contacts: any) => { onNet(events.CONTACTS_SEND_CONTACTS, (contacts: any) => {
+4 -2
View File
@@ -234,9 +234,10 @@ async function Phone() {
if (!isPhoneOpen) { if (!isPhoneOpen) {
isPhoneOpen = true; isPhoneOpen = true;
await phoneOpenAnim(); // Animation starts before the phone is open await phoneOpenAnim(); // Animation starts before the phone is open
emitNet('phone:getCredentials')
emitNet(events.CONTACTS_GET_CONTACTS); emitNet(events.CONTACTS_GET_CONTACTS);
emitNet(events.SELLOUT_FETCH_LISTING); emitNet(events.SELLOUT_FETCH_LISTING);
emitNet('phone:getCredentials') // Gets the credentials. Will eventually most likely only get the phone number and name, idk. 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 SetCursorLocation(0.90, 0.922) //Experimental
let res = GetActiveScreenResolution() let res = GetActiveScreenResolution()
SendNuiMessage( SendNuiMessage(
@@ -270,9 +271,10 @@ async function Phone() {
if (!isPhoneOpen) { if (!isPhoneOpen) {
isPhoneOpen = true; isPhoneOpen = true;
await phoneOpenAnim(); // Animation starts before the phone is open await phoneOpenAnim(); // Animation starts before the phone is open
emitNet('phone:getCredentials')
emitNet(events.CONTACTS_GET_CONTACTS); emitNet(events.CONTACTS_GET_CONTACTS);
emitNet(events.SELLOUT_FETCH_LISTING); emitNet(events.SELLOUT_FETCH_LISTING);
emitNet('phone:getCredentials') console.log("Sellout fetched from client side")
SetCursorLocation(0.936, 0.922) //Experimental SetCursorLocation(0.936, 0.922) //Experimental
let res = GetActiveScreenResolution() let res = GetActiveScreenResolution()
SendNuiMessage( SendNuiMessage(
+12 -10
View File
@@ -1,15 +1,5 @@
import events from '../utils/events'; 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) => { onNet(events.SELLOUT_SEND_LISTING, (listing: any) => {
SendNuiMessage( SendNuiMessage(
JSON.stringify({ JSON.stringify({
@@ -19,3 +9,15 @@ onNet(events.SELLOUT_SEND_LISTING, (listing: any) => {
}) })
) )
}) })
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)
})
+8 -5
View File
@@ -1,9 +1,12 @@
import { pool } from './db'; 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<string> {
const query = "SELECT phone_number FROM users WHERE identifier = ?" const query = "SELECT phone_number FROM users WHERE identifier = ?"
const result = await pool.query(query, [identifier]); const [results] = await pool.query(query, [identifier]);
const phoneNumber = <IPhoneNumber[]>results;
return result return phoneNumber[0].phone_number;
} }
+32 -24
View File
@@ -1,51 +1,59 @@
import events from '../utils/events'; import events from '../utils/events';
import { ESX, getSource } from './server'; import { ESX, getSource } from './server';
import { pool } from './db'; import { pool } from './db';
import { usePhoneNumber } from './functions';
interface IListing { interface Listing {
title: string; title: string;
name: string; name: string;
url: string; url?: string;
description: string; description: string;
} }
async function addListing(identifier: string, name: string, title: string, url: string, description: string): Promise<any> {
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<IListing[]> { async function fetchAllListings(): Promise<Listing[]> {
const query = "SELECT * FROM npwd_sellout_listings ORDER BY id DESC"; const query = "SELECT * FROM npwd_sellout_listings ORDER BY id DESC";
const [ results ] = await pool.query(query); const [ results ] = await pool.query(query);
const listings = <IListing[]>results; const listings = <Listing[]>results;
return listings; return listings;
} }
onNet(events.SELLOUT_ADD_LISTING, (data: any) => { async function addListing(identifier: string, name: string, number: any, listing: Listing): Promise<any> {
try { const query = "INSERT INTO npwd_sellout_listings (identifier, name, number, title, url, description) VALUES (?, ?, ?, ?, ?, ?)"
const xPlayer = ESX.GetPlayerFromId(getSource()) await pool.query(query, [
const _identifier = xPlayer.getIdentifier() identifier,
const name = xPlayer.getName() name,
console.log("ADDED") number,
listing.title,
addListing(_identifier, name, data.title, data.url, data.desc) listing.url,
} catch (error) { listing.description,
console.log(error) ])
} }
})
onNet(events.SELLOUT_FETCH_LISTING, async () => { onNet(events.SELLOUT_FETCH_LISTING, async () => {
try { try {
console.log("Fetching all listings") const _source = (global as any).source;
const listings = await fetchAllListings(); const listings = await fetchAllListings();
console.log("ADDED") emitNet(events.SELLOUT_SEND_LISTING, _source, listings)
emitNet(events.SELLOUT_SEND_LISTING, getSource(), listings)
} catch(error) { } catch(error) {
console.log(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)
}
})
+1 -1
View File
@@ -30,6 +30,6 @@ export default {
// Sellout // Sellout
SELLOUT_ADD_LISTING: 'phone:addListing', SELLOUT_ADD_LISTING: 'phone:addListing',
SELLOUT_FETCH_LISTING: 'phone:fetchAllListing', SELLOUT_FETCH_LISTING: 'phone:fetchAllListings',
SELLOUT_SEND_LISTING: 'phone:sendAllListings' SELLOUT_SEND_LISTING: 'phone:sendAllListings'
} }