File src/components/list/List.js changed (mode: 100644) (index 1fb2151..3dd2ea4) |
... |
... |
import { handleResponse } from '../../helpers'; |
3 |
3 |
import { API_URL } from '../../config'; |
import { API_URL } from '../../config'; |
4 |
4 |
import Loading from '../common/Loading' |
import Loading from '../common/Loading' |
5 |
5 |
import Table from './Table' |
import Table from './Table' |
|
6 |
|
import Pagination from './Pagination' |
6 |
7 |
|
|
7 |
8 |
class List extends React.Component { |
class List extends React.Component { |
8 |
9 |
constructor(props) { |
constructor(props) { |
|
... |
... |
class List extends React.Component { |
11 |
12 |
this.state = { |
this.state = { |
12 |
13 |
loading: false, |
loading: false, |
13 |
14 |
currencies: [], |
currencies: [], |
14 |
|
error: null |
|
|
15 |
|
error: null, |
|
16 |
|
totalPages: 0, |
|
17 |
|
page: 1, |
15 |
18 |
}; |
}; |
16 |
19 |
} |
} |
17 |
20 |
|
|
18 |
21 |
componentDidMount(){ |
componentDidMount(){ |
19 |
22 |
this.setState({ loading: true }); |
this.setState({ loading: true }); |
20 |
23 |
|
|
21 |
|
fetch(`${API_URL}/cryptocurrencies?page=1&perPage=20`) |
|
|
24 |
|
const { page } = this.state; |
|
25 |
|
|
|
26 |
|
fetch(`${API_URL}/cryptocurrencies?page=${page}&perPage=20`) |
22 |
27 |
.then(handleResponse) |
.then(handleResponse) |
23 |
28 |
.then((data) => { |
.then((data) => { |
|
29 |
|
const {currencies, totalPages} = data; |
24 |
30 |
this.setState({ |
this.setState({ |
25 |
31 |
loading: false, |
loading: false, |
26 |
|
currencies: data.currencies |
|
|
32 |
|
currencies, |
|
33 |
|
totalPages |
27 |
34 |
}); |
}); |
28 |
35 |
}) |
}) |
29 |
36 |
.catch((error) => { |
.catch((error) => { |
|
... |
... |
class List extends React.Component { |
47 |
54 |
} |
} |
48 |
55 |
|
|
49 |
56 |
render() { |
render() { |
50 |
|
const { loading, error, currencies } = this.state; |
|
|
57 |
|
const { loading, error, currencies, totalPages, page } = this.state; |
51 |
58 |
|
|
52 |
59 |
if (loading) { |
if (loading) { |
53 |
60 |
return <div className="loading-container"><Loading /></div> |
return <div className="loading-container"><Loading /></div> |
|
... |
... |
class List extends React.Component { |
58 |
65 |
} |
} |
59 |
66 |
|
|
60 |
67 |
return ( |
return ( |
61 |
|
<Table |
|
62 |
|
currencies={currencies} |
|
63 |
|
renderChangePercent={this.renderChangePercent} |
|
64 |
|
/> |
|
|
68 |
|
<div> |
|
69 |
|
<Table |
|
70 |
|
currencies={currencies} |
|
71 |
|
renderChangePercent={this.renderChangePercent} |
|
72 |
|
/> |
|
73 |
|
<Pagination |
|
74 |
|
totalPages={totalPages} |
|
75 |
|
page={page} |
|
76 |
|
/> |
|
77 |
|
</div> |
|
78 |
|
|
65 |
79 |
); |
); |
66 |
80 |
} |
} |
67 |
81 |
} |
} |
File src/components/list/Pagination.js added (mode: 100644) (index 0000000..fa52cc8) |
|
1 |
|
import React from 'react'; |
|
2 |
|
import './Pagination.css'; |
|
3 |
|
|
|
4 |
|
const Pagination = (props) =>{ |
|
5 |
|
const { totalPages, page } = props; |
|
6 |
|
|
|
7 |
|
return ( |
|
8 |
|
<div className="Pagination"> |
|
9 |
|
<button className="Pagination-button"> |
|
10 |
|
← |
|
11 |
|
</button> |
|
12 |
|
<span className="Pagination-info"> |
|
13 |
|
Page <b>{page}</b> of <b>{totalPages}</b> |
|
14 |
|
</span> |
|
15 |
|
<button className="Pagination-button"> |
|
16 |
|
→ |
|
17 |
|
</button> |
|
18 |
|
</div> |
|
19 |
|
); |
|
20 |
|
} |
|
21 |
|
|
|
22 |
|
export default Pagination; |