diff options
author | Eug-VS <eug-vs@keemail.me> | 2020-01-05 03:13:24 +0300 |
---|---|---|
committer | Eug-VS <eug-vs@keemail.me> | 2020-01-05 03:14:46 +0300 |
commit | dd622def55c52255493c467e2be2f8e3473a1256 (patch) | |
tree | 3419507e0b66bf46d728795dcbbd91b49607eacb /src/components/SolutionCard/SolutionCard.js | |
parent | 321674f2710910f87893b4d0e65e67b77d1ebaa4 (diff) | |
download | chrono-cube-ui-dd622def55c52255493c467e2be2f8e3473a1256.tar.gz |
Add DELETE as menu option to SolutionCard
Diffstat (limited to 'src/components/SolutionCard/SolutionCard.js')
-rw-r--r-- | src/components/SolutionCard/SolutionCard.js | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/components/SolutionCard/SolutionCard.js b/src/components/SolutionCard/SolutionCard.js index 5f3e5b4..f2d814c 100644 --- a/src/components/SolutionCard/SolutionCard.js +++ b/src/components/SolutionCard/SolutionCard.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import { Typography, @@ -8,12 +8,16 @@ import { 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: { @@ -26,10 +30,26 @@ const useStyles = makeStyles(theme => ({ }, })); -const SolutionCard = ({ solution }) => { +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 @@ -42,11 +62,19 @@ const SolutionCard = ({ solution }) => { title={author} subheader="04.01.2020 13:20" action={( - <IconButton> + <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> |