Açıklama Yok

App.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React, { useEffect, useState } from 'react';
  2. import { ActivityIndicator, Button, FlatList, Text, View } from 'react-native';
  3. export default App = () => {
  4. const [isLoading, setLoading] = useState(true);
  5. const [mocion, setMocion] = useState(null);
  6. const [description, setDescription] = useState(null);
  7. const [pin, setPIN] = useState(null);
  8. const [response, setResponse] = useState(null);
  9. // this connects us to the API and fetches the json file with the mociones
  10. const getMociones = async () => {
  11. try {
  12. const response = await fetch('http://10.190.1.140:5000/send?PIN=121071');
  13. const json = await response.json();
  14. setMocion(json.Mocion);
  15. setDescription(json.Description);
  16. setPIN(json.PIN);
  17. } catch (error) {
  18. console.error(error);
  19. } finally {
  20. setLoading(false);
  21. }
  22. }
  23. useEffect(() => {
  24. getMociones();
  25. }, []);
  26. // this recieves the value of the button pressed and sends it to the api
  27. const sendVotes = (value) => {
  28. console.log(value); // testing that we recied the value
  29. //sending to the API
  30. const PIN = pin;
  31. const Token = 'abc123'
  32. const votos = value;
  33. const url = `http://10.190.1.140:5000/vote?PIN=${PIN}&Token=${Token}&votos=${votos}`;
  34. //connecting to API
  35. fetch(url)
  36. console.log(response);
  37. };
  38. // here we want to display each mocion in a flatlist
  39. // it's supposed to be like buttons. Once clicked it would let you vote inside
  40. return (
  41. <View style={{ flex: 1, padding: 24 }}>
  42. <Text>{mocion}</Text>
  43. <Text>{description}</Text>
  44. {/* container for the look of the buttons */}
  45. <View>
  46. <Button title='A favor' onPress={() => sendVotes('A Favor')} />
  47. <Button title='En Contra'onPress={() => sendVotes('En Contra')} />
  48. <Button title='Abstenido/a' onPress={() => sendVotes('Abstenido/a')} />
  49. </View>
  50. </View>
  51. );
  52. };