Commit ce569a5d authored by zarina's avatar zarina 🌊

#7, Добавлена возможность редактирования цитат

parent 389f2ee3
...@@ -14,6 +14,7 @@ const FormToFill = (props) => { ...@@ -14,6 +14,7 @@ const FormToFill = (props) => {
<FormGroup> <FormGroup>
<Label for="author">Author</Label> <Label for="author">Author</Label>
<Input <Input
value={props.author}
type="text" type="text"
name="author" name="author"
id="author" id="author"
...@@ -22,6 +23,7 @@ const FormToFill = (props) => { ...@@ -22,6 +23,7 @@ const FormToFill = (props) => {
<FormGroup> <FormGroup>
<Label for="category">Select</Label> <Label for="category">Select</Label>
<Input <Input
value={props.category}
type="select" type="select"
name="category" name="category"
id="category" id="category"
...@@ -32,7 +34,9 @@ const FormToFill = (props) => { ...@@ -32,7 +34,9 @@ const FormToFill = (props) => {
</FormGroup> </FormGroup>
<FormGroup> <FormGroup>
<Label for="text">Quote Text</Label> <Label for="text">Quote Text</Label>
<Input type="textarea" <Input
value={props.text}
type="textarea"
name="text" name="text"
id="text" id="text"
onChange={props.inputHandler} onChange={props.inputHandler}
......
...@@ -12,7 +12,7 @@ const Header = () => { ...@@ -12,7 +12,7 @@ const Header = () => {
<NavLink className="nav-link" to="/quotes">Quotes</NavLink> <NavLink className="nav-link" to="/quotes">Quotes</NavLink>
</NavItem> </NavItem>
<NavItem> <NavItem>
<NavLink className="nav-link" to="/add-quote">Add Quote</NavLink> <NavLink className="nav-link" to="/add-quote">Add new quote</NavLink>
</NavItem> </NavItem>
</Nav> </Nav>
</Container> </Container>
......
import React from 'react'; import React from 'react';
import { Card, Button, CardFooter, CardBody, import { Card, Button, CardFooter, CardBody,
CardTitle, CardText } from 'reactstrap'; CardTitle, CardText } from 'reactstrap';
import {NavLink} from "react-router-dom";
const Quote = props => { const Quote = props => {
return ( return (
...@@ -10,7 +12,7 @@ const Quote = props => { ...@@ -10,7 +12,7 @@ const Quote = props => {
<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 onClick={props.delete} className='mr-3' color='danger'>Delete</Button> <Button onClick={props.delete} className='mr-3' color='danger'>Delete</Button>
<Button color='info'>Edit</Button> <Button tag={NavLink} to={`/quotes/${props.id}/edit`} color='info'>Edit</Button>
</CardBody> </CardBody>
<CardFooter className='text-muted'>{props.category}</CardFooter> <CardFooter className='text-muted'>{props.category}</CardFooter>
</Card> </Card>
......
...@@ -7,7 +7,7 @@ const Sidebar = () => { ...@@ -7,7 +7,7 @@ const Sidebar = () => {
const printCategories = () => { const printCategories = () => {
return CATEGORIES.map(category => { return CATEGORIES.map(category => {
return <NavItem> return <NavItem key={`sidebar_${category.id}` }>
<NavLink className="nav-link" to={'/quotes/' + category.id} >{category.title}</NavLink> <NavLink className="nav-link" to={'/quotes/' + category.id} >{category.title}</NavLink>
</NavItem> </NavItem>
}) })
......
...@@ -22,6 +22,7 @@ function App() { ...@@ -22,6 +22,7 @@ function App() {
<Route path="/" exact component={Quotes}/> <Route path="/" exact component={Quotes}/>
<Route path="/quotes/" exact component={Quotes}/> <Route path="/quotes/" exact component={Quotes}/>
<Route path="/quotes/:category" exact component={Quotes}/> <Route path="/quotes/:category" exact component={Quotes}/>
<Route path="/quotes/:id/edit" exact component={QuoteForm}/>
</Switch> </Switch>
</div> </div>
</Container> </Container>
......
...@@ -11,6 +11,25 @@ const QuoteForm = props => { ...@@ -11,6 +11,25 @@ const QuoteForm = props => {
text: '' text: ''
}); });
useEffect(() => {
if (props.match.params.id) {
axios.get(`quotes/${props.match.params.id}.json`)
.then(
response => {
setQuoteInfo(response.data)
}
)
}
else{
let resetQuoteInfo = {
author: '',
category: CATEGORIES[0].id,
text: ''
};
setQuoteInfo(resetQuoteInfo)
}
},[props.match.params.id]);
const inputHandler = (e) => { const inputHandler = (e) => {
setQuoteInfo({ setQuoteInfo({
...quoteInfo, ...quoteInfo,
...@@ -25,7 +44,7 @@ const QuoteForm = props => { ...@@ -25,7 +44,7 @@ const QuoteForm = props => {
} }
axios.post('/quotes.json', quoteInfo).then( axios.post('/quotes.json', quoteInfo).then(
response => { ()=> {
props.history.push('./') props.history.push('./')
} }
) )
...@@ -34,7 +53,12 @@ const QuoteForm = props => { ...@@ -34,7 +53,12 @@ const QuoteForm = props => {
return ( return (
<div className='QuoteForm'> <div className='QuoteForm'>
<FormToFill submitQuote={submitQuote} inputHandler={inputHandler}/> <FormToFill submitQuote={submitQuote}
inputHandler={inputHandler}
text={quoteInfo.text}
category={quoteInfo.category}
author={quoteInfo.author}
/>
</div> </div>
) )
}; };
......
...@@ -40,6 +40,7 @@ const Quotes = props => { ...@@ -40,6 +40,7 @@ const Quotes = props => {
category={quotes[quote].category} category={quotes[quote].category}
key={quote} key={quote}
delete={() => deleteQuote(quote)} delete={() => deleteQuote(quote)}
id={quote}
/> />
}) })
}; };
......
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