|
@@ -1,16 +1,19 @@
|
1
|
1
|
import React, { useEffect, useState } from 'react';
|
2
|
|
-import { ActivityIndicator, FlatList, Text, View } from 'react-native';
|
|
2
|
+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 [data, setData] = useState([]);
|
|
6
|
+ const[json, setJson] = useState(null);
|
|
7
|
+ const [mocion, setMocion] = useState([]);
|
|
8
|
+ const [description, setDescription] = useState([]);
|
7
|
9
|
|
8
|
10
|
// this connects us to the API and fetches the json file with the mociones
|
9
|
11
|
const getMociones = async () => {
|
10
|
12
|
try {
|
11
|
|
- const response = await fetch('http://127.0.0.1:5000/send?PIN=121071');
|
|
13
|
+ const response = await fetch('http://10.190.1.140:5000/send?PIN=121071');
|
12
|
14
|
const json = await response.json();
|
13
|
|
- setData(json.Description);
|
|
15
|
+ setMocion(json.Mocion);
|
|
16
|
+ setDescription(json.Description);
|
14
|
17
|
} catch (error) {
|
15
|
18
|
console.error(error);
|
16
|
19
|
} finally {
|
|
@@ -22,19 +25,35 @@ export default App = () => {
|
22
|
25
|
getMociones();
|
23
|
26
|
}, []);
|
24
|
27
|
|
|
28
|
+ // this recieves the value of the button pressed and sends it to the api
|
|
29
|
+ const sendVotos = (value) => {
|
|
30
|
+ console.log(value); // testing that we recied the value
|
|
31
|
+
|
|
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
|
+ });
|
|
41
|
+ };
|
|
42
|
+
|
25
|
43
|
// here we want to display each mocion in a flatlist
|
26
|
44
|
// it's supposed to be like buttons. Once clicked it would let you vote inside
|
27
|
45
|
return (
|
28
|
46
|
<View style={{ flex: 1, padding: 24 }}>
|
29
|
|
- {isLoading ? <ActivityIndicator/> : (
|
30
|
|
- <FlatList
|
31
|
|
- data={data}
|
32
|
|
- keyExtractor={({ id }, index) => id}
|
33
|
|
- renderItem={({ item }) => (
|
34
|
|
- <Text>{data}</Text>
|
35
|
|
- )}
|
36
|
|
- />
|
37
|
|
- )}
|
|
47
|
+ <Text>{mocion}</Text>
|
|
48
|
+ <Text>{description}</Text>
|
|
49
|
+
|
|
50
|
+ {/* 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
|
+
|
38
|
57
|
</View>
|
39
|
58
|
);
|
40
|
59
|
};
|