Improve/marketplace (#184)

Overall fixes for sellout => marketplace.
This commit is contained in:
Christopher Gjelten authored and GitHub committed 2021-03-28 04:20:12 +02:00
1 parent baf6dedb6f
commit a88286f97a
23 files changed
+85 -52

No files matched your search

@@ -0,0 +1,53 @@
import React from 'react';
import { AppWrapper } from '../../../ui/components/AppWrapper';
import { AppContent } from '../../../ui/components/AppContent';
import { MarketplaceTitle } from './MarketplaceTitle';
import { MarketplaceListContainer } from './SelloutList/MarketplaceListContainer';
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';
export const MarketplaceApp = () => {
return (
<MarketplaceThemeProvider>
<AppWrapper id="sellout-app">
<MarketplaceTitle />
<AppContent>
<Switch>
<Route path="/marketplace" exact component={MarketplaceListContainer} />
<Route path="/marketplace/new" component={ListingFormContainer} />
</Switch>
</AppContent>
<NavigationBar />
</AppWrapper>
</MarketplaceThemeProvider>
);
};
InjectDebugData([
{
app: 'SELLOUT',
method: 'setListings',
data: [
{
id: 1,
name: 'Some guy',
number: '111-1134',
title: 'eeeeeeeeeeeeeeeeeeeeeeeee',
description:
'skldfsd sajsfjklsdfj sdajsklfjdsjklas jskj sdjsd jasdkl sdjsf jasdklsfjfj kljasdkf jkaf jsdkla jsk jdkla j kljasdkf jkld jasd kljk',
url: 'https://beta.iodine.gg/706Y3.jpeg',
},
{
id: 2,
name: 'Some other dude',
number: '666-6666',
title: 'Material',
description: 'Selling my wife',
url: '',
},
],
},
]);
@@ -0,0 +1,30 @@
import React from 'react';
import Paper from '@material-ui/core/Paper';
import { makeStyles } from '@material-ui/core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faAd } from '@fortawesome/free-solid-svg-icons';
const useStyles = makeStyles((theme) => ({
root: {
height: '60px',
width: '100%',
display: 'flex',
flexFlow: 'row nowrap',
justifyContent: 'center',
alignItems: 'center',
background: theme.palette.background.default,
},
icon: {
color: theme.palette.primary.main,
fontSize: 40,
},
}));
export const MarketplaceTitle = () => {
const classes = useStyles();
return (
<Paper className={classes.root} square variant="outlined" elevation={24}>
<FontAwesomeIcon icon={faAd} className={classes.icon} />
</Paper>
);
};
@@ -0,0 +1,83 @@
import { Box, Tooltip, Button } from '@material-ui/core';
import { makeStyles, Theme } from '@material-ui/core/styles';
import React from 'react';
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';
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';
import { CallEvents } from '../../../../../../typings/call';
const useStyles = makeStyles((theme: Theme) => ({
icon: {
color: theme.palette.primary.main,
},
}));
export const ListingActions = ({ listing }: { listing: MarketplaceListing }) => {
const classes = useStyles();
const { number: myNumber } = useSimcard();
const { t } = useTranslation();
const history = useHistory();
const handleDeleteListing = () => {
Nui.send(MarketplaceEvents.DELETE_LISTING, {
id: listing.id,
});
};
const handleReportListing = () => {
Nui.send(MarketplaceEvents.REPORT_LISTING, listing);
};
const handleCall = () => {
Nui.send(CallEvents.INITIALIZE_CALL, {
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>
);
};
@@ -0,0 +1,73 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { Typography, Paper } from '@material-ui/core';
import { ListItem } from '../../../../ui/components/ListItem';
import { PictureResponsive } from '../../../../ui/components/PictureResponsive';
import { MarketplaceListing } from '../../../../../../typings/marketplace';
import { ListingActions } from './ListingActions';
import { PictureReveal } from '../../../../ui/components/PictureReveal';
const useStyles = makeStyles((theme) => ({
root: {
overflowX: 'hidden',
display: 'flex',
flexFlow: 'row nowrap',
alignItems: 'flex-start',
width: '100%',
marginTop: '3px',
},
content: {
display: 'flex',
marginTop: '-10px',
flexFlow: 'column nowrap',
width: '100%',
},
paper: {
overflow: 'auto',
display: 'flex',
flexFlow: 'column',
alignItems: 'flex',
height: 'auto',
background: theme.palette.background.default,
marginBottom: 20,
},
}));
export const MarketplaceItem = (listing: MarketplaceListing) => {
const classes = useStyles();
return (
<ListItem className={classes.root}>
<div className={classes.content}>
<Paper elevation={2} className={classes.paper}>
<div style={{ margin: 10 }}>
<Typography style={{ margin: 5 }} variant="h5">
{listing.name}
</Typography>
<Typography variant="h5" style={{ padding: 5 }}>
{listing.title}
</Typography>
</div>
{listing.url ? (
<PictureReveal>
<PictureResponsive src={listing.url} alt={`${listing.name}`} />
</PictureReveal>
) : (
<Typography style={{ margin: 10 }}>
No image provided{' '}
<span role="img" aria-label="emoji">
🙁
</span>
</Typography>
)}
<Typography variant="body1" style={{ padding: 10 }}>
{listing.description}
</Typography>
<ListingActions listing={listing} />
</Paper>
</div>
</ListItem>
);
};
@@ -0,0 +1,16 @@
import React from 'react';
import { List } from '../../../../ui/components/List';
import { useListing } from '../../hooks/useListing';
import { MarketplaceItem } from './MarketplaceItem';
export const MarketplaceList = () => {
const listings = useListing();
return (
<List>
{listings.map((listing) => (
<MarketplaceItem key={listing.id} {...listing} />
))}
</List>
);
};
@@ -0,0 +1,6 @@
import React from 'react';
import { MarketplaceList } from './MarketplaceList';
export const MarketplaceListContainer = () => {
return <MarketplaceList />;
};
@@ -0,0 +1,111 @@
import React, { useState } from 'react';
import { makeStyles, Button, TextField, Typography } from '@material-ui/core';
import Nui from '../../../../os/nui-events/utils/Nui';
import { MarketplaceEvents } from '../../../../../../typings/marketplace';
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
import { useTranslation } from 'react-i18next';
import { useHistory } from 'react-router';
const useStyles = makeStyles((theme) => ({
root: {
width: '100%',
margin: 'auto',
textAlign: 'center',
},
input: {
marginBottom: 25,
},
textFieldInput: {
fontSize: 22,
},
multilineFieldInput: {
fontSize: 20,
},
postButton: {
display: 'block',
margin: 'auto',
background: theme.palette.primary.main,
width: '80%',
fontSize: 20,
},
}));
export const ListingForm = () => {
const classes = useStyles();
const { t } = useTranslation();
const { addAlert } = useSnackbar();
const history = useHistory();
const [title, setTitle] = useState('');
const [url, setUrl] = useState('');
const [description, setDescription] = useState('');
const addListing = () => {
if (title !== '' && description !== '') {
Nui.send(MarketplaceEvents.ADD_LISTING, {
title,
url,
description,
});
history.push('/marketplace');
} else {
addAlert({
message: t('APPS_MARKETPLACE_REQUIRED_FIELDS'),
type: 'error',
});
}
};
return (
<div className={classes.root}>
<h1>New Listing</h1>
<TextField
className={classes.input}
onChange={(e) => setTitle(e.target.value)}
label={t('GENERIC_REQUIRED')}
placeholder={t('APPS_MARKETPLACE_FORM_TITLE')}
inputProps={{
className: classes.textFieldInput,
maxLength: 25,
}}
style={{ width: '80%' }}
size="medium"
InputLabelProps={{
shrink: true,
}}
/>
<TextField
className={classes.input}
placeholder={t('APPS_MARKETPLACE_FORM_IMAGE')}
onChange={(e) => setUrl(e.target.value)}
inputProps={{ className: classes.textFieldInput }}
style={{ width: '80%' }}
size="medium"
variant="outlined"
/>
<TextField
className={classes.input}
onChange={(e) => setDescription(e.target.value)}
label={t('GENERIC_REQUIRED')}
placeholder={t('APPS_MARKETPLACE_FORM_DESCRIPTION')}
inputProps={{
className: classes.multilineFieldInput,
maxLength: 130,
}}
style={{ width: '80%' }}
size="medium"
InputLabelProps={{
shrink: true,
}}
multiline
rows={4}
variant="outlined"
/>
<Button onClick={addListing} className={classes.postButton}>
Post
</Button>
</div>
);
};
@@ -0,0 +1,10 @@
import React from 'react';
import { ListingForm } from './ListingForm';
export const ListingFormContainer = () => {
return (
<div>
<ListingForm />
</div>
);
};
@@ -0,0 +1,39 @@
import React, { useState } from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { Link } from 'react-router-dom';
import { BottomNavigation, BottomNavigationAction } from '@material-ui/core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faHome } from '@fortawesome/free-solid-svg-icons';
import AddCircleIcon from '@material-ui/icons/AddCircle';
const useStyles = makeStyles((theme) => ({
root: {
width: '100%',
backgroundColor: theme.palette.background.default,
},
icon: {
color: theme.palette.primary.main,
},
}));
export const NavigationBar = () => {
const classes = useStyles();
const [activePage, setActivePage] = useState(0);
return (
<BottomNavigation
value={activePage}
onChange={(event, newPage) => {
setActivePage(newPage);
}}
showLabels
className={classes.root}
>
<BottomNavigationAction
component={Link}
icon={<FontAwesomeIcon icon={faHome} />}
to="/marketplace"
/>
<BottomNavigationAction component={Link} icon={<AddCircleIcon />} to="/marketplace/new" />
</BottomNavigation>
);
};