Без опису

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import React, { useEffect, useState } from 'react';
  2. import { ActivityIndicator, Button, 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://192.168.1.200:5000/send?PIN=2'); // 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 sendVotos() {
  27. }
  28. {/*function getVotoFavorNums() {
  29. const [countFavor, setCountFavor] = useState(0);
  30. const [countContra, setCountContra] = useState(0);
  31. const [countAbstenid, setCountAbstenid] = useState(0);
  32. return (
  33. <div>
  34. <button onClick={() => setCountFavor(countFavor + 1)}>
  35. A favor
  36. </button>
  37. <button onClick={() => setCountContra(countContra + 1)}>
  38. En contra
  39. </button>
  40. </div>
  41. );
  42. }
  43. function getVotoAbstenidNums() {
  44. const [countAbstenid, setCountAbstenid] = useState(0);
  45. return (
  46. <div>
  47. <button onClick={() => setCountAbstenid(countAbstenid + 1)}>
  48. Abstenida/o
  49. </button>
  50. </div>
  51. );
  52. }
  53. function getVotoNums() {
  54. getVotoFavorNums();
  55. getVotoContraNums();
  56. getVotoAbstenidNums();
  57. }
  58. const getVotos = async () => {
  59. try {
  60. const response = await fetch('http://192.168.1.200:5000/send?PIN=121071'); // connection to the website
  61. const json = await response.json();
  62. // Getting votes count
  63. getVotoNums();
  64. } catch (error) {
  65. console.error(error);
  66. } finally {
  67. setLoading(false); // once found the loading icon will be replaced with the content of the json
  68. }
  69. } */}
  70. useEffect(() => {
  71. getMociones();
  72. //getVotos();
  73. }, []);
  74. // this is for displaying the mocion, its description, and votes' options on the screen
  75. return (
  76. <View style={{ flex: 1, padding: 24 }}>
  77. <Text>{Mocion}</Text>
  78. <Text>{Description}</Text>
  79. <Button title = "A favor " color={'#e81b39'} />
  80. <Button title = "En Contra" color={'#e81b39'} />
  81. <Button title = "Abstenido" color={'#e81b39'} />
  82. </View>
  83. );
  84. };