From dd622def55c52255493c467e2be2f8e3473a1256 Mon Sep 17 00:00:00 2001 From: Eug-VS Date: Sun, 5 Jan 2020 03:13:24 +0300 Subject: Add DELETE as menu option to SolutionCard --- src/components/SolutionCard/SolutionCard.js | 34 ++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'src/components/SolutionCard/SolutionCard.js') 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 ( { title={author} subheader="04.01.2020 13:20" action={( - + )} /> + + Delete + -- cgit v1.2.3