Commit 389f2ee3 authored by zarina's avatar zarina 🌊

#6, добавлена возможность удаления цитат

parent 0674d7b8
...@@ -9,7 +9,7 @@ const Quote = props => { ...@@ -9,7 +9,7 @@ const Quote = props => {
<CardBody> <CardBody>
<CardTitle className='text-uppercase font-weight-bold'>{props.author}</CardTitle> <CardTitle className='text-uppercase font-weight-bold'>{props.author}</CardTitle>
<CardText>{props.text}</CardText> <CardText>{props.text}</CardText>
<Button className='mr-3' color='danger'>Delete</Button> <Button onClick={props.delete} className='mr-3' color='danger'>Delete</Button>
<Button color='info'>Edit</Button> <Button color='info'>Edit</Button>
</CardBody> </CardBody>
<CardFooter className='text-muted'>{props.category}</CardFooter> <CardFooter className='text-muted'>{props.category}</CardFooter>
......
...@@ -22,16 +22,31 @@ const Quotes = props => { ...@@ -22,16 +22,31 @@ const Quotes = props => {
, [props.match.params.category]); , [props.match.params.category]);
const deleteQuote = (id) => {
axios.delete(`/quotes/${id}.json`)
.then(() => {
let allQuotes = {...quotes};
delete allQuotes[id];
setQuotes(allQuotes)
})
}
const printQuotes = () => { const printQuotes = () => {
return Object.keys(quotes).map(quote => { return Object.keys(quotes).map(quote => {
return <Quote author={quotes[quote].author} return <Quote author={quotes[quote].author}
text={quotes[quote].text} text={quotes[quote].text}
category={quotes[quote].category} category={quotes[quote].category}
key={quote} key={quote}
delete={() => deleteQuote(quote)}
/> />
}) })
}; };
return ( return (
<div className='Quotes'> <div className='Quotes'>
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment