mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +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 { AppContent } from '../../../ui/components/AppContent';
|
||||
import { useApp } from '../../../os/apps/hooks/useApps';
|
||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||
import { Route } from 'react-router-dom';
|
||||
import ContactsInfoPage from './views/ContactInfo';
|
||||
import { ContactPage } from './views/ContactsPage';
|
||||
import { ContactsThemeProvider } from '../providers/ContactsThemeProvider';
|
||||
import { ContactEvents } from '../../../../../typings/contact';
|
||||
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) => ({
|
||||
absolute: {
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import { Box, Tooltip, Button } from '@material-ui/core';
|
||||
import { makeStyles, Theme } from '@material-ui/core/styles';
|
||||
import React from 'react';
|
||||
import {
|
||||
MarketplaceActionResp,
|
||||
MarketplaceEvents,
|
||||
MarketplaceListing,
|
||||
} from '../../../../../../typings/marketplace';
|
||||
import { MarketplaceEvents, MarketplaceListing } from '../../../../../../typings/marketplace';
|
||||
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
|
||||
import DeleteIcon from '@material-ui/icons/Delete';
|
||||
import ReportIcon from '@material-ui/icons/Report';
|
||||
@@ -17,6 +13,7 @@ import { useHistory } from 'react-router';
|
||||
import { CallEvents } from '../../../../../../typings/call';
|
||||
import { fetchNui } from '../../../../utils/fetchNui';
|
||||
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
||||
import { ServerPromiseResp } from '../../../../../../typings/common';
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => ({
|
||||
icon: {
|
||||
@@ -33,12 +30,12 @@ export const ListingActions: React.FC<MarketplaceListing> = ({ children, ...list
|
||||
const { addAlert } = useSnackbar();
|
||||
|
||||
const handleDeleteListing = () => {
|
||||
fetchNui<MarketplaceActionResp>(MarketplaceEvents.DELETE_LISTING, {
|
||||
fetchNui<ServerPromiseResp>(MarketplaceEvents.DELETE_LISTING, {
|
||||
id: listing.id,
|
||||
}).then(({ err, errMsg }) => {
|
||||
if (err) {
|
||||
}).then((resp) => {
|
||||
if (resp.status !== 'ok') {
|
||||
return addAlert({
|
||||
message: t(errMsg),
|
||||
message: t('APPS_MARKETPLACE_DELETE_LISTING_FAILED'),
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
@@ -51,12 +48,12 @@ export const ListingActions: React.FC<MarketplaceListing> = ({ children, ...list
|
||||
};
|
||||
|
||||
const handleReportListing = () => {
|
||||
fetchNui<MarketplaceActionResp>(MarketplaceEvents.REPORT_LISTING, {
|
||||
fetchNui<ServerPromiseResp>(MarketplaceEvents.REPORT_LISTING, {
|
||||
listingId: listing.id,
|
||||
}).then(({ err, errMsg }) => {
|
||||
if (err) {
|
||||
}).then((resp) => {
|
||||
if (resp.status !== 'ok') {
|
||||
return addAlert({
|
||||
message: t(errMsg),
|
||||
message: t('APPS_MARKETPLACE_REPORT_LISTING_FAILED'),
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
import React from 'react';
|
||||
import { MarketplaceList } from './MarketplaceList';
|
||||
import { Box, CircularProgress } from '@material-ui/core';
|
||||
|
||||
const LoadingListings: React.FC = () => (
|
||||
<Box display="flex" flexGrow={1} width="100%" justifyContent="center" alignItems="center">
|
||||
<CircularProgress />
|
||||
</Box>
|
||||
);
|
||||
import { LoadingSpinner } from '../../../../ui/components/LoadingSpinner';
|
||||
|
||||
export const MarketplaceListContainer: React.FC = () => {
|
||||
return (
|
||||
<React.Suspense fallback={<LoadingListings />}>
|
||||
<React.Suspense fallback={<LoadingSpinner />}>
|
||||
<MarketplaceList />
|
||||
</React.Suspense>
|
||||
);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { atom, selector, useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
import { atom, selector, useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
import {
|
||||
MarketplaceEvents,
|
||||
MarketplaceFetchResp,
|
||||
MarketplaceListing,
|
||||
} from '../../../../../typings/marketplace';
|
||||
import { fetchNui } from '../../../utils/fetchNui';
|
||||
import { isEnvBrowser } from '../../../utils/misc';
|
||||
|
||||
const defaultData: MarketplaceListing[] = [
|
||||
{
|
||||
@@ -36,9 +37,11 @@ const listingState = atom<MarketplaceListing[]>({
|
||||
try {
|
||||
return (await fetchNui<MarketplaceFetchResp>(MarketplaceEvents.FETCH_LISTING)).data;
|
||||
} catch (e) {
|
||||
if (process.env.NODE_ENV === 'development' && !process.env.REACT_APP_IN_GAME) {
|
||||
if (isEnvBrowser()) {
|
||||
return defaultData;
|
||||
}
|
||||
console.error(e);
|
||||
return [];
|
||||
}
|
||||
},
|
||||
}),
|
||||
@@ -46,3 +49,4 @@ const listingState = atom<MarketplaceListing[]>({
|
||||
|
||||
export const useListingValue = () => useRecoilValue(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 {
|
||||
MarketPlaceBroadcastData,
|
||||
MarketplaceBroadcastAddDTO,
|
||||
MarketplaceDeleteDTO,
|
||||
MarketplaceEvents,
|
||||
MarketplaceListing,
|
||||
} from '../../../../../typings/marketplace';
|
||||
import { useSetListings } from './state';
|
||||
import { useMarketplaceActions } from './useMarketplaceActions';
|
||||
|
||||
export const useMarketplaceService = () => {
|
||||
const setListings = useSetListings();
|
||||
const { addListing, deleteListing } = useMarketplaceActions();
|
||||
|
||||
useNuiEvent<MarketPlaceBroadcastData>(
|
||||
'SELLOUT',
|
||||
MarketplaceEvents.BROADCAST_EVENT,
|
||||
({ type, listing }) => {
|
||||
if (type === 'ADD') {
|
||||
const typeCastListing = listing as MarketplaceListing;
|
||||
return setListings((curState) => [...curState, typeCastListing]);
|
||||
}
|
||||
const addListingHandler = (resp: MarketplaceBroadcastAddDTO) => {
|
||||
addListing(resp.listing);
|
||||
};
|
||||
|
||||
if (type === 'DELETE') {
|
||||
const deleteDTO = listing as MarketplaceDeleteDTO;
|
||||
return setListings((currVal) => {
|
||||
const arrayPos = currVal.map((item) => item.id).indexOf(deleteDTO.id);
|
||||
return [...currVal].splice(arrayPos);
|
||||
});
|
||||
}
|
||||
},
|
||||
const deleteListingHandler = (listing: MarketplaceDeleteDTO) => {
|
||||
deleteListing(listing.id);
|
||||
};
|
||||
|
||||
useNuiEvent<MarketplaceBroadcastAddDTO>(
|
||||
'MARKETPLACE',
|
||||
MarketplaceEvents.BROADCAST_ADD,
|
||||
addListingHandler,
|
||||
);
|
||||
|
||||
useNuiEvent<MarketplaceDeleteDTO>(
|
||||
'MARKETPLACE',
|
||||
MarketplaceEvents.BROADCAST_DELETE,
|
||||
deleteListingHandler,
|
||||
);
|
||||
};
|
||||
@@ -14,7 +14,7 @@
|
||||
"APPS_NOTES": "Bilješke",
|
||||
"APPS_EXAMPLE": "Primjerna Aplikacija",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Market",
|
||||
"APPS_MARKETPLACE": "Market",
|
||||
"APPS_CAMERA": "Camera",
|
||||
|
||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Dolazi telefonski poziv",
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
"APPS_NOTES": "Notes",
|
||||
"APPS_EXAMPLE": "Example app",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Marketplace",
|
||||
"APPS_MARKETPLACE": "Marketplace",
|
||||
"APPS_CAMERA": "Camera",
|
||||
|
||||
"APPS_CAMERA_FAILED_TO_TAKE_PHOTO": "Photo could not be saved :(",
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
"APPS_NOTES": "Notas",
|
||||
"APPS_EXAMPLE": "App de Ejemplo",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Mercado",
|
||||
"APPS_MARKETPLACE": "Mercado",
|
||||
"APPS_CAMERA": "Camara",
|
||||
|
||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Llamada entrante",
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
"APPS_NOTES": "Notes",
|
||||
"APPS_EXAMPLE": "App test",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Marché",
|
||||
"APPS_MARKETPLACE": "Marché",
|
||||
"APPS_CAMERA": "Caméra",
|
||||
|
||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Appel entrant",
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
"APPS_NOTES": "Jegyzetek",
|
||||
"APPS_EXAMPLE": "Péla app",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Pia",
|
||||
"APPS_MARKETPLACE": "Pia",
|
||||
"APPS_CAMERA": "Kamera",
|
||||
|
||||
"APPS_CAMERA_FAILED_TO_TAKE_PHOTO": "Nem lehet elmenteni a képet :(",
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
"APPS_NOTES": "Notater",
|
||||
"APPS_EXAMPLE": "Example app",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Marked",
|
||||
"APPS_MARKETPLACE": "Marked",
|
||||
"APPS_CAMERA": "Kamera",
|
||||
|
||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Innkommende Anrop",
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"APPS_NOTES": "Notas",
|
||||
"APPS_EXAMPLE": "Aplicativo exemplo",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Market",
|
||||
"APPS_MARKETPLACE": "Market",
|
||||
"APPS_CAMERA": "Camera",
|
||||
|
||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Incoming Phone Call",
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
"APPS_NOTES": "Notas",
|
||||
"APPS_EXAMPLE": "Aplicativo de exemplo",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Mercado",
|
||||
"APPS_MARKETPLACE": "Mercado",
|
||||
"APPS_CAMERA": "Camera",
|
||||
|
||||
"APPS_CAMERA_FAILED_TO_TAKE_PHOTO": "Não foi possível salvar a foto :(",
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"APPS_NOTES": "Anteckningar",
|
||||
"APPS_EXAMPLE": "Exempel app",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Market",
|
||||
"APPS_MARKETPLACE": "Market",
|
||||
"APPS_CAMERA": "Camera",
|
||||
|
||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Incoming Phone Call",
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"APPS_NOTES": "Notlar",
|
||||
"APPS_EXAMPLE": "Örnek uygulama",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Market",
|
||||
"APPS_MARKETPLACE": "Market",
|
||||
"APPS_CAMERA": "Camera",
|
||||
|
||||
"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} />,
|
||||
},
|
||||
{
|
||||
id: 'SELLOUT',
|
||||
nameLocale: 'APPS_SELLOUT',
|
||||
id: 'MARKETPLACE',
|
||||
nameLocale: 'APPS_MARKETPLACE',
|
||||
backgroundColor: SELLOUT_APP_PRIMARY_COLOR,
|
||||
color: SELLOUT_APP_ICON_COLOR,
|
||||
path: '/marketplace',
|
||||
Route: () => (
|
||||
<AppRoute id="MARKETPLACE" path="/marketplace" component={MarketplaceApp} emitOnOpen={true} />
|
||||
<AppRoute
|
||||
id="MARKETPLACE"
|
||||
path="/marketplace"
|
||||
component={MarketplaceApp}
|
||||
emitOnOpen={false}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user