No Description

App.js 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. //calls data query
  16. function loadDoc(query) {
  17. var xhttp = new XMLHttpRequest();
  18. xhttp.onreadystatechange = function() {
  19. if (this.readyState == 4 && this.status == 200) {
  20. information = this.responseText;
  21. console.log(information[6])
  22. organize()
  23. }
  24. };
  25. xhttp.open("GET", query, true);
  26. xhttp.send();
  27. }
  28. //"https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP02PR)&for=county:127&in=state:72"
  29. //change this to an external css file later
  30. const styles = StyleSheet.create({
  31. buttons: {
  32. flexDirection: 'row',
  33. justifyContent: 'center',
  34. marginTop: 40,
  35. marginBottom: 30,
  36. margin: 30,
  37. borderColor: "grey",
  38. },
  39. container: {
  40. flexDirection: 'column',
  41. justifyContent: 'center',
  42. backgroundColor: 'black',
  43. alignItems: 'center',
  44. justifyContent: 'center',
  45. marginTop: 20,
  46. },
  47. containerbackground:{
  48. backgroundColor: '#063970',
  49. marginTop: 20
  50. },
  51. intro: {
  52. fontWeight: "bold",
  53. color:"#beb2c8",
  54. fontSize: 30,
  55. },
  56. sub: {
  57. color:"#D7D6D6",
  58. fontSize: 20
  59. },
  60. scrollView:{
  61. marginHorizontal: 20
  62. },
  63. listItem:{
  64. fontSize: 30,
  65. color: "white",
  66. textDecorationLines: "underline"
  67. },
  68. listButtons:{
  69. fontSize: 15,
  70. color: "white",
  71. textDecorationLines: "underline"
  72. },
  73. buttonsVer: {
  74. flexDirection: 'column',
  75. justifyContent: 'center',
  76. marginTop: 40,
  77. marginBottom: 30,
  78. margin: 30,
  79. borderColor: "grey",
  80. }
  81. });
  82. //default button press
  83. const handlePress = () => false
  84. //data parsing goes here
  85. function importJSON() {
  86. var stuff = JSON.stringify(data)
  87. return stuff
  88. }
  89. //calls update to data in data page
  90. function updateInfo(option){
  91. switch(option){
  92. case 0:
  93. break;
  94. case 1:
  95. loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP02PR)&for=county:127&in=state:72")
  96. break;
  97. case 2:
  98. loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP03)&for=county:127&in=state:72")
  99. break;
  100. case 3:
  101. loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP04)&for=county:127&in=state:72")
  102. break;
  103. case 4:
  104. loadDoc("https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP05)&for=county:127&in=state:72")
  105. break;
  106. }
  107. }
  108. //data display
  109. function DataDisplay({option}) {
  110. const [tableValue, setTableValue] = useState(0);
  111. useEffect(() => {
  112. setTableValue(option * 1);
  113. console.log(tableValue)
  114. updateInfo(tableValue);
  115. }, [option]); // add props as dependencies
  116. return (
  117. <Text style={styles.sub}>{information}</Text>
  118. );
  119. }
  120. //data pick
  121. /*
  122. function Parent() {
  123. const [parentOption, setParentOption] = useState(0);
  124. return (
  125. <View>
  126. <Pressable onPress = {() => setParentOption(current => 1)}>
  127. <Text style = {styles.listItem}> DP02PR </Text>
  128. </Pressable>
  129. <Pressable onPress = {() => setParentOption(current => 2)}>
  130. <Text style = {styles.listItem}> DP03PR </Text>
  131. </Pressable>
  132. <Pressable onPress = {() => setParentOption(current => 3)}>
  133. <Text style = {styles.listItem}> DP04PR </Text>
  134. </Pressable>
  135. <Pressable onPress = {() => setParentOption(current => 4)}>
  136. <Text style = {styles.listItem}> DP05PR </Text>
  137. </Pressable>
  138. <DataDisplay parentOption={parentOption} />
  139. </View>
  140. );
  141. }
  142. */
  143. //picker test
  144. function Picker() {
  145. //table to pick from
  146. const [open, setOpen] = useState(false);
  147. const [option, setOption] = useState(0);
  148. const [value, setValue] = useState(0);
  149. const [table, setTable] = useState([
  150. {label:'DP02PR', value: 1},
  151. {label:'DP03', value: 2},
  152. {label:'DP04', value: 3},
  153. {label:'DP05', value: 4},
  154. ]);
  155. //cambiar pueblo
  156. /*
  157. //pueblo
  158. const [open2, setOpen2] = useState(false);
  159. const [value2, setValue2] = useState(null);
  160. const [pueblo, setPueblo] = useState([
  161. {label: 'Apple', value: 'apple'},
  162. {label: 'Banana', value: 'banana'}
  163. ]);
  164. */
  165. return (
  166. <View>
  167. <DropDownPicker
  168. open={open}
  169. value={value}
  170. items={table}
  171. setOpen={setOpen}
  172. setValue={setValue}
  173. setItems={setTable}
  174. onChangeValue={(value) => {
  175. setOption(current => value);
  176. }}
  177. />
  178. <DataDisplay option={option} />
  179. </View>
  180. );
  181. }
  182. //actual application
  183. class App extends React.Component {
  184. vars = {
  185. welcome:
  186. <View style = {styles.containerbackground}>
  187. <ScrollView style={styles.scrollView}>
  188. <View style = {styles.container}>
  189. <Text style={styles.intro}>BIENVENIDO!!!!</Text>
  190. <Text style={styles.sub}>Aqui podra mantenerse al tanto con las
  191. ultimas noticias relacionadas al censo</Text>
  192. <Image source={require('./testimg.gif')} />
  193. </View>
  194. </ScrollView>
  195. </View>,
  196. newsView:
  197. <View style = {styles.containerbackground}>
  198. <ScrollView style={styles.scrollView}>
  199. <View style = {styles.container}>
  200. <Text style={styles.intro}>Noticias</Text>
  201. <Image source={require('./testimg.gif')} />
  202. </View>
  203. </ScrollView></View>,
  204. dataOp:
  205. <View style = {styles.containerbackground}>
  206. <ScrollView nestedScrollEnabled = {true} style={styles.scrollView}>
  207. <View style = {styles.container}>
  208. <Text style={styles.intro}>DATA VIEWING PROJECT</Text>
  209. <Picker />
  210. <Image source={require('./testimg.gif')} />
  211. </View>
  212. </ScrollView></View>
  213. }
  214. //current state
  215. state = {current: this.vars.welcome}
  216. //state changing functions
  217. setHome = () => this.setState({ current: this.vars.welcome })
  218. setData = () => this.setState({current: this.vars.dataOp})
  219. setNews = () => this.setState({ current: this.vars.newsView })
  220. //render app
  221. render() {
  222. return (
  223. <View>
  224. <View style = {styles.containerbackground}>
  225. <View style = {styles.container}>
  226. <Text style={styles.sub}> Navegador</Text>
  227. <View style = {styles.buttons}>
  228. <Button
  229. onPress = {this.setNews}
  230. title = "Noticias"
  231. color = "blue"
  232. />
  233. <Button
  234. onPress = {this.setData}
  235. title = "Datos"
  236. color = "black"
  237. />
  238. </View>
  239. {this.state.current}
  240. </View>
  241. </View>
  242. </View>
  243. );
  244. }
  245. }
  246. export default App