chore(marketplace): Misc cleanups

This commit is contained in:
Taso committed 2021-06-10 17:52:14 -04:00
1 parent 865a8e44de
commit 9404a6dd26
6 files changed
+27 -62

No files matched your search

@@ -5,9 +5,7 @@ import { MarketplaceListContainer } from './MarketplaceList/MarketplaceListConta
import { NavigationBar } from './navigation/NavigationBar';
import { Switch, Route } from 'react-router-dom';
import { ListingFormContainer } from './form/ListingFormContainer';
import InjectDebugData from '../../../os/debug/InjectDebugData';
import { MarketplaceThemeProvider } from '../providers/MarketplaceThemeProvider';
import { MarketplaceEvents } from '../../../../../typings/marketplace';
import { AppTitle } from '../../../ui/components/AppTitle';
import { useApp } from '../../../os/apps/hooks/useApps';
@@ -29,29 +27,3 @@ export const MarketplaceApp = () => {
</MarketplaceThemeProvider>
);
};
InjectDebugData([
{
app: 'SELLOUT',
method: MarketplaceEvents.SEND_LISTING,
data: [
{
id: 1,
name: 'Some guy',
number: '111-1134',
title: 'eeeeeeeeeeeeeeeeeeeeeeeee',
description:
'skldfsdEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE',
url: 'https://beta.iodine.gg/706Y3.jpeg',
},
{
id: 2,
name: 'Some other dude',
number: '666-6666',
title: 'Material',
description: 'Selling my wife',
url: '',
},
],
},
]);
@@ -1,6 +1,6 @@
import React, { useEffect, useState, useCallback } from 'react';
import { makeStyles, Button, Box } from '@material-ui/core';
import { MarketplaceActionResp, MarketplaceEvents } from '../../../../../../typings/marketplace';
import { MarketplaceEvents, MarketplaceListing } from '../../../../../../typings/marketplace';
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
import { useTranslation } from 'react-i18next';
import ImageIcon from '@material-ui/icons/Image';
@@ -10,6 +10,7 @@ import { useQueryParams } from '../../../../common/hooks/useQueryParams';
import { deleteQueryFromLocation } from '../../../../common/utils/deleteQueryFromLocation';
import { TextField } from '../../../../ui/components/Input';
import { fetchNui } from '../../../../utils/fetchNui';
import { ServerPromiseResp } from '../../../../../../typings/common';
const useStyles = makeStyles((theme) => ({
root: {
@@ -49,14 +50,14 @@ export const ListingForm = () => {
const addListing = () => {
if (title !== '' && description !== '') {
fetchNui<MarketplaceActionResp>(MarketplaceEvents.ADD_LISTING, {
fetchNui<ServerPromiseResp<MarketplaceListing[]>>(MarketplaceEvents.ADD_LISTING, {
title,
description,
url,
}).then(({ err, errMsg }) => {
if (err) {
}).then((resp) => {
if (resp.status !== 'ok') {
return addAlert({
message: t('errMsg'),
message: t('APPS_MARKETPLACE_CREATE_LISTING_FAILED'),
type: 'error',
});
}
+7 -6
View File
@@ -1,9 +1,6 @@
import { atom, selector, useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
import {
MarketplaceEvents,
MarketplaceFetchResp,
MarketplaceListing,
} from '../../../../../typings/marketplace';
import { ServerPromiseResp } from '../../../../../typings/common';
import { MarketplaceEvents, MarketplaceListing } from '../../../../../typings/marketplace';
import { fetchNui } from '../../../utils/fetchNui';
import { isEnvBrowser } from '../../../utils/misc';
@@ -35,7 +32,11 @@ const listingState = atom<MarketplaceListing[]>({
key: 'defaultListings',
get: async () => {
try {
return (await fetchNui<MarketplaceFetchResp>(MarketplaceEvents.FETCH_LISTING)).data;
const resp = await fetchNui<ServerPromiseResp<MarketplaceListing[]>>(
MarketplaceEvents.FETCH_LISTING,
);
return resp.data;
} catch (e) {
if (isEnvBrowser()) {
return defaultData;
@@ -5,17 +5,24 @@ import {
MarketplaceEvents,
} from '../../../../../typings/marketplace';
import { useMarketplaceActions } from './useMarketplaceActions';
import { useCallback } from 'react';
export const useMarketplaceService = () => {
const { addListing, deleteListing } = useMarketplaceActions();
const addListingHandler = (resp: MarketplaceBroadcastAddDTO) => {
addListing(resp.listing);
};
const addListingHandler = useCallback(
(resp: MarketplaceBroadcastAddDTO) => {
addListing(resp.listing);
},
[addListing],
);
const deleteListingHandler = (listing: MarketplaceDeleteDTO) => {
deleteListing(listing.id);
};
const deleteListingHandler = useCallback(
(listing: MarketplaceDeleteDTO) => {
deleteListing(listing.id);
},
[deleteListing],
);
useNuiEvent<MarketplaceBroadcastAddDTO>(
'MARKETPLACE',
@@ -7,7 +7,7 @@ export class _MarketplaceDB {
identifier: string,
username: string,
name: string,
number: any,
number: string,
listing: MarketplaceListingBase,
): Promise<number> {
const query =
-16
View File
@@ -12,27 +12,11 @@ export interface MarketplaceListingBase {
description: string;
}
export interface MarketplaceFetchResp extends MarketplaceActionResp {
data: MarketplaceListing[];
}
export interface MarketplaceActionResp {
err: boolean;
errMsg?: string;
}
export enum MarketplaceEvents {
ADD_LISTING = 'npwd:addListing',
ADD_LISTING_SUCCESS = 'npwd:addListingSuccess',
FETCH_LISTING = 'npwd:fetchAllListings',
SEND_LISTING = 'npwd:sendAllListings',
ACTION_RESULT = 'npwd:selloutActionResult',
DELETE_LISTING = 'npwd:marketplaceDeleteListing',
DELETE_LISTING_SUCCESS = 'npwd:marketplaceDeleteListingSuccess',
REPORT_LISTING = 'npwd:reportListing',
REPORT_LISTING_SUCCESS = 'npwd:reportListingSuccess',
REPORT_LISTING_SUCESS = 'npwd:reportListingFailed',
SEND_ALERT = 'nwpd:sendListingAlert',
BROADCAST_ADD = 'npwd:sendMarketplaceBroadcastAdd',
BROADCAST_DELETE = 'npwd:sendMarketplaceBroadcastDelete',
}