No Description

MocionScreen.js 1.9KB

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