Merge pull request #16 from Re-Ignited-Development/feat/sellout-app

Feat/sellout app
This commit is contained in:
Christopher Gjelten authored and GitHub committed 2020-10-18 22:12:29 +02:00
commit bd581ec118
22 files changed
+271 -109

No files matched your search

+14 -14
View File
@@ -37,26 +37,26 @@ setTimeout(() => {
window.dispatchEvent(
new MessageEvent("message", {
data: {
app: "BANK",
app: "CONTACTS",
method: "setContacts",
data: [
{
id: 1,
number: "345-4366",
display: "Gjelten",
avatar: "https://i.imgur.com/Qpw6j8D.png",
display: "chip",
avatar: 'https://i.imgur.com/Qpw6j8D.png'
},
{
id: 2,
number: "456-4366",
display: "Loyd",
avatar: "",
display: "shit",
avatar: ''
},
{
id: 3,
number: "123-4366",
display: "Fabian",
avatar: "https://i.imgur.com/B8ta5Aa.jpeg",
display: "rocky",
avatar: 'https://i.imgur.com/B8ta5Aa.jpeg'
},
],
},
@@ -85,24 +85,24 @@ setTimeout(() => {
data: [
{
id: 1,
name: "Donald Trump",
name: "Some guy",
number: "123-4567",
description:
"This is me just selling the whole country, because like why not dude",
img: "some shady link?",
"Selling this cool car",
url: "",
},
{
id: 2,
name: "Joe Biden",
name: "Some other dude",
number: "666-6666",
description: "I think I might buy it Trump!",
img: "even shadier link?",
description: "Selling my wife",
url: "",
},
],
},
})
);
});
}, 1000);
function Phone() {
useNuiService();
@@ -0,0 +1,3 @@
#contact-app .Mui-focused::after {
border-bottom: #2196f3 solid 4px;
}
@@ -8,9 +8,9 @@ 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 PersonAddIcon from '@material-ui/icons/PersonAdd'
import Fab from '@material-ui/core/Fab';
import { useContactModal } from '../hooks/useContactModal';
const useStyles = makeStyles((theme: Theme) =>
createStyles({
@@ -36,6 +36,7 @@ export const ContactsApp = () => {
const classes = useStyles();
const { showModal, setShowModal } = useModal();
const contacts = useApp("CONTACTS");
const { showContactModal } = useContactModal();
const openModal = () => {
setShowModal(true);
@@ -1,6 +1,15 @@
import React from "react";
import ListItemText from "@material-ui/core/ListItemText";
import { Button, ListItemAvatar, Avatar as MuiAvatar } from "@material-ui/core";
import {
Button,
ListItemAvatar,
Avatar as MuiAvatar,
List,
ListItem,
TextField,
Collapse,
makeStyles
} from "@material-ui/core";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faPen } from "@fortawesome/free-solid-svg-icons";
@@ -9,17 +18,39 @@ import { useFilteredContacts } from "../../hooks/useFilteredContacts";
import PhoneIcon from "@material-ui/icons/Phone";
import ChatIcon from "@material-ui/icons/Chat";
import { List } from "../../../../ui/components/List";
import { ListItem } from "../../../../ui/components/ListItem";
import { useContacts } from "../../hooks/useContacts";
import { useContactModal } from '../../hooks/useContactModal';
import Nui from "../../../../os/nui-events/utils/Nui";
import "../Contact.css"
const useStyles = makeStyles((theme) => ({
updateButton: {
margin: 'auto',
fontSize: 14,
width: 150,
background: "#2196f3",
marginBottom: 10,
padding: 8
},
collapseItem: {
margin: 'auto',
width: '50%'
}
}))
export const ContactList = () => {
const classes = useStyles()
const { filteredContacts } = useFilteredContacts();
const { showContactModal, setShowContactModal } = useContactModal();
const contacts = useContacts();
const openContactInfo = () => {
setShowContactModal(!showContactModal);
}
const startCall = (number) => {
console.log(number);
Nui.send("phone:startCall", {
@@ -29,40 +60,52 @@ export const ContactList = () => {
return (
<List>
{contacts.contacts
.filter(
(contact) =>
contact.display.includes(filteredContacts) ||
contact.number.includes(filteredContacts)
)
.map((contact) => (
<ListItem key={contact.id} divider>
<ListItemAvatar>
{contact.avatar ? (
<MuiAvatar src={contact.avatar} />
) : (
<MuiAvatar>{contact.display.slice(0, 1)}</MuiAvatar>
)}
</ListItemAvatar>
<ListItemText
primary={contact.display}
secondary={contact.number}
/>
<Button onClick={() => startCall(contact.number)}>
<PhoneIcon />
</Button>
<Button
onClick={() =>
console.log("Message: " + contact.display, contact.number)
}
>
<ChatIcon />
</Button>
<Button>
<FontAwesomeIcon icon={faPen} size="lg" />
</Button>
</ListItem>
))}
{contacts.contacts.filter(contact => contact.display.includes(filteredContacts) || contact.number.includes(filteredContacts)).map((contact) => (
<>
<ListItem key={contact.id} divider>
<ListItemAvatar>
{contact.avatar ? (
<MuiAvatar src={contact.avatar} />
): (
<MuiAvatar>{contact.display.slice(0, 1).toUpperCase()}</MuiAvatar>
)}
</ListItemAvatar>
<ListItemText primary={contact.display} secondary={contact.number} />
<Button onClick={() => startCall(contact.number)}>
<PhoneIcon />
</Button>
<Button
onClick={() =>
console.log("Message: " + contact.display, contact.number)
}
>
<ChatIcon />
</Button>
<Button onClick={openContactInfo}>
<FontAwesomeIcon icon={faPen} size="lg"/>
</Button>
</ListItem>
<Collapse in={showContactModal} timeout="auto" unmountOnExit>
<List component="div" disablePadding>
<ListItem className={classes.collapseItem}>
<TextField
value={contact.display}
/>
</ListItem>
<ListItem className={classes.collapseItem}>
<TextField
value={contact.number}
/>
</ListItem>
<ListItem className={classes.collapseItem}>
<Button className={classes.updateButton}>
Update contact
</Button>
</ListItem>
</List>
</Collapse>
</>
))}
</List>
);
};
+6 -2
View File
@@ -10,7 +10,11 @@ export const contactsState = {
default: false,
}),
filterContacts: atom({
key: "filterContacts",
default: "",
key: 'filterContacts',
default: ""
}),
showContactsModal: atom({
key: 'showContactModal',
default: false
})
};
@@ -0,0 +1,7 @@
import { useRecoilState } from 'recoil';
import { contactsState } from './state';
export const useContactModal = () => {
const [ showContactModal, setShowContactModal ] = useRecoilState(contactsState.showContactsModal);
return { showContactModal, setShowContactModal };
}
+1 -1
View File
@@ -5,7 +5,7 @@ interface Contact {
id: string;
display: string;
number: string;
img?: string;
avatar?: string
}
interface IUseContacts {
@@ -1,3 +1,8 @@
#sellout-app .Mui-selected {
color: #f44336 !important;
}
#sellout-app .Mui-focused::after {
border-bottom: #f44336 solid 3px;
}
@@ -51,14 +51,16 @@ 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>*/}
</div>
<ImageDisplay imgURL={listing.img} />
{listing.url ? (
<ImageDisplay imgURL={listing.url} />
): null }
<Typography variant="h6" className={classes.desc}>
{listing.description}
</Typography>
@@ -1,5 +1,8 @@
import React from "react";
import React, { useState } from "react";
import { makeStyles, Button, TextField } from "@material-ui/core";
import Nui from "../../../../os/nui-events/utils/Nui";
import "../Sellout.css"
const useStyles = makeStyles((theme) => ({
root: {
@@ -27,11 +30,25 @@ const useStyles = makeStyles((theme) => ({
export const ListingForm = () => {
const classes = useStyles();
const [ title, setTitle ] = useState('');
const [ url, setUrl ] = useState('');
const [ desc, setDesc ] = useState('');
const addListing = () => {
Nui.send('phone:addListing', {
title,
url,
desc
})
}
return (
<div className={classes.root}>
<h1>New Listing</h1>
<TextField
className={classes.input}
onChange={e => setTitle(e.target.value)}
placeholder="Title on listing.."
inputProps={{ className: classes.textFieldInput }}
style={{ width: "80%" }}
@@ -41,6 +58,7 @@ export const ListingForm = () => {
<TextField
className={classes.input}
placeholder="Image URL"
onChange={e => setUrl(e.target.value)}
inputProps={{ className: classes.textFieldInput }}
style={{ width: "80%" }}
size="medium"
@@ -49,6 +67,7 @@ export const ListingForm = () => {
<TextField
className={classes.input}
onChange={e => setDesc(e.target.value)}
placeholder="Description"
inputProps={{ className: classes.multilineFieldInput }}
style={{ width: "80%" }}
@@ -58,7 +77,7 @@ export const ListingForm = () => {
variant="outlined"
/>
<Button className={classes.postButton}>Post</Button>
<Button onClick={addListing} className={classes.postButton}>Post</Button>
</div>
);
};
@@ -5,7 +5,6 @@ import { BottomNavigation, BottomNavigationAction } from "@material-ui/core";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faHome } from "@fortawesome/free-solid-svg-icons";
import AddCircleIcon from "@material-ui/icons/AddCircle";
import FaceIcon from "@material-ui/icons/Face";
const useStyles = makeStyles((theme) => ({
root: {
@@ -38,11 +37,6 @@ export const NavigationBar = () => {
icon={<AddCircleIcon />}
to="/sellout/new"
/>
<BottomNavigationAction
component={Link}
icon={<FaceIcon />}
to="/sellout/new"
/>
</BottomNavigation>
);
};
+1 -1
View File
@@ -3,6 +3,6 @@ import { atom } from "recoil";
export const selloutState = {
listing: atom({
key: "listing",
default: null,
default: [],
}),
};
@@ -32,11 +32,6 @@ export const Navigation = () => {
className={classes.root}
onChange={(_e, value) => value()}
>
<BottomNavigationAction
label="Phone"
value={() => history.push("/phone")}
icon={<PhoneIcon />}
/>
<BottomNavigationAction
label="Home"
value={() => history.push("/")}
+3 -2
View File
@@ -19,6 +19,7 @@ on(`__cfx_nui:${events.CONTACTS_ADD_CONTACT}`, (data: any) => {
emitNet(events.CONTACTS_ADD_CONTACT, number, display, avatar);
setTimeout(() => {
emitNet(events.CONTACTS_GET_CONTACTS);
}, 1000);
emitNet(events.CONTACTS_GET_CONTACTS)
}, 500)
});
+8 -6
View File
@@ -235,9 +235,10 @@ async function Phone() {
isPhoneOpen = true;
await phoneOpenAnim();
emitNet(events.CONTACTS_GET_CONTACTS);
emitNet("phone:getCredentials"); // Gets the credentials. Will eventually most likely only get the phone number and name, idk.
SetCursorLocation(0.936, 0.922); //Experimental
let res = GetActiveScreenResolution();
emitNet(events.SELLOUT_FETCH_LISTING);
emitNet('phone:getCredentials') // Gets the credentials. Will eventually most likely only get the phone number and name, idk.
SetCursorLocation(0.936, 0.922) //Experimental
let res = GetActiveScreenResolution()
SendNuiMessage(
JSON.stringify({
app: "PHONE",
@@ -270,9 +271,10 @@ async function Phone() {
isPhoneOpen = true;
await phoneOpenAnim();
emitNet(events.CONTACTS_GET_CONTACTS);
emitNet("phone:getCredentials");
SetCursorLocation(0.936, 0.922); //Experimental
let res = GetActiveScreenResolution();
emitNet(events.SELLOUT_FETCH_LISTING);
emitNet('phone:getCredentials')
SetCursorLocation(0.936, 0.922) //Experimental
let res = GetActiveScreenResolution()
SendNuiMessage(
JSON.stringify({
app: "PHONE",
+21
View File
@@ -0,0 +1,21 @@
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({
app: "SELLOUT",
method: "setListings",
data: listing
})
)
})
+4 -3
View File
@@ -1,7 +1,8 @@
import { ESXClient } from "fivem-esx-js/client/esx_client";
import "./cl_main";
import "./cl_twitter";
import "./cl_contacts";
import './cl_main';
import './cl_twitter';
import './cl_contacts';
import './cl_sellout';
export let ESX: ESXClient = null;
+9
View File
@@ -0,0 +1,9 @@
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
}
+5 -4
View File
@@ -1,9 +1,10 @@
import { ESXServer } from "fivem-esx-js/server/esx_server";
import "./db";
import "./sv_twitter";
import "./sv_main";
import "./sv_contacts";
import './db';
import './sv_twitter';
import './sv_main';
import './sv_contacts';
import './sv_sellout';
export let ESX: ESXServer = null;
+12 -14
View File
@@ -37,19 +37,17 @@ onNet(events.CONTACTS_GET_CONTACTS, async () => {
} catch (error) {
console.log("Failed to fetch contacts: ", error);
}
})
onNet(events.CONTACTS_ADD_CONTACT, (number: string, display: string, avatar: string) => {
try {
const _source = (global as any).source;
const xPlayer = ESX.GetPlayerFromId(_source);
const _identifier = xPlayer.getIdentifier()
addContact(_identifier, number, display, avatar);
//emit(events.CONTACTS_GET_CONTACTS);
} catch(error) {
console.log("Failed to add contact: ", error);
});
onNet(
events.CONTACTS_ADD_CONTACT,
(number: string, display: string, avatar: string) => {
try {
const _source = (global as any).source;
const xPlayer = ESX.GetPlayerFromId(_source);
const _identifier = xPlayer.getIdentifier();
addContact(_identifier, number, display, avatar);
emit(events.CONTACTS_GET_CONTACTS);
} catch (error) {
console.log("Failed to add contact: ", error);
}
}
);
+51
View File
@@ -0,0 +1,51 @@
import events from '../utils/events';
import { ESX, getSource } from './server';
import { pool } from './db';
interface IListing {
title: string;
name: 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[]> {
const query = "SELECT * FROM npwd_sellout_listings ORDER BY id DESC";
const [ results ] = await pool.query(query);
const listings = <IListing[]>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)
}
})
onNet(events.SELLOUT_FETCH_LISTING, async () => {
try {
console.log("Fetching all listings")
const listings = await fetchAllListings();
console.log("ADDED")
emitNet(events.SELLOUT_SEND_LISTING, getSource(), listings)
} catch(error) {
console.log(error)
}
})
+11 -6
View File
@@ -22,9 +22,14 @@ export default {
TWITTER_TOGGLE_LIKE_FAILURE: "toggleLikeFailed",
// Contacts
CONTACTS_SEND_CONTACTS: "phone:sendContacts",
CONTACTS_GET_CONTACTS: "phone:getContacts",
CONTACTS_ADD_CONTACT_NUI: "contacts:add",
CONTACTS_ADD_CONTACT: "contacts:add",
CONTACTS_UPDATE_CONTACTS: "phone:updateContacts",
};
CONTACTS_SEND_CONTACTS: 'phone:sendContacts',
CONTACTS_GET_CONTACTS: 'phone:getContacts',
CONTACTS_ADD_CONTACT_NUI: 'contacts:add',
CONTACTS_ADD_CONTACT: 'contacts:add',
CONTACTS_UPDATE_CONTACTS: 'phone:updateContacts',
// Sellout
SELLOUT_ADD_LISTING: 'phone:addListing',
SELLOUT_FETCH_LISTING: 'phone:fetchAllListing',
SELLOUT_SEND_LISTING: 'phone:sendAllListings'
}