|
@@ -1,41 +1,64 @@
|
1
|
1
|
import React, { useEffect, useState } from 'react';
|
2
|
|
-import { ActivityIndicator, Button, FlatList, Text, TouchableOpacity, View } from 'react-native';
|
3
|
|
-import { globalStyles } from '../styles/global';
|
4
|
|
-import Card from '../shared/card';
|
|
2
|
+import { ActivityIndicator, Button, FlatList, Text, View } from 'react-native';
|
5
|
3
|
|
6
|
4
|
export default App = () => {
|
7
|
|
- const [isLoading, setLoading] = useState(true);
|
8
|
|
- const [Description, setDescription] = useState([]); // this is looking for 'Description' and it's content
|
9
|
|
- const [Mocion, setMocion] = useState([]); // this is looking for 'Mocion' and it's content
|
10
|
|
-
|
11
|
|
- // this connects us to the API and fetches the json file with the mociones
|
12
|
|
- const getMociones = async () => {
|
13
|
|
- try {
|
14
|
|
- const response = await fetch('http://192.168.1.200:5000/send?PIN=613382'); // connection to the website
|
15
|
|
- const json = await response.json();
|
16
|
|
-
|
17
|
|
- // setting the content of each category
|
18
|
|
- setMocion(json.Mocion);
|
19
|
|
- setDescription(json.Description);
|
20
|
|
- } catch (error) {
|
21
|
|
- console.error(error);
|
22
|
|
- } finally {
|
23
|
|
- setLoading(false); // once found the loading icon will be replaced with the content of the json
|
24
|
|
- }
|
25
|
|
- }
|
26
|
|
-
|
27
|
|
- useEffect(() => {
|
28
|
|
- getMociones();
|
29
|
|
- }, []);
|
30
|
|
-
|
31
|
|
-
|
32
|
|
- // this is for displaying the mocion on the screen
|
|
5
|
+ const [mocion, setMocion] = useState(null);
|
|
6
|
+ const [description, setDescription] = useState(null);
|
|
7
|
+ const [pin, setPIN] = useState(null);
|
|
8
|
+ const [response, setResponse] = useState(null);
|
|
9
|
+
|
|
10
|
+ // this connects us to the API and fetches the json file with the mociones
|
|
11
|
+ const getMociones = async () => {
|
|
12
|
+ try {
|
|
13
|
+ const response = await fetch('http://10.190.1.140:5000/send?PIN=121071');
|
|
14
|
+ const json = await response.json();
|
|
15
|
+ setMocion(json.Mocion);
|
|
16
|
+ setDescription(json.Description);
|
|
17
|
+ setPIN(json.PIN);
|
|
18
|
+ } catch (error) {
|
|
19
|
+ console.error(error);
|
|
20
|
+ }
|
|
21
|
+
|
|
22
|
+ }
|
|
23
|
+
|
|
24
|
+ useEffect(() => {
|
|
25
|
+ getMociones();
|
|
26
|
+ }, []);
|
|
27
|
+
|
|
28
|
+ // this recieves the value of the button pressed and sends it to the api
|
|
29
|
+ const sendVotes = (value) => {
|
|
30
|
+ console.log(value); // testing that we recied the value
|
|
31
|
+
|
|
32
|
+ //sending to the API
|
|
33
|
+ const PIN = pin;
|
|
34
|
+ const Token = 'abc123';
|
|
35
|
+ const votos = value;
|
|
36
|
+
|
|
37
|
+ const url = `http://10.190.1.140:5000/vote?PIN=${PIN}&Token=${Token}&votos=${votos}`;
|
|
38
|
+
|
|
39
|
+ //connecting to API
|
|
40
|
+ fetch(url);
|
|
41
|
+
|
|
42
|
+ console.log(response);
|
|
43
|
+ };
|
|
44
|
+
|
|
45
|
+ // here we want to display each mocion in a flatlist
|
|
46
|
+ // it's supposed to be like buttons. Once clicked it would let you vote inside
|
33
|
47
|
return (
|
34
|
48
|
<View style={{ flex: 1, padding: 24 }}>
|
|
49
|
+ <Text>{mocion}</Text>
|
|
50
|
+ <Text>{description}</Text>
|
|
51
|
+
|
|
52
|
+ {/* container for the look of the buttons */}
|
|
53
|
+ <View>
|
|
54
|
+
|
|
55
|
+ <Button title='A favor' onPress={() => sendVotes('A Favor')} />
|
|
56
|
+ <Button title='En Contra'onPress={() => sendVotes('En Contra')} />
|
|
57
|
+ <Button title='Abstenido/a' onPress={() => sendVotes('Abstenido/a')} />
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+ </View>
|
35
|
61
|
|
36
|
|
- <Text>{Mocion}</Text>
|
37
|
|
- <Text>{Description}</Text>
|
38
|
|
- <Button title= 'A favor' color={'#e81b39'} />
|
39
|
62
|
</View>
|
40
|
63
|
);
|
41
|
64
|
};
|