123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- import React, { useEffect, useState } from 'react';
- import { ActivityIndicator, FlatList, Text, TouchableOpacity, View } from 'react-native';
- import { globalStyles } from '../styles/global';
-
- export default App = () => {
- const [isLoading, setLoading] = useState(true);
- const [Description, setDescription] = useState([]); // this is looking for 'Description' and it's content
- const [Mocion, setMocion] = useState([]); // this is looking for 'Mocion' and it's content
- const [PIN, setPIN] = useState([]); // this is looking for 'PIN' and it's content
- const [Votos, setVotos] = useState(0); // this is looking for 'Votos' and it's content
-
- // this connects us to the API and fetches the json file with the mociones
- const getMociones = async () => {
- try {
- const response = await fetch('http://10.190.1.140:5000/send?PIN=121071'); // connection to the website
- const json = await response.json();
-
- // setting the content of each category
- setMocion(json.Mocion);
- setDescription(json.Description);
- setPIN(json.PIN);
- setVotos(json.Votos);
-
- } catch (error) {
- console.error(error);
- } finally {
- setLoading(false); // once found the loading icon will be replaced with the content of the json
- }
- }
-
- function getVotoFavorNums() {
- const [countFavor, setCountFavor] = useState(0);
-
- return (
- <div>
- <button onClick={() => setCountFavor(countFavor + 1)}>
- A favor
- </button>
- </div>
- );
- }
-
- function getVotoContraNums() {
- const [countContra, setCountContra] = useState(0);
-
- return (
- <div>
- <button onClick={() => setCountContra(countContra + 1)}>
- En contra
- </button>
- </div>
- );
- }
-
- function getVotoAbstenidNums() {
- const [countAbstenid, setCountAbstenid] = useState(0);
-
- return (
- <div>
- <button onClick={() => setCountAbstenid(countAbstenid + 1)}>
- Abstenida/o
- </button>
- </div>
- );
- }
-
- function getVotoNums() {
- getVotoFavorNums();
- getVotoContraNums();
- getVotoAbstenidNums();
- }
-
- const getVotos = async () => {
- try {
- const response = await fetch('http://10.190.1.140:5000/send?PIN=121071'); // connection to the website
- const json = await response.json();
-
- // Getting votes count
- getVotoNums();
-
-
- } catch (error) {
- console.error(error);
- } finally {
- setLoading(false); // once found the loading icon will be replaced with the content of the json
- }
- }
- useEffect(() => {
- getMociones();
- getVotos();
- }, []);
-
- // this is for displaying the mocion, its description, and votes' options on the screen
- return (
- <View style={{ flex: 1, padding: 24 }}>
- <Text>{Mocion}</Text>
- <Text>{Description}</Text>
- <Button>
- title = "A favor"
- onPress={() => Alert.alert('Voto a favor')}
- </Button>
- <Button>
- title = "En contra"
- onPress={() => Alert.alert('Voto en contra')}
- </Button>
- <Button>
- title = "Abstenido"
- onPress={() => Alert.alert('Se abstuvo al voto')}
- </Button>
- </View>
- );
- };
|