-
Notifications
You must be signed in to change notification settings - Fork 0
/
dd.js
137 lines (114 loc) · 3.43 KB
/
dd.js
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
import React, { Component } from "react";
import {
Card, CardImg, CardText, CardBody,
CardTitle, CardSubtitle} from 'reactstrap';
const cardStyle = {
minWidth: 250,
display: "inline-block",
padding: 16,
border: "1px solid #eee",
margin: 16,
cursor: "pointer",
backgroundColor: "white",
borderRadius: 12,
backgroundColor: "#F99DB0",
boxShadow: "0 0 8px -4px rgba(0,0,0, 0.5)"
};
const cardStylex = {
minWidth: 250,
display: "inline-block",
padding: 16,
border: "1px solid #eee",
margin: 16,
cursor: "pointer",
backgroundColor: "white",
borderRadius: 12,
backgroundColor: "#B1F99D",
boxShadow: "0 0 8px -4px rgba(0,0,0, 0.5)"
};
const cardStyley = {
minWidth: 250,
display: "inline-block",
padding: 16,
border: "1px solid #eee",
margin: 16,
cursor: "pointer",
backgroundColor: "white",
borderRadius: 12,
backgroundColor: "#9DB1F9",
boxShadow: "0 0 8px -4px rgba(0,0,0, 0.5)"
};
const image= {
border: "1px solid #eee",
borderRadius: 4,
display:"inline-block",
padding: 16,
minWidth: 300,
float:"right",
cursor: "pointer",
height: 150
};
class Cardnew extends Component {
// Constructor is not used and can be removed
// it can be used to set some initial state
constructor(props) {
super(props);
this.state={
activeCases:0,
recoveredCases:0,
deaths:0,
totalActiveCases: 0,
totalRecoveredCases: 0,
totalDeaths: 0,
}
}
componentDidMount() {
fetch("https://disease.sh/v3/covid-19/all").then((res) => {
res.json().then((json) => {
let { cases, recovered, deaths, todayCases, todayDeaths, todayRecovered } = json;
// updateState
this.setState({
activeCases: todayCases,
recoveredCases: todayRecovered,
deaths: todayDeaths,
totalActiveCases: cases,
totalRecoveredCases: recovered,
totalDeaths: deaths,
});
});
});
}
render() {
// Extarct the value from the props using destructors
// return the HTML snippet, inject values from received from props
// and apply styles to style the card
const {activeCases,recoveredCases,deaths,totalActiveCases,totalDeaths,totalRecoveredCases} =this.state
return (
<div >
<Card style={cardStyle} >
<CardBody>
<CardTitle><h2>Total Cases </h2></CardTitle>
<CardText>+{activeCases.toLocaleString()}</CardText>
<CardText>Worldwide total :{totalActiveCases.toLocaleString()}</CardText>
</CardBody>
</Card>
<Card style ={cardStylex}>
<CardBody>
<CardTitle><h2>Recovered</h2></CardTitle>
<CardText>+{recoveredCases.toLocaleString()}</CardText>
<CardText>Worldwide total :{totalRecoveredCases.toLocaleString()}</CardText>
</CardBody>
</Card>
<Card style={cardStyley}>
<CardBody>
<CardTitle> <h2> Deaths</h2> </CardTitle>
<CardText>+{deaths.toLocaleString()}</CardText>
<CardText>Worldwide total :{totalDeaths.toLocaleString()}</CardText>
</CardBody>
</Card>
<img src="https://images.unsplash.com/photo-1584530007341-7ccbb2778bad?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80" style={image}/>
</div>
);
}
}
export default Cardnew;