Nessuna descrizione

MocionScreen.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 getVotoNums() {
  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. const [countContra, setCountContra] = useState(0);
  36. return (
  37. <div>
  38. <button onClick={() => setCountContra(countContra + 1)}>
  39. En contra
  40. </button>
  41. </div>
  42. );
  43. const [countAbstenid, setCountAbstenid] = useState(0);
  44. return (
  45. <div>
  46. <button onClick={() => setCountAbstenid(countAbstenid + 1)}>
  47. Abstenida/o
  48. </button>
  49. </div>
  50. );
  51. }
  52. const getVotos = async () => {
  53. try {
  54. const response = await fetch('http://10.190.1.140:5000/send?PIN=121071'); // connection to the website
  55. const json = await response.json();
  56. // Getting votes count
  57. getVotoNums();
  58. } catch (error) {
  59. console.error(error);
  60. } finally {
  61. setLoading(false); // once found the loading icon will be replaced with the content of the json
  62. }
  63. }
  64. useEffect(() => {
  65. getMociones();
  66. getVotos();
  67. }, []);
  68. // this is for displaying the mocion on the screen
  69. return (
  70. <View style={{ flex: 1, padding: 24 }}>
  71. <Text>{Mocion}</Text>
  72. <Text>{Description}</Text>
  73. <Text>{Votos}</Text>
  74. </View>
  75. );
  76. };