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 (
); } function getVotoContraNums() { const [countContra, setCountContra] = useState(0); return (
); } function getVotoAbstenidNums() { const [countAbstenid, setCountAbstenid] = useState(0); return (
); } 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 ( {Mocion} {Description} ); };