2 İşlemeler

Yazar SHA1 Mesaj Tarih
  luislopez66 fa6790e4a7 Motion's votes' code added 2 yıl önce
  luislopez66 9737d1ff92 Added votes counts code 2 yıl önce

+ 1
- 1
MocionesIUPI/routes/homeStack.js Dosyayı Görüntüle

@@ -28,7 +28,7 @@ const screens = {
28 28
 
29 29
 const HomeStack = createStackNavigator(screens, {
30 30
     defaultNavigationOptions: {
31
-        title: 'MocinesIUPI',
31
+        title: 'MocionesIUPI',
32 32
         headerStyle:  { backgroundColor: "#e81b39",}
33 33
     }
34 34
 });

+ 51
- 0
MocionesIUPI/screens/MocionScreen.js Dosyayı Görüntüle

@@ -7,6 +7,7 @@ export default App = () => {
7 7
   const [Description, setDescription] = useState([]); // this is looking for 'Description' and it's content
8 8
   const [Mocion, setMocion] = useState([]); // this is looking for 'Mocion' and it's content
9 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 12
   // this connects us to the API and fetches the json file with the mociones
12 13
   const getMociones = async () => {
@@ -18,6 +19,7 @@ export default App = () => {
18 19
       setMocion(json.Mocion); 
19 20
       setDescription(json.Description);
20 21
       setPIN(json.PIN);
22
+      setVotos(json.Votos);
21 23
 
22 24
     } catch (error) {
23 25
       console.error(error);
@@ -26,8 +28,56 @@ export default App = () => {
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 78
   useEffect(() => {
30 79
     getMociones();
80
+    getVotos();
31 81
   }, []);
32 82
 
33 83
   // this is for displaying the mocion on the screen
@@ -35,6 +85,7 @@ export default App = () => {
35 85
     <View style={{ flex: 1, padding: 24 }}>
36 86
       <Text>{Mocion}</Text>
37 87
       <Text>{Description}</Text>
88
+      <Text>{Votos}</Text>
38 89
     </View>
39 90
   );
40 91
 };