No Description

App.js 5.5KB

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