Browse Source

Check option change, numbers dont match up

andrea.nieves7 2 years ago
parent
commit
f43557f310
1 changed files with 78 additions and 12 deletions
  1. 78
    12
      App.js

+ 78
- 12
App.js View File

@@ -2,7 +2,7 @@ import { StatusBar } from 'expo-status-bar';
2 2
 import React, {useState, useEffect} from 'react';
3 3
 import { View, Image, StyleSheet, Text, Button, ScrollView, Pressable} from 'react-native';
4 4
 import data from './transfer.json' 
5
-import { Dropdown } from 'react-native-element-dropdown';
5
+import DropDownPicker from 'react-native-dropdown-picker';
6 6
 
7 7
 //where data will be put
8 8
 var organizedData
@@ -18,6 +18,10 @@ function organize(){
18 18
 	
19 19
 }
20 20
 
21
+//fix
22
+
23
+DropDownPicker.setListMode("SCROLLVIEW")
24
+
21 25
 //calls data query
22 26
 function loadDoc(query) {
23 27
   var xhttp = new XMLHttpRequest();
@@ -120,27 +124,32 @@ function updateInfo(option){
120 124
 			loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP02PR)&for=county:127&in=state:72")
121 125
 			break;
122 126
 		case 2:
123
-			loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP03PR)&for=county:127&in=state:72")
127
+			loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP03)&for=county:127&in=state:72")
124 128
 			break;
125 129
 		case 3:
126
-			loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP04PR)&for=county:127&in=state:72")
130
+			loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP04)&for=county:127&in=state:72")
127 131
 			break;
128 132
 		case 4:
129
-			loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP05PR)&for=county:127&in=state:72")
133
+			loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP05)&for=county:127&in=state:72")
130 134
 			break;
131 135
 		
132 136
 	}
133 137
 }
134 138
 
135 139
 
136
-function DataDisplay({parentOption}) {
137
-  const [option, setOption] = useState(0);
140
+
141
+
142
+//data display
143
+
144
+function DataDisplay({option}) {
145
+  const [tableValue, setTableValue] = useState(0);
146
+
138 147
 
139 148
   useEffect(() => {
140
-    setOption(parentOption);
141
-	console.log(option)
142
-    updateInfo(option);
143
-  }, [parentOption]); // 👈️ add props as dependencies
149
+    setTableValue(option * 1);
150
+	console.log(tableValue)
151
+    updateInfo(tableValue);
152
+  }, [option]); // add props as dependencies
144 153
 
145 154
 
146 155
   return (
@@ -148,6 +157,8 @@ function DataDisplay({parentOption}) {
148 157
   );
149 158
 }
150 159
 
160
+//data pick
161
+/*
151 162
 function Parent() {
152 163
   const [parentOption, setParentOption] = useState(0);
153 164
 
@@ -173,8 +184,63 @@ function Parent() {
173 184
     </View>
174 185
   );
175 186
 }
187
+*/
188
+
189
+
190
+//picker test
191
+
192
+function Picker() {
193
+	
194
+	//table to pick from
195
+  
196
+  
197
+  const [open, setOpen] = useState(false);
198
+  const [option, setOption] = useState(0);
199
+  const [value, setValue] = useState(0);
200
+  const [table, setTable] = useState([
201
+    {label:'DP02PR', value: 1},
202
+    {label:'DP03', value: 2},
203
+	{label:'DP04', value: 3},
204
+    {label:'DP05', value: 4},
205
+  ]);
206
+    
207
+  //cambiar pueblo
208
+  
209
+  /*
210
+  //pueblo
211
+  const [open2, setOpen2] = useState(false);
212
+  const [value2, setValue2] = useState(null);
213
+  const [pueblo, setPueblo] = useState([
214
+    {label: 'Apple', value: 'apple'},
215
+    {label: 'Banana', value: 'banana'}
216
+  ]);
217
+  */
218
+
219
+  return (
220
+  <View>
221
+    <DropDownPicker
222
+      open={open}
223
+      value={value}
224
+      items={table}
225
+      setOpen={setOpen}
226
+      setValue={setValue}
227
+      setItems={setTable}
228
+	  onChangeValue={(value) => {
229
+		setOption(current => value);
230
+		}}
231
+
232
+    />
233
+	
234
+	<DataDisplay option={option} />
235
+	
236
+	</View>
237
+  );
238
+}
176 239
 
177 240
 
241
+
242
+//actual application
243
+
178 244
 class App extends React.Component {
179 245
 
180 246
 
@@ -213,13 +279,13 @@ vars = {
213 279
 		
214 280
 		dataOp:
215 281
 		<View style = {styles.containerbackground}>
216
-		<ScrollView style={styles.scrollView}>
282
+		<ScrollView nestedScrollEnabled = {true} style={styles.scrollView}>
217 283
 		 <View style = {styles.container}>
218 284
 			
219 285
 		  
220 286
 			<Text style={styles.intro}>DATA VIEWING PROJECT</Text>		
221 287
 			
222
-			<Parent />
288
+			<Picker />
223 289
 			
224 290
 			<Image source={require('./testimg.gif')} />
225 291