Kaynağa Gözat

votos are complete

Orlando04 2 yıl önce
ebeveyn
işleme
ba3882836f
1 değiştirilmiş dosya ile 24 ekleme ve 17 silme
  1. 24
    17
      MocionesIUPI/App.js

+ 24
- 17
MocionesIUPI/App.js Dosyayı Görüntüle

@@ -3,9 +3,10 @@ import { ActivityIndicator, Button, FlatList, Text, View } from 'react-native';
3 3
 
4 4
 export default App = () => {
5 5
   const [isLoading, setLoading] = useState(true);
6
-  const[json, setJson] = useState(null);
7
-  const [mocion, setMocion] = useState([]);
8
-  const [description, setDescription] = useState([]);
6
+  const [mocion, setMocion] = useState(null);
7
+  const [description, setDescription] = useState(null);
8
+  const [pin, setPIN] = useState(null);
9
+  const [response, setResponse] = useState(null);
9 10
 
10 11
   // this connects us to the API and fetches the json file with the mociones
11 12
   const getMociones = async () => {
@@ -14,6 +15,7 @@ export default App = () => {
14 15
       const json = await response.json();
15 16
       setMocion(json.Mocion);
16 17
       setDescription(json.Description);
18
+      setPIN(json.PIN);
17 19
     } catch (error) {
18 20
       console.error(error);
19 21
     } finally {
@@ -26,18 +28,20 @@ export default App = () => {
26 28
   }, []);
27 29
 
28 30
   // this recieves the value of the button pressed and sends it to the api 
29
-  const sendVotos = (value) => {
31
+  const sendVotes = (value) => {
30 32
     console.log(value); // testing that we recied the value
31 33
 
32
-    //adding new values to json
33
-    fetch('http://10.190.1.140:5000', {
34
-      method: 'POST',
35
-      body: JSON.stringify(json),
36
-      headers: {
37
-        'Accept': 'application/json',
38
-        'Content-Type': 'application/json'
39
-      },
40
-    });
34
+    //sending to the API
35
+    const PIN = pin;
36
+    const Token = 'abc123'
37
+    const votos = value;
38
+
39
+    const url = `http://10.190.1.140:5000/vote?PIN=${PIN}&Token=${Token}&votos=${votos}`;
40
+
41
+    //connecting to API
42
+    fetch(url)
43
+
44
+    console.log(response);
41 45
   };
42 46
 
43 47
   // here we want to display each mocion in a flatlist 
@@ -48,10 +52,13 @@ export default App = () => {
48 52
       <Text>{description}</Text>
49 53
       
50 54
       {/* container for the look of the buttons */}
51
-      <View >
52
-      <Button title='A favor' onPress={() => sendVotos('A Favor')} />
53
-      <Button title='En Contra'onPress={() => sendVotos('En Contra')} />
54
-      <Button title='Abstenido/a' onPress={() => sendVotos('Abstenido/a')} />
55
+      <View>
56
+
57
+      <Button title='A favor' onPress={() => sendVotes('A Favor')} />
58
+      <Button title='En Contra'onPress={() => sendVotes('En Contra')} />
59
+      <Button title='Abstenido/a' onPress={() => sendVotes('Abstenido/a')} />
60
+
61
+
55 62
       </View>
56 63
 
57 64
     </View>