diff --git a/phone/src/apps/marketplace/components/MarketplaceApp.tsx b/phone/src/apps/marketplace/components/MarketplaceApp.tsx index 1b694c4..3fcce5c 100644 --- a/phone/src/apps/marketplace/components/MarketplaceApp.tsx +++ b/phone/src/apps/marketplace/components/MarketplaceApp.tsx @@ -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 = () => { ); }; - -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: '', - }, - ], - }, -]); diff --git a/phone/src/apps/marketplace/components/form/ListingForm.tsx b/phone/src/apps/marketplace/components/form/ListingForm.tsx index 293b153..b6e8185 100644 --- a/phone/src/apps/marketplace/components/form/ListingForm.tsx +++ b/phone/src/apps/marketplace/components/form/ListingForm.tsx @@ -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(MarketplaceEvents.ADD_LISTING, { + fetchNui>(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', }); } diff --git a/phone/src/apps/marketplace/hooks/state.ts b/phone/src/apps/marketplace/hooks/state.ts index 82ba787..32d2180 100644 --- a/phone/src/apps/marketplace/hooks/state.ts +++ b/phone/src/apps/marketplace/hooks/state.ts @@ -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({ key: 'defaultListings', get: async () => { try { - return (await fetchNui(MarketplaceEvents.FETCH_LISTING)).data; + const resp = await fetchNui>( + MarketplaceEvents.FETCH_LISTING, + ); + + return resp.data; } catch (e) { if (isEnvBrowser()) { return defaultData; diff --git a/phone/src/apps/marketplace/hooks/useMarketplaceService.ts b/phone/src/apps/marketplace/hooks/useMarketplaceService.ts index 83d16f6..2d293b0 100644 --- a/phone/src/apps/marketplace/hooks/useMarketplaceService.ts +++ b/phone/src/apps/marketplace/hooks/useMarketplaceService.ts @@ -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( 'MARKETPLACE', diff --git a/resources/server/marketplace/marketplace.db.ts b/resources/server/marketplace/marketplace.db.ts index 8888b12..8313c1d 100644 --- a/resources/server/marketplace/marketplace.db.ts +++ b/resources/server/marketplace/marketplace.db.ts @@ -7,7 +7,7 @@ export class _MarketplaceDB { identifier: string, username: string, name: string, - number: any, + number: string, listing: MarketplaceListingBase, ): Promise { const query = diff --git a/typings/marketplace.ts b/typings/marketplace.ts index f70064b..eb06c8c 100644 --- a/typings/marketplace.ts +++ b/typings/marketplace.ts @@ -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', }