Sin descripción

MocionScreen.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import React, { useEffect, useState } from 'react';
  2. import { ActivityIndicator, FlatList, Text, TouchableOpacity, View } from 'react-native';
  3. import { globalStyles } from '../styles/global';
  4. export default App = () => {
  5. const [isLoading, setLoading] = useState(true);
  6. const [Description, setDescription] = useState([]); // this is looking for 'Description' and it's content
  7. const [Mocion, setMocion] = useState([]); // this is looking for 'Mocion' and it's content
  8. const [PIN, setPIN] = useState([]); // this is looking for 'PIN' and it's content
  9. const [Votos, setVotos] = useState(0); // this is looking for 'Votos' and it's content
  10. // this connects us to the API and fetches the json file with the mociones
  11. const getMociones = async () => {
  12. try {
  13. const response = await fetch('http://10.190.1.140:5000/send?PIN=121071'); // connection to the website
  14. const json = await response.json();
  15. // setting the content of each category
  16. setMocion(json.Mocion);
  17. setDescription(json.Description);
  18. setPIN(json.PIN);
  19. setVotos(json.Votos);
  20. } catch (error) {
  21. console.error(error);
  22. } finally {
  23. setLoading(false); // once found the loading icon will be replaced with the content of the json
  24. }
  25. }
  26. function getVotoFavorNums() {
  27. const [countFavor, setCountFavor] = useState(0);
  28. return (
  29. <div>
  30. <button onClick={() => setCountFavor(countFavor + 1)}>
  31. A favor
  32. </button>
  33. </div>
  34. );
  35. }
  36. function getVotoContraNums() {
  37. const [countContra, setCountContra] = useState(0);
  38. return (
  39. <div>
  40. <button onClick={() => setCountContra(countContra + 1)}>
  41. En contra
  42. </button>
  43. </div>
  44. );
  45. }
  46. function getVotoAbstenidNums() {
  47. const [countAbstenid, setCountAbstenid] = useState(0);
  48. return (
  49. <div>
  50. <button onClick={() => setCountAbstenid(countAbstenid + 1)}>
  51. Abstenida/o
  52. </button>
  53. </div>
  54. );
  55. }
  56. function getVotoNums() {
  57. getVotoFavorNums();
  58. getVotoContraNums();
  59. getVotoAbstenidNums();
  60. }
  61. const getVotos = async () => {
  62. try {
  63. const response = await fetch('http://10.190.1.140:5000/send?PIN=121071'); // connection to the website
  64. const json = await response.json();
  65. // Getting votes count
  66. getVotoNums();
  67. } catch (error) {
  68. console.error(error);
  69. } finally {
  70. setLoading(false); // once found the loading icon will be replaced with the content of the json
  71. }
  72. }
  73. useEffect(() => {
  74. getMociones();
  75. getVotos();
  76. }, []);
  77. // this is for displaying the mocion, its description, and votes' options on the screen
  78. return (
  79. <View style={{ flex: 1, padding: 24 }}>
  80. <Text>{Mocion}</Text>
  81. <Text>{Description}</Text>
  82. <Button>
  83. title = "A favor"
  84. onPress={() => Alert.alert('Voto a favor')}
  85. </Button>
  86. <Button>
  87. title = "En contra"
  88. onPress={() => Alert.alert('Voto en contra')}
  89. </Button>
  90. <Button>
  91. title = "Abstenido"
  92. onPress={() => Alert.alert('Se abstuvo al voto')}
  93. </Button>
  94. </View>
  95. );
  96. };