forked from shahibuzzaman/covid19-tracker-reactJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountries.js
More file actions
154 lines (145 loc) · 4.25 KB
/
Countries.js
File metadata and controls
154 lines (145 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import React, { Component } from 'react';
import Country from './Country';
import {
InputGroup,
InputGroupText,
InputGroupAddon,
Input,
Navbar,
Col,
Container,
Row,
Pagination,
PaginationItem,
PaginationLink,
} from 'reactstrap';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faSearch } from '@fortawesome/free-solid-svg-icons';
class Countries extends Component {
state = {
search: '',
filter: null,
page: 1,
};
onChange = (e) => {
this.setState({ search: e.target.value });
};
render() {
const { countries } = this.props;
const filteredCountries = countries.filter((countries) => {
return (
countries.country
.toLowerCase()
.indexOf(this.state.search.toLowerCase()) !== -1
);
});
let productCount = this.props.countries.length;
let PerPage = 8;
let pages = Math.ceil(productCount / PerPage);
let skip = (this.state.page - 1) * PerPage;
return (
<div style={{ marginTop: '10px' }}>
<Navbar
light
expand='md'
className='fixed-top'
style={{ width: '35%', marginLeft: '32%', marginTop: '5px' }}
>
<InputGroup size='sm'>
<InputGroupAddon addonType='prepend'>
<InputGroupText>
<FontAwesomeIcon icon={faSearch} />
</InputGroupText>
</InputGroupAddon>
<Input
placeholder='sm'
bsSize='sm'
type='text'
name='text'
id='text'
placeholder='Search by Country Name ....'
onChange={this.onChange}
/>
</InputGroup>
</Navbar>
<Container>
<Row>
<Col>
<div style={userStyle}>
{filteredCountries
.slice(skip, PerPage + skip)
.map((countries) => (
<Country key={countries.id} countries={countries} />
))}
</div>
</Col>
<Col>
<div>
<Pagination
style={{ marginLeft: '15px' }}
size='sm'
aria-label='Page navigation example'
>
<PaginationItem
class={`page-item ${this.state.page === 1 && 'disabled'}`}
>
<PaginationLink
class='page-link'
href='#'
onClick={() =>
this.setState({ page: this.state.page - 1 })
}
>
Previous
</PaginationLink>
</PaginationItem>
{Array.from({ length: pages }).map((_, i) => (
<PaginationItem
class={`page-item ${
this.state.page === i + 1 ? 'active' : ''
}`}
>
<PaginationLink
class='page-link'
href='#'
onClick={() => this.setState({ page: i })}
>
{++i}
</PaginationLink>
<PaginationItem></PaginationItem>
</PaginationItem>
))}
<PaginationItem
class={`page-item ${
this.state.page === pages && 'disabled'
}`}
>
<PaginationLink
class='page-link'
href='#'
onClick={() =>
this.setState({ page: this.state.page + 1 })
}
>
Next
</PaginationLink>
</PaginationItem>
</Pagination>
</div>
</Col>
</Row>
<Row></Row>
</Container>
</div>
);
}
}
const userStyle = {
marginLeft: '50px',
marginRight: '50px',
marginBottom: '30px',
display: 'grid',
gridTemplateColumns: 'repeat(4, 1fr)',
gridGap: '1rem',
};
export default Countries;