mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
tweak(marketplace): Tweak marketplace to match current fetching std
This commit is contained in:
1 parent
10639260e0
commit
5e225ca736
23 files changed
+148
-136
No files matched your search
@@ -3,13 +3,15 @@ import { AppWrapper } from '../../../ui/components';
|
|||||||
import { AppTitle } from '../../../ui/components/AppTitle';
|
import { AppTitle } from '../../../ui/components/AppTitle';
|
||||||
import { AppContent } from '../../../ui/components/AppContent';
|
import { AppContent } from '../../../ui/components/AppContent';
|
||||||
import { useApp } from '../../../os/apps/hooks/useApps';
|
import { useApp } from '../../../os/apps/hooks/useApps';
|
||||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
|
||||||
import { Route } from 'react-router-dom';
|
import { Route } from 'react-router-dom';
|
||||||
import ContactsInfoPage from './views/ContactInfo';
|
import ContactsInfoPage from './views/ContactInfo';
|
||||||
import { ContactPage } from './views/ContactsPage';
|
import { ContactPage } from './views/ContactsPage';
|
||||||
import { ContactsThemeProvider } from '../providers/ContactsThemeProvider';
|
import { ContactsThemeProvider } from '../providers/ContactsThemeProvider';
|
||||||
import { ContactEvents } from '../../../../../typings/contact';
|
|
||||||
import { LoadingSpinner } from '../../../ui/components/LoadingSpinner';
|
import { LoadingSpinner } from '../../../ui/components/LoadingSpinner';
|
||||||
|
import { makeStyles } from '@material-ui/core/styles';
|
||||||
|
import { useHistory } from 'react-router';
|
||||||
|
import { Fab, Theme } from '@material-ui/core';
|
||||||
|
import PersonAddIcon from '@material-ui/icons/PersonAdd';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) => ({
|
const useStyles = makeStyles((theme: Theme) => ({
|
||||||
absolute: {
|
absolute: {
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
import { Box, Tooltip, Button } from '@material-ui/core';
|
import { Box, Tooltip, Button } from '@material-ui/core';
|
||||||
import { makeStyles, Theme } from '@material-ui/core/styles';
|
import { makeStyles, Theme } from '@material-ui/core/styles';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {
|
import { MarketplaceEvents, MarketplaceListing } from '../../../../../../typings/marketplace';
|
||||||
MarketplaceActionResp,
|
|
||||||
MarketplaceEvents,
|
|
||||||
MarketplaceListing,
|
|
||||||
} from '../../../../../../typings/marketplace';
|
|
||||||
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
|
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
|
||||||
import DeleteIcon from '@material-ui/icons/Delete';
|
import DeleteIcon from '@material-ui/icons/Delete';
|
||||||
import ReportIcon from '@material-ui/icons/Report';
|
import ReportIcon from '@material-ui/icons/Report';
|
||||||
@@ -17,6 +13,7 @@ import { useHistory } from 'react-router';
|
|||||||
import { CallEvents } from '../../../../../../typings/call';
|
import { CallEvents } from '../../../../../../typings/call';
|
||||||
import { fetchNui } from '../../../../utils/fetchNui';
|
import { fetchNui } from '../../../../utils/fetchNui';
|
||||||
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
||||||
|
import { ServerPromiseResp } from '../../../../../../typings/common';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) => ({
|
const useStyles = makeStyles((theme: Theme) => ({
|
||||||
icon: {
|
icon: {
|
||||||
@@ -33,12 +30,12 @@ export const ListingActions: React.FC<MarketplaceListing> = ({ children, ...list
|
|||||||
const { addAlert } = useSnackbar();
|
const { addAlert } = useSnackbar();
|
||||||
|
|
||||||
const handleDeleteListing = () => {
|
const handleDeleteListing = () => {
|
||||||
fetchNui<MarketplaceActionResp>(MarketplaceEvents.DELETE_LISTING, {
|
fetchNui<ServerPromiseResp>(MarketplaceEvents.DELETE_LISTING, {
|
||||||
id: listing.id,
|
id: listing.id,
|
||||||
}).then(({ err, errMsg }) => {
|
}).then((resp) => {
|
||||||
if (err) {
|
if (resp.status !== 'ok') {
|
||||||
return addAlert({
|
return addAlert({
|
||||||
message: t(errMsg),
|
message: t('APPS_MARKETPLACE_DELETE_LISTING_FAILED'),
|
||||||
type: 'error',
|
type: 'error',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -51,12 +48,12 @@ export const ListingActions: React.FC<MarketplaceListing> = ({ children, ...list
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleReportListing = () => {
|
const handleReportListing = () => {
|
||||||
fetchNui<MarketplaceActionResp>(MarketplaceEvents.REPORT_LISTING, {
|
fetchNui<ServerPromiseResp>(MarketplaceEvents.REPORT_LISTING, {
|
||||||
listingId: listing.id,
|
listingId: listing.id,
|
||||||
}).then(({ err, errMsg }) => {
|
}).then((resp) => {
|
||||||
if (err) {
|
if (resp.status !== 'ok') {
|
||||||
return addAlert({
|
return addAlert({
|
||||||
message: t(errMsg),
|
message: t('APPS_MARKETPLACE_REPORT_LISTING_FAILED'),
|
||||||
type: 'error',
|
type: 'error',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { MarketplaceList } from './MarketplaceList';
|
import { MarketplaceList } from './MarketplaceList';
|
||||||
import { Box, CircularProgress } from '@material-ui/core';
|
import { LoadingSpinner } from '../../../../ui/components/LoadingSpinner';
|
||||||
|
|
||||||
const LoadingListings: React.FC = () => (
|
|
||||||
<Box display="flex" flexGrow={1} width="100%" justifyContent="center" alignItems="center">
|
|
||||||
<CircularProgress />
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
|
|
||||||
export const MarketplaceListContainer: React.FC = () => {
|
export const MarketplaceListContainer: React.FC = () => {
|
||||||
return (
|
return (
|
||||||
<React.Suspense fallback={<LoadingListings />}>
|
<React.Suspense fallback={<LoadingSpinner />}>
|
||||||
<MarketplaceList />
|
<MarketplaceList />
|
||||||
</React.Suspense>
|
</React.Suspense>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { atom, selector, useRecoilValue, useSetRecoilState } from 'recoil';
|
import { atom, selector, useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
|
||||||
import {
|
import {
|
||||||
MarketplaceEvents,
|
MarketplaceEvents,
|
||||||
MarketplaceFetchResp,
|
MarketplaceFetchResp,
|
||||||
MarketplaceListing,
|
MarketplaceListing,
|
||||||
} from '../../../../../typings/marketplace';
|
} from '../../../../../typings/marketplace';
|
||||||
import { fetchNui } from '../../../utils/fetchNui';
|
import { fetchNui } from '../../../utils/fetchNui';
|
||||||
|
import { isEnvBrowser } from '../../../utils/misc';
|
||||||
|
|
||||||
const defaultData: MarketplaceListing[] = [
|
const defaultData: MarketplaceListing[] = [
|
||||||
{
|
{
|
||||||
@@ -36,9 +37,11 @@ const listingState = atom<MarketplaceListing[]>({
|
|||||||
try {
|
try {
|
||||||
return (await fetchNui<MarketplaceFetchResp>(MarketplaceEvents.FETCH_LISTING)).data;
|
return (await fetchNui<MarketplaceFetchResp>(MarketplaceEvents.FETCH_LISTING)).data;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (process.env.NODE_ENV === 'development' && !process.env.REACT_APP_IN_GAME) {
|
if (isEnvBrowser()) {
|
||||||
return defaultData;
|
return defaultData;
|
||||||
}
|
}
|
||||||
|
console.error(e);
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -46,3 +49,4 @@ const listingState = atom<MarketplaceListing[]>({
|
|||||||
|
|
||||||
export const useListingValue = () => useRecoilValue(listingState);
|
export const useListingValue = () => useRecoilValue(listingState);
|
||||||
export const useSetListings = () => useSetRecoilState(listingState);
|
export const useSetListings = () => useSetRecoilState(listingState);
|
||||||
|
export const useListings = () => useRecoilState(listingState);
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { useCallback } from 'react';
|
||||||
|
import { useSetListings } from './state';
|
||||||
|
import { MarketplaceListing } from '../../../../../typings/marketplace';
|
||||||
|
|
||||||
|
interface MarketplaceActionValues {
|
||||||
|
deleteListing: (id: number) => void;
|
||||||
|
addListing: (listing: MarketplaceListing) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useMarketplaceActions = (): MarketplaceActionValues => {
|
||||||
|
const setListings = useSetListings();
|
||||||
|
|
||||||
|
const deleteListing = useCallback(
|
||||||
|
(id: number) => {
|
||||||
|
setListings((curListings) => [...curListings].filter((listing) => listing.id !== id));
|
||||||
|
},
|
||||||
|
[setListings],
|
||||||
|
);
|
||||||
|
|
||||||
|
const addListing = useCallback(
|
||||||
|
(listing: MarketplaceListing) => {
|
||||||
|
setListings((curListings) => [...curListings, listing]);
|
||||||
|
},
|
||||||
|
[setListings],
|
||||||
|
);
|
||||||
|
|
||||||
|
return { deleteListing, addListing };
|
||||||
|
};
|
||||||
@@ -1,31 +1,31 @@
|
|||||||
import { useNuiEvent } from 'fivem-nui-react-lib';
|
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||||
import {
|
import {
|
||||||
MarketPlaceBroadcastData,
|
MarketplaceBroadcastAddDTO,
|
||||||
MarketplaceDeleteDTO,
|
MarketplaceDeleteDTO,
|
||||||
MarketplaceEvents,
|
MarketplaceEvents,
|
||||||
MarketplaceListing,
|
|
||||||
} from '../../../../../typings/marketplace';
|
} from '../../../../../typings/marketplace';
|
||||||
import { useSetListings } from './state';
|
import { useMarketplaceActions } from './useMarketplaceActions';
|
||||||
|
|
||||||
export const useMarketplaceService = () => {
|
export const useMarketplaceService = () => {
|
||||||
const setListings = useSetListings();
|
const { addListing, deleteListing } = useMarketplaceActions();
|
||||||
|
|
||||||
useNuiEvent<MarketPlaceBroadcastData>(
|
const addListingHandler = (resp: MarketplaceBroadcastAddDTO) => {
|
||||||
'SELLOUT',
|
addListing(resp.listing);
|
||||||
MarketplaceEvents.BROADCAST_EVENT,
|
};
|
||||||
({ type, listing }) => {
|
|
||||||
if (type === 'ADD') {
|
|
||||||
const typeCastListing = listing as MarketplaceListing;
|
|
||||||
return setListings((curState) => [...curState, typeCastListing]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === 'DELETE') {
|
const deleteListingHandler = (listing: MarketplaceDeleteDTO) => {
|
||||||
const deleteDTO = listing as MarketplaceDeleteDTO;
|
deleteListing(listing.id);
|
||||||
return setListings((currVal) => {
|
};
|
||||||
const arrayPos = currVal.map((item) => item.id).indexOf(deleteDTO.id);
|
|
||||||
return [...currVal].splice(arrayPos);
|
useNuiEvent<MarketplaceBroadcastAddDTO>(
|
||||||
});
|
'MARKETPLACE',
|
||||||
}
|
MarketplaceEvents.BROADCAST_ADD,
|
||||||
},
|
addListingHandler,
|
||||||
|
);
|
||||||
|
|
||||||
|
useNuiEvent<MarketplaceDeleteDTO>(
|
||||||
|
'MARKETPLACE',
|
||||||
|
MarketplaceEvents.BROADCAST_DELETE,
|
||||||
|
deleteListingHandler,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
"APPS_NOTES": "Bilješke",
|
"APPS_NOTES": "Bilješke",
|
||||||
"APPS_EXAMPLE": "Primjerna Aplikacija",
|
"APPS_EXAMPLE": "Primjerna Aplikacija",
|
||||||
"APPS_TWITTER": "Twitter",
|
"APPS_TWITTER": "Twitter",
|
||||||
"APPS_SELLOUT": "Market",
|
"APPS_MARKETPLACE": "Market",
|
||||||
"APPS_CAMERA": "Camera",
|
"APPS_CAMERA": "Camera",
|
||||||
|
|
||||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Dolazi telefonski poziv",
|
"APPS_DIALER_INCOMING_CALL_TITLE": "Dolazi telefonski poziv",
|
||||||
|
|||||||
@@ -59,7 +59,7 @@
|
|||||||
"APPS_NOTES": "Notes",
|
"APPS_NOTES": "Notes",
|
||||||
"APPS_EXAMPLE": "Example app",
|
"APPS_EXAMPLE": "Example app",
|
||||||
"APPS_TWITTER": "Twitter",
|
"APPS_TWITTER": "Twitter",
|
||||||
"APPS_SELLOUT": "Marketplace",
|
"APPS_MARKETPLACE": "Marketplace",
|
||||||
"APPS_CAMERA": "Camera",
|
"APPS_CAMERA": "Camera",
|
||||||
|
|
||||||
"APPS_CAMERA_FAILED_TO_TAKE_PHOTO": "Photo could not be saved :(",
|
"APPS_CAMERA_FAILED_TO_TAKE_PHOTO": "Photo could not be saved :(",
|
||||||
|
|||||||
@@ -58,7 +58,7 @@
|
|||||||
"APPS_NOTES": "Notas",
|
"APPS_NOTES": "Notas",
|
||||||
"APPS_EXAMPLE": "App de Ejemplo",
|
"APPS_EXAMPLE": "App de Ejemplo",
|
||||||
"APPS_TWITTER": "Twitter",
|
"APPS_TWITTER": "Twitter",
|
||||||
"APPS_SELLOUT": "Mercado",
|
"APPS_MARKETPLACE": "Mercado",
|
||||||
"APPS_CAMERA": "Camara",
|
"APPS_CAMERA": "Camara",
|
||||||
|
|
||||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Llamada entrante",
|
"APPS_DIALER_INCOMING_CALL_TITLE": "Llamada entrante",
|
||||||
|
|||||||
@@ -59,7 +59,7 @@
|
|||||||
"APPS_NOTES": "Notes",
|
"APPS_NOTES": "Notes",
|
||||||
"APPS_EXAMPLE": "App test",
|
"APPS_EXAMPLE": "App test",
|
||||||
"APPS_TWITTER": "Twitter",
|
"APPS_TWITTER": "Twitter",
|
||||||
"APPS_SELLOUT": "Marché",
|
"APPS_MARKETPLACE": "Marché",
|
||||||
"APPS_CAMERA": "Caméra",
|
"APPS_CAMERA": "Caméra",
|
||||||
|
|
||||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Appel entrant",
|
"APPS_DIALER_INCOMING_CALL_TITLE": "Appel entrant",
|
||||||
|
|||||||
@@ -59,7 +59,7 @@
|
|||||||
"APPS_NOTES": "Jegyzetek",
|
"APPS_NOTES": "Jegyzetek",
|
||||||
"APPS_EXAMPLE": "Péla app",
|
"APPS_EXAMPLE": "Péla app",
|
||||||
"APPS_TWITTER": "Twitter",
|
"APPS_TWITTER": "Twitter",
|
||||||
"APPS_SELLOUT": "Pia",
|
"APPS_MARKETPLACE": "Pia",
|
||||||
"APPS_CAMERA": "Kamera",
|
"APPS_CAMERA": "Kamera",
|
||||||
|
|
||||||
"APPS_CAMERA_FAILED_TO_TAKE_PHOTO": "Nem lehet elmenteni a képet :(",
|
"APPS_CAMERA_FAILED_TO_TAKE_PHOTO": "Nem lehet elmenteni a képet :(",
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
"APPS_NOTES": "Notater",
|
"APPS_NOTES": "Notater",
|
||||||
"APPS_EXAMPLE": "Example app",
|
"APPS_EXAMPLE": "Example app",
|
||||||
"APPS_TWITTER": "Twitter",
|
"APPS_TWITTER": "Twitter",
|
||||||
"APPS_SELLOUT": "Marked",
|
"APPS_MARKETPLACE": "Marked",
|
||||||
"APPS_CAMERA": "Kamera",
|
"APPS_CAMERA": "Kamera",
|
||||||
|
|
||||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Innkommende Anrop",
|
"APPS_DIALER_INCOMING_CALL_TITLE": "Innkommende Anrop",
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
"APPS_NOTES": "Notas",
|
"APPS_NOTES": "Notas",
|
||||||
"APPS_EXAMPLE": "Aplicativo exemplo",
|
"APPS_EXAMPLE": "Aplicativo exemplo",
|
||||||
"APPS_TWITTER": "Twitter",
|
"APPS_TWITTER": "Twitter",
|
||||||
"APPS_SELLOUT": "Market",
|
"APPS_MARKETPLACE": "Market",
|
||||||
"APPS_CAMERA": "Camera",
|
"APPS_CAMERA": "Camera",
|
||||||
|
|
||||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Incoming Phone Call",
|
"APPS_DIALER_INCOMING_CALL_TITLE": "Incoming Phone Call",
|
||||||
|
|||||||
@@ -59,7 +59,7 @@
|
|||||||
"APPS_NOTES": "Notas",
|
"APPS_NOTES": "Notas",
|
||||||
"APPS_EXAMPLE": "Aplicativo de exemplo",
|
"APPS_EXAMPLE": "Aplicativo de exemplo",
|
||||||
"APPS_TWITTER": "Twitter",
|
"APPS_TWITTER": "Twitter",
|
||||||
"APPS_SELLOUT": "Mercado",
|
"APPS_MARKETPLACE": "Mercado",
|
||||||
"APPS_CAMERA": "Camera",
|
"APPS_CAMERA": "Camera",
|
||||||
|
|
||||||
"APPS_CAMERA_FAILED_TO_TAKE_PHOTO": "Não foi possível salvar a foto :(",
|
"APPS_CAMERA_FAILED_TO_TAKE_PHOTO": "Não foi possível salvar a foto :(",
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
"APPS_NOTES": "Anteckningar",
|
"APPS_NOTES": "Anteckningar",
|
||||||
"APPS_EXAMPLE": "Exempel app",
|
"APPS_EXAMPLE": "Exempel app",
|
||||||
"APPS_TWITTER": "Twitter",
|
"APPS_TWITTER": "Twitter",
|
||||||
"APPS_SELLOUT": "Market",
|
"APPS_MARKETPLACE": "Market",
|
||||||
"APPS_CAMERA": "Camera",
|
"APPS_CAMERA": "Camera",
|
||||||
|
|
||||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Incoming Phone Call",
|
"APPS_DIALER_INCOMING_CALL_TITLE": "Incoming Phone Call",
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
"APPS_NOTES": "Notlar",
|
"APPS_NOTES": "Notlar",
|
||||||
"APPS_EXAMPLE": "Örnek uygulama",
|
"APPS_EXAMPLE": "Örnek uygulama",
|
||||||
"APPS_TWITTER": "Twitter",
|
"APPS_TWITTER": "Twitter",
|
||||||
"APPS_SELLOUT": "Market",
|
"APPS_MARKETPLACE": "Market",
|
||||||
"APPS_CAMERA": "Camera",
|
"APPS_CAMERA": "Camera",
|
||||||
|
|
||||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Incoming Phone Call",
|
"APPS_DIALER_INCOMING_CALL_TITLE": "Incoming Phone Call",
|
||||||
|
|||||||
@@ -127,13 +127,18 @@ export const APPS: IAppConfig[] = [
|
|||||||
Route: () => <AppRoute id="TWITTER" path="/twitter" component={TwitterApp} emitOnOpen={true} />,
|
Route: () => <AppRoute id="TWITTER" path="/twitter" component={TwitterApp} emitOnOpen={true} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'SELLOUT',
|
id: 'MARKETPLACE',
|
||||||
nameLocale: 'APPS_SELLOUT',
|
nameLocale: 'APPS_MARKETPLACE',
|
||||||
backgroundColor: SELLOUT_APP_PRIMARY_COLOR,
|
backgroundColor: SELLOUT_APP_PRIMARY_COLOR,
|
||||||
color: SELLOUT_APP_ICON_COLOR,
|
color: SELLOUT_APP_ICON_COLOR,
|
||||||
path: '/marketplace',
|
path: '/marketplace',
|
||||||
Route: () => (
|
Route: () => (
|
||||||
<AppRoute id="MARKETPLACE" path="/marketplace" component={MarketplaceApp} emitOnOpen={true} />
|
<AppRoute
|
||||||
|
id="MARKETPLACE"
|
||||||
|
path="/marketplace"
|
||||||
|
component={MarketplaceApp}
|
||||||
|
emitOnOpen={false}
|
||||||
|
/>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -143,12 +143,6 @@ on(`__cfx_nui:${PhoneEvents.UI_IS_READY}`, (_data: any, cb: Function) => {
|
|||||||
* NUI Service Callback Registration
|
* NUI Service Callback Registration
|
||||||
*
|
*
|
||||||
* * * * * * * * * * * * */
|
* * * * * * * * * * * * */
|
||||||
RegisterNuiCallbackType(PhoneEvents.OPEN_APP_LISTINGS);
|
|
||||||
on(`__cfx_nui:${PhoneEvents.OPEN_APP_LISTINGS}`, (data: any, cb: Function) => {
|
|
||||||
emitNet(MarketplaceEvents.FETCH_LISTING);
|
|
||||||
cb();
|
|
||||||
});
|
|
||||||
|
|
||||||
RegisterNuiCallbackType(PhoneEvents.OPEN_APP_NOTES);
|
RegisterNuiCallbackType(PhoneEvents.OPEN_APP_NOTES);
|
||||||
on(`__cfx_nui:${PhoneEvents.OPEN_APP_NOTES}`, (data: any, cb: Function) => {
|
on(`__cfx_nui:${PhoneEvents.OPEN_APP_NOTES}`, (data: any, cb: Function) => {
|
||||||
emitNet(NotesEvents.FETCH_ALL_NOTES);
|
emitNet(NotesEvents.FETCH_ALL_NOTES);
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import { MarketplaceEvents, MarketPlaceBroadcastData } from '../../typings/marketplace';
|
import {
|
||||||
|
MarketplaceBroadcastAddDTO,
|
||||||
|
MarketplaceDeleteDTO,
|
||||||
|
MarketplaceEvents,
|
||||||
|
} from '../../typings/marketplace';
|
||||||
import { RegisterNuiProxy } from './cl_utils';
|
import { RegisterNuiProxy } from './cl_utils';
|
||||||
import { sendMarketplaceEvent } from '../utils/messages';
|
import { sendMarketplaceEvent } from '../utils/messages';
|
||||||
|
|
||||||
@@ -8,6 +12,10 @@ RegisterNuiProxy(MarketplaceEvents.ADD_LISTING);
|
|||||||
RegisterNuiProxy(MarketplaceEvents.DELETE_LISTING);
|
RegisterNuiProxy(MarketplaceEvents.DELETE_LISTING);
|
||||||
RegisterNuiProxy(MarketplaceEvents.REPORT_LISTING);
|
RegisterNuiProxy(MarketplaceEvents.REPORT_LISTING);
|
||||||
|
|
||||||
onNet(MarketplaceEvents.BROADCAST_EVENT, (broadcastEvent: MarketPlaceBroadcastData) => {
|
onNet(MarketplaceEvents.BROADCAST_ADD, (broadcastEvent: MarketplaceBroadcastAddDTO) => {
|
||||||
sendMarketplaceEvent(MarketplaceEvents.BROADCAST_EVENT, broadcastEvent);
|
sendMarketplaceEvent(MarketplaceEvents.BROADCAST_ADD, broadcastEvent);
|
||||||
|
});
|
||||||
|
|
||||||
|
onNet(MarketplaceEvents.BROADCAST_DELETE, (broadcastEvent: MarketplaceDeleteDTO) => {
|
||||||
|
sendMarketplaceEvent(MarketplaceEvents.BROADCAST_DELETE, broadcastEvent);
|
||||||
});
|
});
|
||||||
@@ -1,40 +1,29 @@
|
|||||||
import {
|
import {
|
||||||
MarketplaceEvents,
|
MarketplaceEvents,
|
||||||
|
MarketplaceListing,
|
||||||
MarketplaceListingBase,
|
MarketplaceListingBase,
|
||||||
MarketplaceReportDTO,
|
MarketplaceReportDTO,
|
||||||
} from '../../../typings/marketplace';
|
} from '../../../typings/marketplace';
|
||||||
import PlayerService from '../players/player.service';
|
|
||||||
import { selloutLogger } from './marketplace.utils';
|
import { selloutLogger } from './marketplace.utils';
|
||||||
import MarketplaceService from './marketplace.service';
|
import MarketplaceService from './marketplace.service';
|
||||||
import { onNetPromise } from '../utils/PromiseNetEvents/onNetPromise';
|
import { onNetPromise } from '../utils/PromiseNetEvents/onNetPromise';
|
||||||
import { MarketplaceDeleteDTO } from '../../../typings/marketplace';
|
import { MarketplaceDeleteDTO } from '../../../typings/marketplace';
|
||||||
|
|
||||||
onNetPromise(MarketplaceEvents.FETCH_LISTING, async (reqObj, resp) => {
|
onNetPromise<void, MarketplaceListing[]>(MarketplaceEvents.FETCH_LISTING, async (reqObj, resp) => {
|
||||||
MarketplaceService.handleFetchListings(resp, reqObj.source).catch((e) => {
|
MarketplaceService.handleFetchListings(reqObj, resp).catch((e) => {
|
||||||
selloutLogger.error(
|
selloutLogger.error(
|
||||||
`Error occurred in fetch listing event (${reqObj.source}), Error: ${e.message}`,
|
`Error occurred in fetch listing event (${reqObj.source}), Error: ${e.message}`,
|
||||||
);
|
);
|
||||||
resp({ error: true, errorMsg: '`Error occurred in fetch listing event' });
|
resp({ status: 'error', errorMsg: 'INTERNAL_ERROR' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
onNetPromise<MarketplaceListingBase>(MarketplaceEvents.ADD_LISTING, async (reqObj, resp) => {
|
onNetPromise<MarketplaceListingBase, void>(MarketplaceEvents.ADD_LISTING, async (reqObj, resp) => {
|
||||||
const player = PlayerService.getPlayer(reqObj.source);
|
MarketplaceService.handleAddListing(reqObj, resp).catch((e) => {
|
||||||
MarketplaceService.handleAddListing(
|
|
||||||
{
|
|
||||||
src: reqObj.source,
|
|
||||||
name: player.getName(),
|
|
||||||
username: player.username,
|
|
||||||
number: player.getPhoneNumber(),
|
|
||||||
listing: reqObj.data,
|
|
||||||
identifier: player.getIdentifier(),
|
|
||||||
},
|
|
||||||
resp,
|
|
||||||
).catch((e) => {
|
|
||||||
selloutLogger.error(
|
selloutLogger.error(
|
||||||
`Error occurred in add listing event (${reqObj.source}), Error: ${e.message}`,
|
`Error occurred in add listing event (${reqObj.source}), Error: ${e.message}`,
|
||||||
);
|
);
|
||||||
resp({ error: true, errorMsg: 'Error occurred in add listing event' });
|
resp({ status: 'error', errorMsg: 'INTERNAL_ERROR' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -44,7 +33,7 @@ onNetPromise<MarketplaceDeleteDTO>(MarketplaceEvents.DELETE_LISTING, async (reqO
|
|||||||
selloutLogger.error(
|
selloutLogger.error(
|
||||||
`Error occurred in delete listing event (${reqObj.source}), Error: ${e.message}`,
|
`Error occurred in delete listing event (${reqObj.source}), Error: ${e.message}`,
|
||||||
);
|
);
|
||||||
resp({ error: true, errorMsg: 'Error occurred in delete listing event' });
|
resp({ status: 'error', errorMsg: 'INTERNAL_ERROR' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -54,6 +43,6 @@ onNetPromise<MarketplaceReportDTO>(MarketplaceEvents.REPORT_LISTING, async (reqO
|
|||||||
selloutLogger.error(
|
selloutLogger.error(
|
||||||
`Error occurred in report listing event (${reqObj.source}), Error: ${e.message}`,
|
`Error occurred in report listing event (${reqObj.source}), Error: ${e.message}`,
|
||||||
);
|
);
|
||||||
resp({ error: true, errorMsg: 'Error occured in report listing event' });
|
resp({ status: 'error', errorMsg: 'INTERNAL_ERROR' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -10,16 +10,7 @@ import {
|
|||||||
} from '../../../typings/marketplace';
|
} from '../../../typings/marketplace';
|
||||||
import { notesLogger } from '../notes/notes.utils';
|
import { notesLogger } from '../notes/notes.utils';
|
||||||
import { reportListingToDiscord } from '../discord';
|
import { reportListingToDiscord } from '../discord';
|
||||||
import { PromiseEventReturnFunc, PromiseRequest } from '../utils/PromiseNetEvents/promise.types';
|
import { PromiseEventResp, PromiseRequest } from '../utils/PromiseNetEvents/promise.types';
|
||||||
|
|
||||||
interface HandleAddListingObj {
|
|
||||||
src: number;
|
|
||||||
identifier: string;
|
|
||||||
username: string;
|
|
||||||
name: string;
|
|
||||||
number: any;
|
|
||||||
listing: MarketplaceListingBase;
|
|
||||||
}
|
|
||||||
|
|
||||||
class _MarketplaceService {
|
class _MarketplaceService {
|
||||||
private readonly marketplaceDB: _MarketplaceDB;
|
private readonly marketplaceDB: _MarketplaceDB;
|
||||||
@@ -30,60 +21,65 @@ class _MarketplaceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleAddListing(
|
async handleAddListing(
|
||||||
{ listing, src, identifier, number, name, username }: HandleAddListingObj,
|
reqObj: PromiseRequest<MarketplaceListingBase>,
|
||||||
resp: PromiseEventReturnFunc,
|
resp: PromiseEventResp<void>,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
selloutLogger.debug('Handling add listing, listing:');
|
selloutLogger.debug('Handling add listing, listing:');
|
||||||
selloutLogger.debug(listing);
|
selloutLogger.debug(reqObj.data);
|
||||||
|
|
||||||
|
const player = PlayerService.getPlayer(reqObj.source);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const listingId = await this.marketplaceDB.addListing(
|
const listingId = await this.marketplaceDB.addListing(
|
||||||
identifier,
|
player.getIdentifier(),
|
||||||
username,
|
player.username,
|
||||||
name,
|
player.getName(),
|
||||||
number,
|
player.getPhoneNumber(),
|
||||||
listing,
|
reqObj.data,
|
||||||
);
|
);
|
||||||
// Respond with success to original source
|
// Respond with success to original source
|
||||||
resp({ status: 'ok' });
|
resp({ status: 'ok' });
|
||||||
|
|
||||||
const returnObj: MarketplaceListing = {
|
const returnObj: MarketplaceListing = {
|
||||||
id: listingId,
|
id: listingId,
|
||||||
identifier,
|
identifier: player.getIdentifier(),
|
||||||
name,
|
name: player.getName(),
|
||||||
number,
|
number: player.getPhoneNumber(),
|
||||||
url: listing.url,
|
url: reqObj.data.url,
|
||||||
username,
|
username: player.username,
|
||||||
description: listing.description,
|
description: reqObj.data.description,
|
||||||
title: listing.title,
|
title: reqObj.data.title,
|
||||||
};
|
};
|
||||||
// Broadcast to everyone we are adding a listing
|
// Broadcast to everyone we are adding a listing
|
||||||
emitNet(MarketplaceEvents.BROADCAST_EVENT, -1, { type: 'ADD', listing: returnObj });
|
emitNet(MarketplaceEvents.BROADCAST_ADD, -1, { type: 'ADD', listing: returnObj });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
selloutLogger.error(`Failed to add listing ${e.message}`, {
|
selloutLogger.error(`Failed to add listing ${e.message}`, {
|
||||||
source: src,
|
source: reqObj.source,
|
||||||
});
|
});
|
||||||
|
|
||||||
resp({ err: true, errMsg: 'Failed to create listing' });
|
resp({ status: 'error', errorMsg: 'DB_ERROR' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleFetchListings(resp: PromiseEventReturnFunc, src: number) {
|
async handleFetchListings(
|
||||||
|
req: PromiseRequest<void>,
|
||||||
|
resp: PromiseEventResp<MarketplaceListing[]>,
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
const listings = await this.marketplaceDB.fetchListings();
|
const listings = await this.marketplaceDB.fetchListings();
|
||||||
|
|
||||||
resp({ data: listings, status: 'ok' });
|
resp({ data: listings, status: 'ok' });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
selloutLogger.error(`Failed to fetch listings, ${e.message}`, {
|
selloutLogger.error(`Failed to fetch listings, ${e.message}`, {
|
||||||
source: src,
|
source: req.source,
|
||||||
});
|
});
|
||||||
resp({ err: true, errMsg: 'Failed to fetch listings' });
|
resp({ status: 'error', errorMsg: 'DB_ERROR' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleDeleteListing(
|
async handleDeleteListing(
|
||||||
reqObj: PromiseRequest<MarketplaceDeleteDTO>,
|
reqObj: PromiseRequest<MarketplaceDeleteDTO>,
|
||||||
resp: PromiseEventReturnFunc,
|
resp: PromiseEventResp<void>,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const identifier = PlayerService.getIdentifier(reqObj.source);
|
const identifier = PlayerService.getIdentifier(reqObj.source);
|
||||||
try {
|
try {
|
||||||
@@ -95,17 +91,17 @@ class _MarketplaceService {
|
|||||||
id: reqObj.data.id,
|
id: reqObj.data.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
emitNet(MarketplaceEvents.BROADCAST_EVENT, -1, { type: 'DELETE', listing: returnObj });
|
emitNet(MarketplaceEvents.BROADCAST_DELETE, -1, returnObj);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
notesLogger.error(`Error in handleDeleteListing, ${e.message}`);
|
notesLogger.error(`Error in handleDeleteListing, ${e.message}`);
|
||||||
|
|
||||||
resp({ error: true, errMsg: 'Error in deleting listing' });
|
resp({ status: 'error', errorMsg: 'DB_ERROR' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleReportListing(
|
async handleReportListing(
|
||||||
reqObj: PromiseRequest<MarketplaceReportDTO>,
|
reqObj: PromiseRequest<MarketplaceReportDTO>,
|
||||||
resp: PromiseEventReturnFunc,
|
resp: PromiseEventResp<void>,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const rListing = await this.marketplaceDB.getListing(reqObj.data.id);
|
const rListing = await this.marketplaceDB.getListing(reqObj.data.id);
|
||||||
@@ -118,7 +114,7 @@ class _MarketplaceService {
|
|||||||
|
|
||||||
if (reportExists) {
|
if (reportExists) {
|
||||||
selloutLogger.error(`This listing has already been reported`);
|
selloutLogger.error(`This listing has already been reported`);
|
||||||
resp({ error: true, errorMsg: 'Listing already exists' });
|
resp({ status: 'error', errorMsg: 'REPORT_EXISTS' });
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.marketplaceDB.reportListing(rListing.id, rListing.name);
|
await this.marketplaceDB.reportListing(rListing.id, rListing.name);
|
||||||
@@ -127,7 +123,7 @@ class _MarketplaceService {
|
|||||||
selloutLogger.error(`Failed to report listing ${e.message}`, {
|
selloutLogger.error(`Failed to report listing ${e.message}`, {
|
||||||
source: reqObj.source,
|
source: reqObj.source,
|
||||||
});
|
});
|
||||||
resp({ error: true, errorMsg: 'Failed to report listing' });
|
resp({ status: 'error', errorMsg: 'DB_ERROR' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ export default {
|
|||||||
MATCH: 'MATCH',
|
MATCH: 'MATCH',
|
||||||
MESSAGES: 'MESSAGES',
|
MESSAGES: 'MESSAGES',
|
||||||
NOTES: 'NOTES',
|
NOTES: 'NOTES',
|
||||||
MARKETPLACE: 'SELLOUT',
|
MARKETPLACE: 'MARKETPLACE',
|
||||||
CONTACTS: 'CONTACTS',
|
CONTACTS: 'CONTACTS',
|
||||||
CAMERA: 'CAMERA',
|
CAMERA: 'CAMERA',
|
||||||
};
|
};
|
||||||
+6
-11
@@ -33,7 +33,12 @@ export enum MarketplaceEvents {
|
|||||||
REPORT_LISTING_SUCCESS = 'npwd:reportListingSuccess',
|
REPORT_LISTING_SUCCESS = 'npwd:reportListingSuccess',
|
||||||
REPORT_LISTING_SUCESS = 'npwd:reportListingFailed',
|
REPORT_LISTING_SUCESS = 'npwd:reportListingFailed',
|
||||||
SEND_ALERT = 'nwpd:sendListingAlert',
|
SEND_ALERT = 'nwpd:sendListingAlert',
|
||||||
BROADCAST_EVENT = 'npwd:sendMarketplaceBroadcast',
|
BROADCAST_ADD = 'npwd:sendMarketplaceBroadcastAdd',
|
||||||
|
BROADCAST_DELETE = 'npwd:sendMarketplaceBroadcastDelete',
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MarketplaceBroadcastAddDTO {
|
||||||
|
listing: MarketplaceListing;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MarketplaceDeleteDTO {
|
export interface MarketplaceDeleteDTO {
|
||||||
@@ -43,13 +48,3 @@ export interface MarketplaceDeleteDTO {
|
|||||||
export interface MarketplaceReportDTO {
|
export interface MarketplaceReportDTO {
|
||||||
id: number;
|
id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MarketPlaceBroadcastData =
|
|
||||||
| {
|
|
||||||
type: 'ADD';
|
|
||||||
listing: MarketplaceListing;
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: 'DELETE';
|
|
||||||
listing: MarketplaceDeleteDTO;
|
|
||||||
};
|
|
||||||
Reference in new issue
Block a user