Browse Source

volvemos a la normalidad

acuerdense de cambiar su IPaddr en la parte de fetch
Orlando04 2 years ago
parent
commit
fbeb7e64c4

+ 8
- 0
MocionesIUPI/routes/homeStack.js View File

4
 
4
 
5
 import HomeScreen from '../screens/HomeScreen';
5
 import HomeScreen from '../screens/HomeScreen';
6
 import MocionScreen from '../screens/MocionScreen';
6
 import MocionScreen from '../screens/MocionScreen';
7
+import PincodeScreen from '../screens/PincodeScreen';
7
 import Header from '../shared/header';
8
 import Header from '../shared/header';
8
 
9
 
9
 {/*Aqui deberan estar todas las pantallas de la aplicacion
10
 {/*Aqui deberan estar todas las pantallas de la aplicacion
15
            headerTitle: () => <Header />
16
            headerTitle: () => <Header />
16
         }
17
         }
17
     },
18
     },
19
+    
20
+    Pinpage: {
21
+        screen: PincodeScreen,
22
+        navigationOptions: {
23
+            headerTitle: () => <Header />
24
+        }
25
+    },
18
 
26
 
19
     Mocion: {
27
     Mocion: {
20
         screen: MocionScreen,
28
         screen: MocionScreen,

+ 3
- 4
MocionesIUPI/screens/HomeScreen.js View File

17
   
17
   
18
       } catch (error) {
18
       } catch (error) {
19
         console.error(error);
19
         console.error(error);
20
-      } finally {
21
-        setLoading(false); // once found the loading icon will be replaced with the content of the json
22
-      }
20
+      } 
21
+      
23
     }
22
     }
24
 
23
 
25
     const pressHandler = () => {
24
     const pressHandler = () => {
26
-        navigation.navigate('Mocion');
25
+        navigation.navigate('Pinpage', {Pin:PIN});
27
     }
26
     }
28
     
27
     
29
     useEffect(() => {
28
     useEffect(() => {

+ 55
- 32
MocionesIUPI/screens/MocionScreen.js View File

1
 import React, { useEffect, useState } from 'react';
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
 export default App = () => {
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
   return (
47
   return (
34
     <View style={{ flex: 1, padding: 24 }}>
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
     </View>
62
     </View>
40
   );
63
   );
41
 };
64
 };