-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCovidDataSearch
149 lines (138 loc) · 3.33 KB
/
CovidDataSearch
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
import React, { useCallback, useState } from "react";
import { StyleSheet, Text, View, TextInput, ScrollView } from "react-native";
import axios from "axios";
const styles = StyleSheet.create({
root: {
flex: 1,
},
textInput: {
borderBottomWidth: 3,
padding: 5,
marginVertical: 50,
backgroundColor: "#fff",
fontSize: 19,
fontWeight: "300",
borderRadius: 16,
borderBottomColor: "orange",
width: "80%",
alignSelf: "center",
},
state: {
color: "orange",
fontSize: 40,
fontWeight: "bold",
},
infoView: {
alignItems: "center",
},
tempText: {
fontSize: 45,
color: "black",
marginVertical: 10,
},
normal: {
fontSize: 22,
color: "black",
marginVertical: 5,
textAlign: "center",
},
death: {
color: "red",
},
recovered: {
color: "blue",
},
active: {
fontWeight: "bold",
},
update: {
color: "purple",
fontWeight: "bold",
},
total: {
color: "green",
},
});
const Covid = () => {
const [input, setInput] = useState("");
const [data, setData] = useState([]);
const [loading, setLoading] = useState(false);
const fetchDataHandler = useCallback(() => {
setLoading(true);
setInput("");
axios({
method: "GET",
url: `https://api.covid19india.org/data.json`,
})
.then((res) => {
setData(res.data.statewise);
})
.catch((err) => {
console.dir(err);
})
.finally(() => {
setLoading(false);
});
});
const particularState = (data, input) => {
let i = 0;
for (i = 0; i < data.length; i++) {
var state = data[i];
if (state.state == input) {
console.log(data[i]);
setData(data[i]);
}
}
};
return (
<ScrollView style={styles.root}>
<View>
<Text
style={{
marginTop: 60,
alignSelf: "center",
fontSize: 30,
fontWeight: "bold",
color: "orange",
fontFamily: "monospace",
}}
>
Covid Cases Tracker
</Text>
<TextInput
placeholder="Enter state name and press return..."
style={styles.textInput}
onChangeText={(text) => setInput(text)}
placeholderTextColor={"#000"}
onSubmitEditing={fetchDataHandler}
value={input}
/>
</View>
{particularState(data, input)}
{data.statecode !== undefined ? (
<View style={styles.infoView}>
<Text
style={[styles.normal, styles.state]}
>{`${data.state}, ${data.statecode}`}</Text>
<Text
style={[styles.normal, styles.total]}
>{`Total Cases : ${data.confirmed}`}</Text>
<Text
style={[styles.normal, styles.death]}
>{`Deaths : ${data.deaths}`}</Text>
<Text
style={[styles.normal, styles.recovered]}
>{`Recovered : ${data.recovered}`}</Text>
<Text
style={[styles.normal, styles.active]}
>{`Active Cases : ${data.active}`}</Text>
<Text
style={[styles.normal, styles.update]}
>{`Last Updated : ${data.lastupdatedtime}`}</Text>
<Text style={styles.normal}>{`${data.statenotes}`}</Text>
</View>
) : null}
</ScrollView>
);
};
export default Covid;