Açıklama Yok

App.js 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. import { StatusBar } from 'expo-status-bar';
  2. import React, {useState, useEffect} from 'react';
  3. import { View, Image, StyleSheet, Text, Button, ScrollView, Pressable} from 'react-native';
  4. import data from './transfer.json'
  5. import DropDownPicker from 'react-native-dropdown-picker';
  6. //where data will be put
  7. var organizedData
  8. //where data will be stored
  9. var information = "data goes here"
  10. //organize data make it pretty
  11. function organize(){
  12. }
  13. //fix
  14. DropDownPicker.setListMode("SCROLLVIEW")
  15. //data query variables (global)
  16. const queryBase = "https://api.census.gov/data/2020/acs/acs5/profile?get=group"
  17. const queryEnd = "&in=state:72"
  18. var table = ""
  19. var pueblo = ""
  20. function updateTable(value){
  21. table = value
  22. }
  23. function updatePueblo(value){
  24. pueblo = value
  25. }
  26. //calls data query
  27. function loadDoc(query) {
  28. var xhttp = new XMLHttpRequest();
  29. xhttp.onreadystatechange = function() {
  30. if (this.readyState == 4 && this.status == 200) {
  31. information = this.responseText;
  32. //organize()
  33. }
  34. };
  35. xhttp.open("GET", query, true);
  36. xhttp.send();
  37. }
  38. //"https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP02PR)&for=county:127&in=state:72"
  39. function fetchData() {
  40. console.log("fetching data")
  41. var query = queryBase + "(" + table + ")&for=county:" + pueblo + queryEnd
  42. console.log(query)
  43. loadDoc(query)
  44. }
  45. //change this to an external css file later
  46. const styles = StyleSheet.create({
  47. buttons: {
  48. flexDirection: 'row',
  49. justifyContent: 'center',
  50. marginTop: 40,
  51. marginBottom: 30,
  52. margin: 30,
  53. borderColor: "grey",
  54. },
  55. container: {
  56. flexDirection: 'column',
  57. justifyContent: 'center',
  58. backgroundColor: 'black',
  59. alignItems: 'center',
  60. justifyContent: 'center',
  61. marginTop: 20,
  62. },
  63. containerbackground:{
  64. backgroundColor: '#063970',
  65. marginTop: 20
  66. },
  67. intro: {
  68. fontWeight: "bold",
  69. color:"#beb2c8",
  70. fontSize: 30,
  71. },
  72. sub: {
  73. color:"#D7D6D6",
  74. fontSize: 20
  75. },
  76. scrollView:{
  77. marginHorizontal: 20
  78. },
  79. listItem:{
  80. fontSize: 30,
  81. color: "white",
  82. textDecorationLines: "underline"
  83. },
  84. listButtons:{
  85. fontSize: 15,
  86. color: "white",
  87. textDecorationLines: "underline"
  88. },
  89. buttonsVer: {
  90. flexDirection: 'column',
  91. justifyContent: 'center',
  92. marginTop: 40,
  93. marginBottom: 30,
  94. margin: 30,
  95. borderColor: "grey",
  96. }
  97. });
  98. //default button press
  99. const handlePress = () => false
  100. //data parsing goes here
  101. function importJSON() {
  102. var stuff = JSON.stringify(data)
  103. return stuff
  104. }
  105. //data display
  106. function DataDisplay({valueTable, valuePueblo}) {
  107. const [tableValue, setTableValue] = useState(null);
  108. const [puebloValue, setPuebloValue] = useState(null);
  109. console.log("tableOption:",valueTable)
  110. console.log("puebloOption:",valuePueblo)
  111. //theres something wrong with this, its applying the previous value of valueTable and valuePueblo instead of the actual value
  112. useEffect(() => {
  113. setTableValue(valueTable);
  114. console.log("tableValue:",tableValue)
  115. //if not undefined
  116. if(tableValue){updateTable(tableValue);}
  117. }, [valueTable]); // add props as dependencies
  118. useEffect(() => {
  119. setPuebloValue(valuePueblo);
  120. console.log("puebloValue:",puebloValue)
  121. if(puebloValue){updatePueblo(puebloValue)};
  122. }, [valuePueblo]); // add props as dependencies
  123. return (
  124. <View>
  125. <Text style={styles.sub}>{information}</Text>
  126. <Button
  127. onPress = {fetchData()}
  128. title = "Fetch Data"
  129. color = "black"
  130. />
  131. </View>
  132. );
  133. }
  134. //data pick
  135. /*
  136. function Parent() {
  137. const [parentOption, setParentOption] = useState(0);
  138. return (
  139. <View>
  140. <Pressable onPress = {() => setParentOption(current => 1)}>
  141. <Text style = {styles.listItem}> DP02PR </Text>
  142. </Pressable>
  143. <Pressable onPress = {() => setParentOption(current => 2)}>
  144. <Text style = {styles.listItem}> DP03PR </Text>
  145. </Pressable>
  146. <Pressable onPress = {() => setParentOption(current => 3)}>
  147. <Text style = {styles.listItem}> DP04PR </Text>
  148. </Pressable>
  149. <Pressable onPress = {() => setParentOption(current => 4)}>
  150. <Text style = {styles.listItem}> DP05PR </Text>
  151. </Pressable>
  152. <DataDisplay parentOption={parentOption} />
  153. </View>
  154. );
  155. }
  156. */
  157. //picker test
  158. function Picker() {
  159. //table to pick from
  160. const [openTable, setOpenTable] = useState(false);
  161. //const [tableOption, setTableOption] = useState(0);
  162. const [valueTable, setValueTable] = useState(null);
  163. const [table, setTable] = useState([
  164. {label:'DP02PR', value: 'DP02PR'},
  165. {label:'DP03', value: 'DP03'},
  166. {label:'DP04', value: 'DP04'},
  167. {label:'DP05', value: 'DP05'},
  168. ]);
  169. //cambiar pueblo
  170. //pueblo
  171. const [openPueblo, setOpenPueblo] = useState(false);
  172. //const [puebloOption, setPuebloOption] = useState(0);
  173. const [valuePueblo, setValuePueblo] = useState(null);
  174. const [pueblo, setPueblo] = useState([
  175. {label: 'Adjuntas', value: '001'},
  176. {label: 'Aguada', value: '003'},
  177. {label: 'Aguadillas', value: '005'},
  178. {label: 'Aguas Buenas', value: '007'},
  179. {label: 'Aibonito', value: '009'},
  180. {label: 'Añasco', value: '011'},
  181. {label: 'Arecibo', value: '013'},
  182. {label: 'Arroyo', value: '015'},
  183. {label: 'Barceloneta', value: '017'},
  184. {label: 'Barranquitas', value: '019'},
  185. {label: 'Bayamón', value: '021'},
  186. {label: 'Cabo Rojo', value: '023'},
  187. {label: 'Caguas', value: '025'},
  188. {label: 'Camuy', value: '027'},
  189. {label: 'Canóvanas', value: '029'},
  190. {label: 'Carolina', value: '031'},
  191. {label: 'Cataño', value: '033'},
  192. {label: 'Cayey', value: '035'},
  193. {label: 'Ceiba', value: '037'},
  194. {label: 'Ciales', value: '039'},
  195. {label: 'Cidra', value: '041'},
  196. {label: 'Coamo', value: '043'},
  197. {label: 'Comerío', value: '045'},
  198. {label: 'Corozal', value: '047'},
  199. {label: 'Culebra', value: '049'},
  200. {label: 'Dorado', value: '051'},
  201. {label: 'Fajardo', value: '053'},
  202. {label: 'Florida', value: '054'},
  203. {label: 'Guánica', value: '055'},
  204. {label: 'Guayama', value: '057'},
  205. {label: 'Guayanilla', value: '059'},
  206. {label: 'Guaynabo', value: '061'},
  207. {label: 'Gurabo', value: '063'},
  208. {label: 'Hatillo', value: '065'},
  209. {label: 'Hormigueros', value: '067'},
  210. {label: 'Humacao', value: '069'},
  211. {label: 'Isabela', value: '071'},
  212. {label: 'Jayuya', value: '073'},
  213. {label: 'Juana Díaz', value: '075'},
  214. {label: 'Juncos', value: '077'},
  215. {label: 'Lajas', value: '079'},
  216. {label: 'Lares', value: '081'},
  217. {label: 'Las Marías', value: '083'},
  218. {label: 'Las Piedras', value: '085'},
  219. {label: 'Loíza', value: '087'},
  220. {label: 'Luquillo', value: '089'},
  221. {label: 'Manatí', value: '091'},
  222. {label: 'Maricao', value: '093'},
  223. {label: 'Maunabo', value: '095'},
  224. {label: 'Mayagüez', value: '097'},
  225. {label: 'Moca', value: '099'},
  226. {label: 'Morovis', value: '101'},
  227. {label: 'Naguabo', value: '103'},
  228. {label: 'Naranjito', value: '105'},
  229. {label: 'Orocovis', value: '107'},
  230. {label: 'Patillas', value: '109'},
  231. {label: 'Peñuelas', value: '111'},
  232. {label: 'Ponce', value: '113'},
  233. {label: 'Quebradillas', value: '115'},
  234. {label: 'Rincón', value: '117'},
  235. {label: 'Río Grande', value: '119'},
  236. {label: 'Sabana Grande', value: '121'},
  237. {label: 'Salinas', value: '123'},
  238. {label: 'San Germán', value: '125'},
  239. {label: 'San Juan', value: '127'},
  240. {label: 'San Lorenzo', value: '129'},
  241. {label: 'San Sebastián', value: '131'},
  242. {label: 'Santa Isabel', value: '133'},
  243. {label: 'Toa Alta', value: '135'},
  244. {label: 'Toa Baja', value: '137'},
  245. {label: 'Trujillo Alto', value: '139'},
  246. {label: 'Utuado', value: '141'},
  247. {label: 'Vega Alta', value: '143'},
  248. {label: 'Vega Baja', value: '145'},
  249. {label: 'Vieques', value: '147'},
  250. {label: 'Villalba', value: '149'},
  251. {label: 'Yabucoa', value: '151'},
  252. {label: 'Yauco', value: '153'}
  253. ]);
  254. //make sure pickers are closed when another opens
  255. return (
  256. <View>
  257. <DropDownPicker
  258. open={openTable}
  259. value={valueTable}
  260. items={table}
  261. setOpen={setOpenTable}
  262. setValue={setValueTable}
  263. setItems={setTable}
  264. //onChangeValue={(valueTable) => {
  265. // setTableOption(current => valueTable);
  266. // }}
  267. onOpen = {() => {setOpenPueblo(false)}}
  268. zIndex={3000}
  269. zIndexInverse={1000}
  270. placeholder="Tabla de Datos"
  271. />
  272. <DropDownPicker
  273. searchable={true}
  274. open={openPueblo}
  275. value={valuePueblo}
  276. items={pueblo}
  277. setOpen={setOpenPueblo}
  278. setValue={setValuePueblo}
  279. setItems={setPueblo}
  280. //onChangeValue={(valuePueblo) => {
  281. // setPuebloOption(current => valuePueblo);
  282. // }}
  283. onOpen = {() => {setOpenTable(false)}}
  284. zIndex={1000}
  285. zIndexInverse={3000}
  286. placeholder="Pueblo"
  287. searchPlaceholder="Busqueda..."
  288. />
  289. <DataDisplay valueTable={valueTable} valuePueblo={valuePueblo} />
  290. </View>
  291. );
  292. }
  293. //actual application
  294. class App extends React.Component {
  295. vars = {
  296. welcome:
  297. <View style = {styles.containerbackground}>
  298. <ScrollView style={styles.scrollView}>
  299. <View style = {styles.container}>
  300. <Text style={styles.intro}>BIENVENIDO!!!!</Text>
  301. <Text style={styles.sub}>Aqui podra mantenerse al tanto con las
  302. ultimas noticias relacionadas al censo</Text>
  303. <Image source={require('./testimg.gif')} />
  304. </View>
  305. </ScrollView>
  306. </View>,
  307. newsView:
  308. <View style = {styles.containerbackground}>
  309. <ScrollView style={styles.scrollView}>
  310. <View style = {styles.container}>
  311. <Text style={styles.intro}>Noticias</Text>
  312. <Image source={require('./testimg.gif')} />
  313. </View>
  314. </ScrollView></View>,
  315. dataOp:
  316. <View style = {styles.containerbackground}>
  317. <ScrollView nestedScrollEnabled = {true} style={styles.scrollView}>
  318. <View style = {styles.container}>
  319. <Text style={styles.intro}>DATA VIEWING PROJECT</Text>
  320. <Picker />
  321. <Image source={require('./testimg.gif')} />
  322. </View>
  323. </ScrollView></View>
  324. }
  325. //current state
  326. state = {current: this.vars.welcome}
  327. //state changing functions
  328. setHome = () => this.setState({ current: this.vars.welcome })
  329. setData = () => this.setState({current: this.vars.dataOp})
  330. setNews = () => this.setState({ current: this.vars.newsView })
  331. //render app
  332. render() {
  333. return (
  334. <View>
  335. <View style = {styles.containerbackground}>
  336. <View style = {styles.container}>
  337. <Text style={styles.sub}> Navegador</Text>
  338. <View style = {styles.buttons}>
  339. <Button
  340. onPress = {this.setNews}
  341. title = "Noticias"
  342. color = "blue"
  343. />
  344. <Button
  345. onPress = {this.setData}
  346. title = "Datos"
  347. color = "black"
  348. />
  349. </View>
  350. {this.state.current}
  351. </View>
  352. </View>
  353. </View>
  354. );
  355. }
  356. }
  357. export default App