|
@@ -1,14 +1,14 @@
|
1
|
1
|
import { StatusBar } from 'expo-status-bar';
|
2
|
|
-import React from 'react';
|
3
|
|
-import { View, Image, StyleSheet, Text, Button, ScrollView } from 'react-native';
|
|
2
|
+import React, {useState, useEffect} from 'react';
|
|
3
|
+import { View, Image, StyleSheet, Text, Button, ScrollView, Pressable} from 'react-native';
|
4
|
4
|
import data from './transfer.json'
|
5
|
|
-
|
|
5
|
+import { Dropdown } from 'react-native-element-dropdown';
|
6
|
6
|
|
7
|
7
|
//where data will be put
|
8
|
8
|
var organizedData
|
9
|
9
|
|
10
|
10
|
//where data will be stored
|
11
|
|
-var information = "default text"
|
|
11
|
+var information = "data goes here"
|
12
|
12
|
|
13
|
13
|
//organize data make it pretty
|
14
|
14
|
function organize(){
|
|
@@ -18,24 +18,23 @@ function organize(){
|
18
|
18
|
|
19
|
19
|
}
|
20
|
20
|
|
21
|
|
-
|
22
|
21
|
//calls data query
|
23
|
|
-function loadDoc() {
|
|
22
|
+function loadDoc(query) {
|
24
|
23
|
var xhttp = new XMLHttpRequest();
|
25
|
24
|
xhttp.onreadystatechange = function() {
|
26
|
25
|
if (this.readyState == 4 && this.status == 200) {
|
27
|
26
|
information = this.responseText;
|
|
27
|
+ console.log(information[6])
|
28
|
28
|
organize()
|
29
|
29
|
}
|
30
|
30
|
};
|
31
|
|
- xhttp.open("GET", "https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP02PR)&for=county:127&in=state:72", true);
|
|
31
|
+ xhttp.open("GET", query, true);
|
32
|
32
|
xhttp.send();
|
33
|
33
|
|
34
|
34
|
}
|
35
|
35
|
|
36
|
|
-loadDoc()
|
37
|
|
-
|
38
|
36
|
|
|
37
|
+//"https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP02PR)&for=county:127&in=state:72"
|
39
|
38
|
|
40
|
39
|
|
41
|
40
|
|
|
@@ -75,9 +74,28 @@ const styles = StyleSheet.create({
|
75
|
74
|
},
|
76
|
75
|
scrollView:{
|
77
|
76
|
marginHorizontal: 20
|
|
77
|
+ },
|
|
78
|
+ listItem:{
|
|
79
|
+ fontSize: 30,
|
|
80
|
+ color: "white",
|
|
81
|
+ textDecorationLines: "underline"
|
|
82
|
+ },
|
|
83
|
+ listButtons:{
|
|
84
|
+ fontSize: 15,
|
|
85
|
+ color: "white",
|
|
86
|
+ textDecorationLines: "underline"
|
|
87
|
+ },
|
|
88
|
+ buttonsVer: {
|
|
89
|
+ flexDirection: 'column',
|
|
90
|
+ justifyContent: 'center',
|
|
91
|
+ marginTop: 40,
|
|
92
|
+ marginBottom: 30,
|
|
93
|
+ margin: 30,
|
|
94
|
+ borderColor: "grey",
|
78
|
95
|
}
|
79
|
96
|
});
|
80
|
97
|
|
|
98
|
+
|
81
|
99
|
//default button press
|
82
|
100
|
|
83
|
101
|
const handlePress = () => false
|
|
@@ -90,10 +108,77 @@ function importJSON() {
|
90
|
108
|
return stuff
|
91
|
109
|
}
|
92
|
110
|
|
93
|
|
-//states
|
|
111
|
+//calls update to data in data page
|
94
|
112
|
|
95
|
|
-let states = {
|
|
113
|
+function updateInfo(option){
|
|
114
|
+
|
|
115
|
+ switch(option){
|
96
|
116
|
|
|
117
|
+ case 0:
|
|
118
|
+ break;
|
|
119
|
+ case 1:
|
|
120
|
+ loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP02PR)&for=county:127&in=state:72")
|
|
121
|
+ break;
|
|
122
|
+ case 2:
|
|
123
|
+ loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP03PR)&for=county:127&in=state:72")
|
|
124
|
+ break;
|
|
125
|
+ case 3:
|
|
126
|
+ loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP04PR)&for=county:127&in=state:72")
|
|
127
|
+ break;
|
|
128
|
+ case 4:
|
|
129
|
+ loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP05PR)&for=county:127&in=state:72")
|
|
130
|
+ break;
|
|
131
|
+
|
|
132
|
+ }
|
|
133
|
+}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+function DataDisplay({parentOption}) {
|
|
137
|
+ const [option, setOption] = useState(0);
|
|
138
|
+
|
|
139
|
+ useEffect(() => {
|
|
140
|
+ setOption(parentOption);
|
|
141
|
+ console.log(option)
|
|
142
|
+ updateInfo(option);
|
|
143
|
+ }, [parentOption]); // 👈️ add props as dependencies
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+ return (
|
|
147
|
+ <Text style={styles.sub}>{information}</Text>
|
|
148
|
+ );
|
|
149
|
+}
|
|
150
|
+
|
|
151
|
+function Parent() {
|
|
152
|
+ const [parentOption, setParentOption] = useState(0);
|
|
153
|
+
|
|
154
|
+ return (
|
|
155
|
+ <View>
|
|
156
|
+ <Pressable onPress = {() => setParentOption(current => 1)}>
|
|
157
|
+ <Text style = {styles.listItem}> DP02PR </Text>
|
|
158
|
+ </Pressable>
|
|
159
|
+
|
|
160
|
+ <Pressable onPress = {() => setParentOption(current => 2)}>
|
|
161
|
+ <Text style = {styles.listItem}> DP03PR </Text>
|
|
162
|
+ </Pressable>
|
|
163
|
+
|
|
164
|
+ <Pressable onPress = {() => setParentOption(current => 3)}>
|
|
165
|
+ <Text style = {styles.listItem}> DP04PR </Text>
|
|
166
|
+ </Pressable>
|
|
167
|
+
|
|
168
|
+ <Pressable onPress = {() => setParentOption(current => 4)}>
|
|
169
|
+ <Text style = {styles.listItem}> DP05PR </Text>
|
|
170
|
+ </Pressable>
|
|
171
|
+
|
|
172
|
+ <DataDisplay parentOption={parentOption} />
|
|
173
|
+ </View>
|
|
174
|
+ );
|
|
175
|
+}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+class App extends React.Component {
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+vars = {
|
97
|
182
|
welcome:
|
98
|
183
|
|
99
|
184
|
|
|
@@ -124,45 +209,41 @@ let states = {
|
124
|
209
|
<Image source={require('./testimg.gif')} />
|
125
|
210
|
|
126
|
211
|
</View>
|
127
|
|
- </ScrollView></View>
|
128
|
|
-
|
|
212
|
+ </ScrollView></View>,
|
129
|
213
|
|
130
|
|
- }
|
131
|
|
-
|
132
|
|
-function dataView(){
|
133
|
|
- return (
|
134
|
|
- <View style = {styles.containerbackground}>
|
|
214
|
+ dataOp:
|
|
215
|
+ <View style = {styles.containerbackground}>
|
135
|
216
|
<ScrollView style={styles.scrollView}>
|
136
|
217
|
<View style = {styles.container}>
|
|
218
|
+
|
137
|
219
|
|
138
|
|
-
|
139
|
|
- <Text style={styles.intro}>DATADATADATADATADATA</Text>
|
140
|
|
-
|
141
|
|
- <Text style={styles.sub}>{information}</Text>
|
142
|
|
-
|
|
220
|
+ <Text style={styles.intro}>DATA VIEWING PROJECT</Text>
|
|
221
|
+
|
|
222
|
+ <Parent />
|
|
223
|
+
|
143
|
224
|
<Image source={require('./testimg.gif')} />
|
144
|
225
|
|
145
|
226
|
</View>
|
146
|
227
|
</ScrollView></View>
|
147
|
|
- )
|
148
|
|
-}
|
149
|
|
-
|
150
|
|
-
|
151
|
|
-class App extends React.Component {
|
|
228
|
+
|
|
229
|
+
|
152
|
230
|
|
|
231
|
+
|
|
232
|
+ }
|
153
|
233
|
//current state
|
154
|
|
-state = {current: states.welcome}
|
|
234
|
+state = {current: this.vars.welcome}
|
155
|
235
|
|
156
|
236
|
//state changing functions
|
157
|
|
-setHome = () => this.setState({ current: states.welcome })
|
|
237
|
+setHome = () => this.setState({ current: this.vars.welcome })
|
158
|
238
|
|
159
|
239
|
|
160
|
|
-setData = () => this.setState({current: dataView()})
|
|
240
|
+setData = () => this.setState({current: this.vars.dataOp})
|
161
|
241
|
|
162
|
242
|
|
163
|
|
-setNews = () => this.setState({ current: states.newsView })
|
164
|
|
-
|
|
243
|
+setNews = () => this.setState({ current: this.vars.newsView })
|
|
244
|
+
|
165
|
245
|
|
|
246
|
+
|
166
|
247
|
//render app
|
167
|
248
|
render() {
|
168
|
249
|
return (
|