Browse Source

Added votes counts code

luislopez66 2 years ago
parent
commit
9737d1ff92
1 changed files with 51 additions and 0 deletions
  1. 51
    0
      MocionesIUPI/screens/MocionScreen.js

+ 51
- 0
MocionesIUPI/screens/MocionScreen.js View File

7
   const [Description, setDescription] = useState([]); // this is looking for 'Description' and it's content
7
   const [Description, setDescription] = useState([]); // this is looking for 'Description' and it's content
8
   const [Mocion, setMocion] = useState([]); // this is looking for 'Mocion' and it's content
8
   const [Mocion, setMocion] = useState([]); // this is looking for 'Mocion' and it's content
9
   const [PIN, setPIN] = useState([]); // this is looking for 'PIN' and it's content
9
   const [PIN, setPIN] = useState([]); // this is looking for 'PIN' and it's content
10
+  const [Votos, setVotos] = useState(0); // this is looking for 'Votos' and it's content
10
 
11
 
11
   // this connects us to the API and fetches the json file with the mociones
12
   // this connects us to the API and fetches the json file with the mociones
12
   const getMociones = async () => {
13
   const getMociones = async () => {
18
       setMocion(json.Mocion); 
19
       setMocion(json.Mocion); 
19
       setDescription(json.Description);
20
       setDescription(json.Description);
20
       setPIN(json.PIN);
21
       setPIN(json.PIN);
22
+      setVotos(json.Votos);
21
 
23
 
22
     } catch (error) {
24
     } catch (error) {
23
       console.error(error);
25
       console.error(error);
26
     }
28
     }
27
   }
29
   }
28
 
30
 
31
+  function getVotoNums() {
32
+    const [countFavor, setcountFavor] = useState(0);
33
+
34
+    return (
35
+      <div>
36
+        <button onClick={() => setCountFavor(countFavor + 1)}>
37
+        A favor
38
+        </button>
39
+      </div>
40
+    );
41
+
42
+    const [countContra, setCountContra] = useState(0);
43
+
44
+    return (
45
+      <div>
46
+        <button onClick={() => setCountContra(countContra + 1)}>
47
+        En contra
48
+        </button>
49
+      </div>
50
+    );
51
+
52
+    const [countAbstenid, setCountAbstenid] = useState(0);
53
+
54
+    return (
55
+      <div>
56
+        <button onClick={() => setCountAbstenid(countAbstenid + 1)}>
57
+        Abstenida/o
58
+        </button>
59
+      </div>
60
+    );
61
+  }
62
+
63
+  const getVotos = async () => {
64
+    try {
65
+      const response = await fetch('http://10.190.1.140:5000/send?PIN=121071'); // connection to the website 
66
+      const json = await response.json();
67
+
68
+      // Getting votes count
69
+      getVotoNums();
70
+
71
+
72
+    } catch (error) {
73
+      console.error(error);
74
+    } finally {
75
+      setLoading(false); // once found the loading icon will be replaced with the content of the json
76
+    }
77
+  }
29
   useEffect(() => {
78
   useEffect(() => {
30
     getMociones();
79
     getMociones();
80
+    getVotos();
31
   }, []);
81
   }, []);
32
 
82
 
33
   // this is for displaying the mocion on the screen
83
   // this is for displaying the mocion on the screen
35
     <View style={{ flex: 1, padding: 24 }}>
85
     <View style={{ flex: 1, padding: 24 }}>
36
       <Text>{Mocion}</Text>
86
       <Text>{Mocion}</Text>
37
       <Text>{Description}</Text>
87
       <Text>{Description}</Text>
88
+      <Text>{Votos}</Text>
38
     </View>
89
     </View>
39
   );
90
   );
40
 };
91
 };