Commit 9b874f53 authored by zarina's avatar zarina 🌊

#4, Реализован вывод цитат по категориям

parent b6b1b067
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
# testing # testing
/coverage /coverage
.idea
# production # production
/build /build
......
import React from 'react'; import React from 'react';
import { Card, Button, CardHeader, CardFooter, CardBody, import { Card, Button, CardFooter, CardBody,
CardTitle, CardText } from 'reactstrap'; CardTitle, CardText } from 'reactstrap';
const Quote = props => { const Quote = props => {
...@@ -7,12 +7,12 @@ const Quote = props => { ...@@ -7,12 +7,12 @@ const Quote = props => {
<div> <div>
<Card> <Card>
<CardBody> <CardBody>
<CardTitle>{props.author}</CardTitle> <CardTitle className='text-uppercase font-weight-bold'>{props.author}</CardTitle>
<CardText>{props.text}</CardText> <CardText>{props.text}</CardText>
<Button color='danger'>Delete</Button> <Button className='mr-3' color='danger'>Delete</Button>
<Button color='info'>Edit</Button> <Button color='info'>Edit</Button>
</CardBody> </CardBody>
<CardFooter className='text-hide'>{props.category}</CardFooter> <CardFooter className='text-muted'>{props.category}</CardFooter>
</Card> </Card>
</div> </div>
); );
......
...@@ -12,7 +12,8 @@ function App() { ...@@ -12,7 +12,8 @@ function App() {
<Switch> <Switch>
<Route path="/add-quote" exact component={QuoteForm}/> <Route path="/add-quote" exact component={QuoteForm}/>
<Route path="/" exact component={Quotes}/> <Route path="/" exact component={Quotes}/>
<Route path="/quotes/" exact component={Quotes}/>
<Route path="/quotes/:category" exact component={Quotes}/>
</Switch> </Switch>
</Container> </Container>
</> </>
......
...@@ -7,7 +7,7 @@ import CATEGORIES from "../../quotes-categories"; ...@@ -7,7 +7,7 @@ import CATEGORIES from "../../quotes-categories";
const QuoteForm = props => { const QuoteForm = props => {
const [quoteInfo, setQuoteInfo] = useState({ const [quoteInfo, setQuoteInfo] = useState({
author: '', author: '',
category: CATEGORIES[0].title, category: CATEGORIES[0].id,
text: '' text: ''
}); });
......
...@@ -2,17 +2,24 @@ import React, {useEffect, useState} from "react"; ...@@ -2,17 +2,24 @@ import React, {useEffect, useState} from "react";
import axios from '../../axios-quote' import axios from '../../axios-quote'
import Quote from "../../components/Quote/Quote"; import Quote from "../../components/Quote/Quote";
const Quotes = () => { const Quotes = props => {
const [quotes, setQuotes] = useState({}); const [quotes, setQuotes] = useState({});
useEffect(() => { useEffect(() => {
axios.get('/quotes.json').then( axios.get(
response => { props.match.params.category ?
setQuotes(response.data) `/quotes.json?orderBy="category"&equalTo="${props.match.params.category}"` :
} '/quotes.json')
) .then(
}, []); response => {
setQuotes(response.data)
})
.catch(error => {
console.log(error)
})
}
, []);
const printQuotes = () => { const printQuotes = () => {
......
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