Tweak/marketplace additions (#137)

Checks for being the OP of the listing. Calling, Message, Delete and Report. 

Updates to Locale is needed.
This commit is contained in:
Christopher Gjelten authored and GitHub committed 2021-03-07 16:30:58 +01:00
1 parent 0203ebbe51
commit 6b6080c4b2
13 files changed
+277 -47

No files matched your search

@@ -34,7 +34,7 @@ InjectDebugData([
{
id: 1,
name: 'Some guy',
number: '123-4567',
number: '111-1134',
title: 'Car',
description: 'Selling this cool car',
url: 'https://i.imgur.com/ROmGTwi.jpeg',
@@ -0,0 +1,84 @@
import { Box, Tooltip, Button } from '@material-ui/core';
import { makeStyles, Theme } from '@material-ui/core/styles';
import React from 'react';
import { MarketplaceListing } from '../../../../common/typings/marketplace';
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
import DeleteIcon from '@material-ui/icons/Delete';
import ReportIcon from '@material-ui/icons/Report';
import ChatIcon from '@material-ui/icons/Chat';
import PhoneIcon from '@material-ui/icons/Phone';
import Nui from '../../../../os/nui-events/utils/Nui';
import { useTranslation } from 'react-i18next';
import { useHistory } from 'react-router';
const useStyles = makeStyles((theme: Theme) => ({
icon: {
color: theme.palette.primary.main,
},
}));
export const ListingActions = (listing: MarketplaceListing) => {
const classes = useStyles();
const { number: myNumber } = useSimcard();
const { t } = useTranslation();
const history = useHistory();
const handleDeleteListing = () => {
Nui.send('phone:marketplaceDeleteListing', {
id: listing.id,
});
};
const handleReportListing = () => {
Nui.send('phone:reportListing', {
listing,
});
};
const handleCall = () => {
Nui.send('phone:beginCall', {
number: listing.number,
});
};
const handleMessage = () => {
history.push(`/messages/new/${listing.number}`);
};
return (
<Box flex justifyContent="space-between" alignItems="center">
<div style={{ float: 'left' }}>
{listing.number !== myNumber ? (
<>
<Tooltip title={t('GENERIC_MESSAGE')}>
<Button onClick={handleMessage}>
<ChatIcon className={classes.icon} />
</Button>
</Tooltip>
<Tooltip title={`${t('GENERIC_CALL')}: ${listing.number}`}>
<Button onClick={handleCall}>
<PhoneIcon className={classes.icon} />
</Button>
</Tooltip>
</>
) : null}
</div>
<div style={{ float: 'right' }}>
{listing.number === myNumber ? (
<Tooltip title={t('GENERIC_DELETE')}>
<Button onClick={handleDeleteListing}>
<DeleteIcon />
</Button>
</Tooltip>
) : (
<Tooltip title={t('GENERIC_REPORT')}>
<Button onClick={handleReportListing}>
<ReportIcon />
</Button>
</Tooltip>
)}
</div>
</Box>
);
};
@@ -1,10 +1,10 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { Button, Typography, Paper } from '@material-ui/core';
import { Typography, Paper } from '@material-ui/core';
import { ListItem } from '../../../../ui/components/ListItem';
import ChatIcon from '@material-ui/icons/Chat';
import PhoneIcon from '@material-ui/icons/Phone';
import { PictureResponsive } from '../../../../ui/components/PictureResponsive';
import { MarketplaceListing } from '../../../../common/typings/marketplace';
import { ListingActions } from './ListingActions';
const useStyles = makeStyles((theme) => ({
root: {
@@ -30,42 +30,26 @@ const useStyles = makeStyles((theme) => ({
background: theme.palette.background.default,
marginBottom: 20,
},
icon: {
color: theme.palette.primary.main,
},
header: {
margin: 10,
},
headerTypo: {
margin: 5,
},
desc: {
padding: 10,
},
}));
export const SelloutItem = (listing) => {
export const SelloutItem = (listing: MarketplaceListing) => {
const classes = useStyles();
return (
<ListItem className={classes.root}>
<div className={classes.content}>
<Paper elevation={2} className={classes.paper}>
<div className={classes.header}>
<Typography className={classes.headerTypo} variant="h5">
<div style={{ margin: 10 }}>
<Typography style={{ margin: 5 }} variant="h5">
{listing.name}
</Typography>
<Typography
className={classes.headerTypo}
style={{ borderBottom: '1px solid #f44336' }}
>
{listing.number}
</Typography>
<Typography variant="h5" style={{ padding: 5 }}>
{listing.title}
</Typography>
</div>
{listing.url ? (
<PictureResponsive src={listing.url} alt={`${listing.name} image`} />
<PictureResponsive src={listing.url} alt={`${listing.name}`} />
) : (
<Typography style={{ margin: 10 }}>
No image provided{' '}
@@ -74,17 +58,11 @@ export const SelloutItem = (listing) => {
</span>
</Typography>
)}
<Typography variant="h6" className={classes.desc}>
<Typography variant="h6" style={{ padding: 10 }}>
{listing.description}
</Typography>
<div>
<Button>
<ChatIcon className={classes.icon} />
</Button>
<Button>
<PhoneIcon className={classes.icon} />
</Button>
</div>
<ListingActions {...listing} />
</Paper>
</div>
</ListItem>
@@ -1,8 +1,11 @@
import React from 'react';
import { List } from '../../../../ui/components/List';
import { useListing } from '../../hooks/useListing';
import { SelloutItem } from './SelloutItem';
export const SelloutList = ({ listings }) => {
export const SelloutList = () => {
const listings = useListing();
return (
<List>
{listings.map((listing) => (
@@ -1,8 +1,6 @@
import React from 'react';
import { useListing } from '../../hooks/useListing';
import { SelloutList } from './SelloutList';
export const SelloutListContainer = () => {
const { listing } = useListing();
return <SelloutList listings={listing} />;
return <SelloutList />;
};
+2 -2
View File
@@ -1,7 +1,7 @@
import { useRecoilValue } from 'recoil';
import { MarketplaceListing } from '../../../common/typings/marketplace';
import { selloutState } from './state';
export const useListing = () => {
const listing = useRecoilValue(selloutState.listing);
return { listing };
return useRecoilValue<MarketplaceListing[]>(selloutState.listing);
};
+1
View File
@@ -1,6 +1,7 @@
export interface MarketplaceListing {
id: number;
identifier?: string;
username: string;
name: string;
number: string;
title: string;
+7
View File
@@ -123,11 +123,18 @@
"APPS_MARKETPLACE_CREATE_LISTING_SUCCESS": "Successfully created a new listing",
"APPS_MARKETPALCE_CREATE_LISTING_FAILED": "Failed to create a new listing",
"APPS_MARKETPLACE_DELETE_LISTING_SUCCESS": "Successfully delete listing",
"APPS_MARKETPLACE_DELETE_LISTING_FAILED": "Failed to delete listing",
"APPS_MARKETPLACE_REPORT_LISTING_FAILED": "This listing has already been reported",
"APPS_MARKETPLACE_REPORT_LISTING_SUCCESS": "Successfully reported listing",
"GENERIC_WAIT": "Please wait...",
"GENERIC_SAVE": "Save",
"GENERIC_UPDATE": "Update",
"GENERIC_DELETE": "Delete",
"GENERIC_REPORT": "Report",
"GENERIC_CALL": "Call",
"GENERIC_MESSAGE": "Message",
"GENERIC_CLOSE": "Close",
"GENERIC_CANCEL": "Cancel",
"GENERIC_TITLE": "Title",