1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
import React, { useState } from 'react';
import {
Typography,
Card,
CardHeader,
CardContent,
IconButton,
Avatar,
Grid,
Menu,
MenuItem,
} from "@material-ui/core";
import { makeStyles } from "@material-ui/core/styles";
import TimerIcon from '@material-ui/icons/Timer';
import MoreVertIcon from '@material-ui/icons/MoreVert';
import { del } from "../../requests";
const useStyles = makeStyles(theme => ({
root: {
padding: theme.spacing(1),
'& .MuiTypography-h3': {
color: theme.palette.secondary.main,
margin: theme.spacing(2),
},
},
}));
const SolutionCard = ({ solution, removeThisCard }) => {
const classes = useStyles();
const [anchorEl, setAnchorEl] = useState(null);
const author = solution.author? solution.author.username : 'anonymous';
const handleOpenMenu = event => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
const handleDelete = () => {
del(`solutions/${solution.id}/`);
handleClose();
removeThisCard(solution.id);
};
return (
<Card elevation={5} className={classes.root}>
<CardHeader
avatar={
author === 'anonymous'?
(<Avatar/>)
:
(<Avatar>{author[0].toUpperCase()}</Avatar>)
}
title={author}
subheader="04.01.2020 13:20"
action={(
<IconButton onClick={handleOpenMenu}>
<MoreVertIcon />
</IconButton>
)}
/>
<Menu
anchorEl={anchorEl}
open={Boolean(anchorEl)}
keepMounted
onClose={handleClose}
>
<MenuItem onClick={handleDelete}>Delete</MenuItem>
</Menu>
<CardContent>
<Grid container direction="row" justify="center" alignItems="center">
<Grid item>
<TimerIcon/>
</Grid>
<Grid item>
<Typography variant="h3">
{ solution.result }
</Typography>
</Grid>
</Grid>
</CardContent>
</Card>
)
};
export default SolutionCard;
|