Browse Source

votos are complete

Orlando04 2 years ago
parent
commit
ba3882836f
1 changed files with 24 additions and 17 deletions
  1. 24
    17
      MocionesIUPI/App.js

+ 24
- 17
MocionesIUPI/App.js View File

3
 
3
 
4
 export default App = () => {
4
 export default App = () => {
5
   const [isLoading, setLoading] = useState(true);
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
   // this connects us to the API and fetches the json file with the mociones
11
   // this connects us to the API and fetches the json file with the mociones
11
   const getMociones = async () => {
12
   const getMociones = async () => {
14
       const json = await response.json();
15
       const json = await response.json();
15
       setMocion(json.Mocion);
16
       setMocion(json.Mocion);
16
       setDescription(json.Description);
17
       setDescription(json.Description);
18
+      setPIN(json.PIN);
17
     } catch (error) {
19
     } catch (error) {
18
       console.error(error);
20
       console.error(error);
19
     } finally {
21
     } finally {
26
   }, []);
28
   }, []);
27
 
29
 
28
   // this recieves the value of the button pressed and sends it to the api 
30
   // this recieves the value of the button pressed and sends it to the api 
29
-  const sendVotos = (value) => {
31
+  const sendVotes = (value) => {
30
     console.log(value); // testing that we recied the value
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
   // here we want to display each mocion in a flatlist 
47
   // here we want to display each mocion in a flatlist 
48
       <Text>{description}</Text>
52
       <Text>{description}</Text>
49
       
53
       
50
       {/* container for the look of the buttons */}
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
       </View>
62
       </View>
56
 
63
 
57
     </View>
64
     </View>