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
+73 -52

No files matched your search

+3 -1
View File
@@ -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: "",
},
@@ -51,16 +51,21 @@ export const SelloutItem = (listing) => {
<Typography className={classes.headerTypo} variant="h5">
{listing.name}
</Typography>
{/*<Typography
<Typography
className={classes.headerTypo}
style={{ borderBottom: "1px solid #f44336" }}
>
{listing.number}
</Typography>*/}
</Typography>
<Typography variant="h5" style={{ padding: 5}}>
{listing.title}
</Typography>
</div>
{listing.url ? (
<ImageDisplay imgURL={listing.url} />
): null }
): (
<Typography style={{ margin: 10 }}>No image provided🙁</Typography>
) }
<Typography variant="h6" className={classes.desc}>
{listing.description}
</Typography>
@@ -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 = () => {
<TextField
className={classes.input}
onChange={e => setDesc(e.target.value)}
onChange={e => setDescription(e.target.value)}
placeholder="Description"
inputProps={{ className: classes.multilineFieldInput }}
style={{ width: "80%" }}
-1
View File
@@ -1,4 +1,3 @@
import { ESX } from "../client/client";
import events from "../utils/events";
onNet(events.CONTACTS_SEND_CONTACTS, (contacts: any) => {
+5 -3
View File
@@ -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(
+13 -11
View File
@@ -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
})
)
})
})
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 { 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 result = await pool.query(query, [identifier]);
return result
const [results] = await pool.query(query, [identifier]);
const phoneNumber = <IPhoneNumber[]>results;
return phoneNumber[0].phone_number;
}
+32 -24
View File
@@ -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<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 [ results ] = await pool.query(query);
const listings = <IListing[]>results;
const listings = <Listing[]>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<any> {
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)
}
})
+1 -1
View File
@@ -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'
}