Orlando04 před 2 roky
rodič
revize
271e139a22

+ 32
- 13
MocionesIUPI/App.js Zobrazit soubor

@@ -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
 };

+ 43
- 0
MocionesIUPI/screens/HomeScreen.js Zobrazit soubor

@@ -0,0 +1,43 @@
1
+import { propertiesListToString } from "@expo/config-plugins/build/android/Properties";
2
+import React, { useEffect, useState }from "react";
3
+import { StyleSheet, View, Text, Button } from 'react-native';
4
+import { globalStyles } from "../styles/global";
5
+
6
+export default App = ({ navigation }) => {
7
+    const [PIN, setPIN] = useState([]); // this is looking for 'PIN' and it's content
8
+  
9
+    // this connects us to the API and fetches the json file with the mociones
10
+    const getMociones = async () => {
11
+       try {
12
+        const response = await fetch('http://10.190.1.140:5000/send?PIN=613382'); // connection to the website 
13
+        const json = await response.json();
14
+  
15
+        // setting the content of each category 
16
+        setPIN(json.PIN);
17
+  
18
+      } catch (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
+      }
23
+    }
24
+
25
+    const pressHandler = () => {
26
+        navigation.navigate('Pinpage', {Pin:PIN},) // with this we send parameters to other screens
27
+    }
28
+    
29
+    useEffect(() => {
30
+        getMociones();
31
+      }, []);
32
+
33
+    return (
34
+        <View style = {globalStyles.container}>
35
+            <Text style = {globalStyles.tittleText}>Home Screen</Text>
36
+            <Button title='Ir a pagina de pin' color={'#e81b39'} onPress={pressHandler} />
37
+        </View>
38
+
39
+        
40
+        
41
+
42
+    )
43
+}

+ 25
- 22
MocionesIUPI/screens/MocionScreen.js Zobrazit soubor

@@ -5,25 +5,22 @@ export default App = () => {
5 5
   const [isLoading, setLoading] = useState(true);
6 6
   const [Description, setDescription] = useState([]); // this is looking for 'Description' and it's content
7 7
   const [Mocion, setMocion] = useState([]); // this is looking for 'Mocion' and it's content
8
-  const [PIN, setPIN] = useState([]); // this is looking for 'PIN' and it's content
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'); // connection to the website 
14
-      const json = await response.json();
15
-
16
-      // setting the content of each category 
17
-      setMocion(json.Mocion); 
18
-      setDescription(json.Description);
19
-      setPIN(json.PIN);
20
-
21
-    } catch (error) {
22
-      console.error(error);
23
-    } finally {
24
-      setLoading(false); // once found the loading icon will be replaced with the content of the json
25
-    }
26
-  }
8
+  
9
+      // this connects us to the API and fetches the json file with the mociones
10
+      const getMociones = async () => {
11
+        try {
12
+         const response = await fetch('http://10.190.1.140:5000/send?PIN=613382'); // connection to the website 
13
+         const json = await response.json();
14
+   
15
+         // setting the content of each category 
16
+         setMocion(json.Mocion); 
17
+         setDescription(json.Description);
18
+       } catch (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
+       }
23
+     }
27 24
 
28 25
   useEffect(() => {
29 26
     getMociones();
@@ -33,9 +30,15 @@ export default App = () => {
33 30
   // it's supposed to be like buttons. Once clicked it would let you vote inside
34 31
   return (
35 32
     <View style={{ flex: 1, padding: 24 }}>
36
-      <Text>{Mocion}</Text>
37
-      <Text>{Description}</Text>
38
-      <Text>{PIN}</Text>
33
+      {isLoading ? <ActivityIndicator/> : (
34
+        <FlatList
35
+          data={data}
36
+          keyExtractor={({ id }, index) => id}
37
+          renderItem={({ item }) => (
38
+            <Text>{data}</Text>
39
+          )}
40
+        />
41
+      )}
39 42
     </View>
40 43
   );
41 44
 };