import React, { useState } from 'react'; import { Typography, Card, CardHeader, CardContent, IconButton, Grid, Menu, MenuItem, } from '@material-ui/core'; import { Solution } from '../../types'; import { makeStyles } from '@material-ui/core/styles'; import TimerIcon from '@material-ui/icons/Timer'; import MoreVertIcon from '@material-ui/icons/MoreVert'; import DeleteIcon from '@material-ui/icons/Delete'; import GithubAvatar from '../GithubAvatar/GithubAvatar'; import { del } from '../../requests'; const DATE_FORMAT = { month: 'long', day: 'numeric', year: 'numeric', hour: '2-digit', minute: '2-digit', }; const useStyles = makeStyles(theme => ({ root: { padding: theme.spacing(1), background: theme.palette.background.elevation2, '& .MuiTypography-h3': { margin: theme.spacing(2), }, }, menu: { '& ul': { background: theme.palette.background.elevation3, } }, })); interface PropTypes { data: Solution; removeThisCard: (id: number) => void; } const SolutionCard: React.FC = ({ data, removeThisCard }) => { const classes = useStyles(); const [anchorEl, setAnchorEl] = useState(null); const author = data.author? data.author.username : 'anonymous'; const date = new Date(data.date); const handleOpenMenu = (event: React.MouseEvent): void => { setAnchorEl(event.currentTarget); }; const handleClose = (): void => { setAnchorEl(null); }; const handleDelete = (): void => { del(`solutions/${data.id}/`).then(() => { removeThisCard(data.id); }); handleClose(); }; return ( } title={author} subheader={date.toLocaleString('default', DATE_FORMAT)} action={ } /> Delete { data.result } ) }; export default SolutionCard;