Без опису

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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[json, setJson] = useState(null);
  6. const [mocion, setMocion] = useState([]);
  7. const [description, setDescription] = useState([]);
  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.190.1.140:5000/send?PIN=121071');
  12. const json = await response.json();
  13. setMocion(json.Mocion);
  14. setDescription(json.Description);
  15. } catch (error) {
  16. console.error(error);
  17. } finally {
  18. setLoading(false);
  19. }
  20. }
  21. useEffect(() => {
  22. getMociones();
  23. }, []);
  24. // this recieves the value of the button pressed and sends it to the api
  25. const sendVotos = (value) => {
  26. console.log(value); // testing that we recied the value
  27. //adding new values to json
  28. fetch('http://10.190.1.140:5000', {
  29. method: 'POST',
  30. body: JSON.stringify(json),
  31. headers: {
  32. 'Accept': 'application/json',
  33. 'Content-Type': 'application/json'
  34. },
  35. });
  36. };
  37. // here we want to display each mocion in a flatlist
  38. // it's supposed to be like buttons. Once clicked it would let you vote inside
  39. return (
  40. <View style={{ flex: 1, padding: 24 }}>
  41. <Text>{mocion}</Text>
  42. <Text>{description}</Text>
  43. {/* container for the look of the buttons */}
  44. <View >
  45. <Button title='A favor' onPress={() => sendVotos('A Favor')} />
  46. <Button title='En Contra'onPress={() => sendVotos('En Contra')} />
  47. <Button title='Abstenido/a' onPress={() => sendVotos('Abstenido/a')} />
  48. </View>
  49. </View>
  50. );
  51. };