andrea.nieves7 2 лет назад
Родитель
Сommit
b9fe2a6d5b
1 измененных файлов: 179 добавлений и 58 удалений
  1. 179
    58
      App.js

+ 179
- 58
App.js Просмотреть файл

@@ -22,14 +22,29 @@ function organize(){
22 22
 
23 23
 DropDownPicker.setListMode("SCROLLVIEW")
24 24
 
25
+//data query variables (global)
26
+
27
+const queryBase = "https://api.census.gov/data/2020/acs/acs5/profile?get=group"
28
+const queryEnd = "&in=state:72"
29
+var table = ""
30
+var pueblo = ""
31
+
32
+
33
+function updateTable(value){
34
+	table = value
35
+}
36
+
37
+function updatePueblo(value){
38
+	pueblo = value
39
+}
40
+
25 41
 //calls data query
26 42
 function loadDoc(query) {
27 43
   var xhttp = new XMLHttpRequest();
28 44
   xhttp.onreadystatechange = function() {
29 45
     if (this.readyState == 4 && this.status == 200) {
30 46
          information = this.responseText;
31
-		 console.log(information[6])
32
-		 organize()
47
+		 //organize()
33 48
   }
34 49
   };
35 50
   xhttp.open("GET", query, true);
@@ -42,6 +57,18 @@ function loadDoc(query) {
42 57
 
43 58
 
44 59
 
60
+function fetchData() {
61
+	
62
+	console.log("fetching data")
63
+	
64
+	var query = queryBase + "(" + table + ")&for=county:" + pueblo + queryEnd 
65
+	
66
+	console.log(query)
67
+	
68
+	loadDoc(query)
69
+	
70
+}
71
+
45 72
 //change this to an external css file later
46 73
 const styles = StyleSheet.create({
47 74
 	
@@ -112,48 +139,41 @@ function importJSON() {
112 139
 	return stuff
113 140
 }
114 141
 
115
-//calls update to data in data page
116
-
117
-function updateInfo(option){
118
-	
119
-	switch(option){
120
-	
121
-		case 0:
122
-			break;
123
-		case 1:
124
-			loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP02PR)&for=county:127&in=state:72")
125
-			break;
126
-		case 2:
127
-			loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP03)&for=county:127&in=state:72")
128
-			break;
129
-		case 3:
130
-			loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP04)&for=county:127&in=state:72")
131
-			break;
132
-		case 4:
133
-			loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP05)&for=county:127&in=state:72")
134
-			break;
135
-		
136
-	}
137
-}
138
-
139
-
140
-
141 142
 
142 143
 //data display
143 144
 
144
-function DataDisplay({option}) {
145
-  const [tableValue, setTableValue] = useState(0);
146
-
145
+function DataDisplay({valueTable, valuePueblo}) {
146
+  const [tableValue, setTableValue] = useState(null);
147
+  const [puebloValue, setPuebloValue] = useState(null);
148
+  
149
+  console.log("tableOption:",valueTable)
150
+  console.log("puebloOption:",valuePueblo)
151
+	
152
+//theres something wrong with this, its applying the previous value of valueTable and valuePueblo instead of the actual value
147 153
 
148 154
   useEffect(() => {
149
-    setTableValue(option * 1);
150
-	console.log(tableValue)
151
-    updateInfo(tableValue);
152
-  }, [option]); // add props as dependencies
153
-
155
+    setTableValue(valueTable);
156
+	console.log("tableValue:",tableValue)
157
+	//if not undefined
158
+	if(tableValue){updateTable(tableValue);}   
159
+  }, [valueTable]); // add props as dependencies
160
+  
161
+  useEffect(() => {
162
+    setPuebloValue(valuePueblo);
163
+	console.log("puebloValue:",puebloValue)
164
+    if(puebloValue){updatePueblo(puebloValue)};
165
+  }, [valuePueblo]); // add props as dependencies
166
+	
154 167
 
155 168
   return (
169
+  <View>
156 170
     <Text style={styles.sub}>{information}</Text>
171
+	<Button
172
+		onPress = {fetchData()}
173
+		title = "Fetch Data"
174
+		color = "black"
175
+		/>
176
+   </View>	  
157 177
   );
158 178
 }
159 179
 
@@ -194,44 +214,145 @@ function Picker() {
194 214
 	//table to pick from
195 215
   
196 216
   
197
-  const [open, setOpen] = useState(false);
198
-  const [option, setOption] = useState(0);
199
-  const [value, setValue] = useState(0);
217
+  const [openTable, setOpenTable] = useState(false);
218
+  //const [tableOption, setTableOption] = useState(0);
219
+  const [valueTable, setValueTable] = useState(null);
200 220
   const [table, setTable] = useState([
201
-    {label:'DP02PR', value: 1},
202
-    {label:'DP03', value: 2},
203
-	{label:'DP04', value: 3},
204
-    {label:'DP05', value: 4},
221
+    {label:'DP02PR', value: 'DP02PR'},
222
+    {label:'DP03', value: 'DP03'},
223
+	{label:'DP04', value: 'DP04'},
224
+    {label:'DP05', value: 'DP05'},
205 225
   ]);
206 226
     
207 227
   //cambiar pueblo
208 228
   
209
-  /*
229
+  
210 230
   //pueblo
211
-  const [open2, setOpen2] = useState(false);
212
-  const [value2, setValue2] = useState(null);
231
+  const [openPueblo, setOpenPueblo] = useState(false);
232
+  //const [puebloOption, setPuebloOption] = useState(0);
233
+  const [valuePueblo, setValuePueblo] = useState(null);
213 234
   const [pueblo, setPueblo] = useState([
214
-    {label: 'Apple', value: 'apple'},
215
-    {label: 'Banana', value: 'banana'}
235
+    {label: 'Adjuntas', value: '001'},
236
+    {label: 'Aguada', value: '003'},
237
+	{label: 'Aguadillas', value: '005'},
238
+    {label: 'Aguas Buenas', value: '007'},
239
+	{label: 'Aibonito', value: '009'},
240
+    {label: 'Añasco', value: '011'},
241
+	{label: 'Arecibo', value: '013'},
242
+    {label: 'Arroyo', value: '015'},
243
+	{label: 'Barceloneta', value: '017'},
244
+    {label: 'Barranquitas', value: '019'},
245
+	{label: 'Bayamón', value: '021'},
246
+    {label: 'Cabo Rojo', value: '023'},
247
+	{label: 'Caguas', value: '025'},
248
+    {label: 'Camuy', value: '027'},
249
+	{label: 'Canóvanas', value: '029'},
250
+	{label: 'Carolina', value: '031'},
251
+	{label: 'Cataño', value: '033'},
252
+	{label: 'Cayey', value: '035'},
253
+	{label: 'Ceiba', value: '037'},
254
+	{label: 'Ciales', value: '039'},
255
+	{label: 'Cidra', value: '041'},
256
+	{label: 'Coamo', value: '043'},
257
+	{label: 'Comerío', value: '045'},
258
+	{label: 'Corozal', value: '047'},
259
+	{label: 'Culebra', value: '049'},
260
+	{label: 'Dorado', value: '051'},
261
+	{label: 'Fajardo', value: '053'},
262
+	{label: 'Florida', value: '054'},
263
+	{label: 'Guánica', value: '055'},
264
+	{label: 'Guayama', value: '057'},
265
+	{label: 'Guayanilla', value: '059'},
266
+	{label: 'Guaynabo', value: '061'},	
267
+	{label: 'Gurabo', value: '063'},
268
+	{label: 'Hatillo', value: '065'},
269
+	{label: 'Hormigueros', value: '067'},
270
+	{label: 'Humacao', value: '069'},
271
+	{label: 'Isabela', value: '071'},
272
+	{label: 'Jayuya', value: '073'},
273
+	{label: 'Juana Díaz', value: '075'},
274
+	{label: 'Juncos', value: '077'},
275
+	{label: 'Lajas', value: '079'},
276
+	{label: 'Lares', value: '081'},
277
+	{label: 'Las Marías', value: '083'},
278
+	{label: 'Las Piedras', value: '085'},
279
+	{label: 'Loíza', value: '087'},
280
+	{label: 'Luquillo', value: '089'},
281
+	{label: 'Manatí', value: '091'},
282
+	{label: 'Maricao', value: '093'},
283
+	{label: 'Maunabo', value: '095'},
284
+	{label: 'Mayagüez', value: '097'},
285
+	{label: 'Moca', value: '099'},
286
+	{label: 'Morovis', value: '101'},
287
+	{label: 'Naguabo', value: '103'},
288
+	{label: 'Naranjito', value: '105'},
289
+	{label: 'Orocovis', value: '107'},
290
+	{label: 'Patillas', value: '109'},
291
+	{label: 'Peñuelas', value: '111'},
292
+	{label: 'Ponce', value: '113'},
293
+	{label: 'Quebradillas', value: '115'},
294
+	{label: 'Rincón', value: '117'},
295
+	{label: 'Río Grande', value: '119'},
296
+	{label: 'Sabana Grande', value: '121'},
297
+	{label: 'Salinas', value: '123'},
298
+	{label: 'San Germán', value: '125'},
299
+	{label: 'San Juan', value: '127'},
300
+	{label: 'San Lorenzo', value: '129'},
301
+	{label: 'San Sebastián', value: '131'},
302
+	{label: 'Santa Isabel', value: '133'},
303
+	{label: 'Toa Alta', value: '135'},
304
+	{label: 'Toa Baja', value: '137'},
305
+	{label: 'Trujillo Alto', value: '139'},
306
+	{label: 'Utuado', value: '141'},
307
+	{label: 'Vega Alta', value: '143'},
308
+	{label: 'Vega Baja', value: '145'},
309
+	{label: 'Vieques', value: '147'},
310
+	{label: 'Villalba', value: '149'},
311
+	{label: 'Yabucoa', value: '151'},
312
+	{label: 'Yauco', value: '153'}
216 313
   ]);
217
-  */
314
+  
315
+  
316
+  //make sure pickers are closed when another opens
317
+  
218 318
 
219 319
   return (
220 320
   <View>
221 321
     <DropDownPicker
222
-      open={open}
223
-      value={value}
322
+      open={openTable}
323
+      value={valueTable}
224 324
       items={table}
225
-      setOpen={setOpen}
226
-      setValue={setValue}
325
+      setOpen={setOpenTable}
326
+      setValue={setValueTable}
227 327
       setItems={setTable}
228
-	  onChangeValue={(value) => {
229
-		setOption(current => value);
230
-		}}
231
-
328
+	  //onChangeValue={(valueTable) => {
329
+	//	setTableOption(current => valueTable);
330
+	//	}}
331
+	  onOpen = {() => {setOpenPueblo(false)}}
332
+	  zIndex={3000}
333
+	  zIndexInverse={1000}
334
+	  placeholder="Tabla de Datos"
335
+    />
336
+	
337
+	<DropDownPicker
338
+      searchable={true}
339
+      open={openPueblo}
340
+      value={valuePueblo}
341
+      items={pueblo}
342
+      setOpen={setOpenPueblo}
343
+      setValue={setValuePueblo}
344
+      setItems={setPueblo}
345
+	  //onChangeValue={(valuePueblo) => {
346
+	//	setPuebloOption(current => valuePueblo);
347
+	//	}}
348
+	  onOpen = {() => {setOpenTable(false)}}
349
+	  zIndex={1000}
350
+      zIndexInverse={3000}
351
+	  placeholder="Pueblo"
352
+	  searchPlaceholder="Busqueda..."
232 353
     />
233 354
 	
234
-	<DataDisplay option={option} />
355
+	<DataDisplay valueTable={valueTable} valuePueblo={valuePueblo} />
235 356
 	
236 357
 	</View>
237 358
   );