forked from shahibuzzaman/covid19-tracker-reactJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
130 lines (114 loc) · 3.71 KB
/
Copy pathApp.js
File metadata and controls
130 lines (114 loc) · 3.71 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
import React, { Component, Fragment } from 'react';
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
import Nav from './Nav';
import Countries from './Countries';
import { Container, Row, Col, UncontrolledAlert } from 'reactstrap';
import axios from 'axios';
import Total from './Total';
import SafetyTips from './SafetyTips';
import About from './About';
import AboutCorona from './AboutCorona';
import Prevention from './Prevention';
import CountryData from './CountryData';
class App extends Component {
state = {
countries: [],
country: [],
all: {},
loading: false
};
getCountries = async () => {
this.setState({ loading: true });
const res = await axios.get('https://corona.lmao.ninja/countries');
this.setState({ countries: res.data, loading: false });
};
// get all total
getAll = async () => {
this.setState({ loading: true });
const res = await axios.get('https://corona.lmao.ninja/all');
this.setState({ all: res.data, loading: false });
};
//get single country data
getCountryData = async country => {
this.setState({ loading: true });
const res = await axios.get(
`https://corona.lmao.ninja/countries/${country}`
);
this.setState({ country: res.data, loading: false });
};
async componentDidMount() {
this.getCountries();
this.getAll();
this.getCountryData();
}
render() {
return (
<Router>
<div>
<Nav />
<Switch>
<Route
exact
path='/'
render={props => (
<Fragment>
<Container fluid={true}>
<Row>
<Col xs='3'>
<Total
loading={this.state.loading}
all={this.state.all}
/>
</Col>
<Col xs='6'>
{/* <div style={{ marginTop: '100px' }}>
<UncontrolledAlert
color='info'
fade={false}
alert={this.state.alert}
>
I am an alert and I can be dismissed without
animating!
</UncontrolledAlert>
</div> */}
<Container responsive='true'>
<Row>
<Col className='themed-container'>
<Countries
loading={this.state.loading}
countries={this.state.countries}
/>
</Col>
</Row>
</Container>
</Col>
<Col xs='3'>
<SafetyTips />
</Col>
</Row>
</Container>
</Fragment>
)}
/>
<Route exact path='/about' component={About} />
<Route
exact
path='/country/:country'
render={routeProps => (
<CountryData
{...routeProps}
getCountryData={this.getCountryData}
country={this.state.country}
loading={this.state.loading}
/>
)}
/>
<Route exact path='/about-covid-19' component={AboutCorona} />
<Route exact path='/prevention' component={Prevention} />
</Switch>
</div>
</Router>
);
}
}
export default App;