Explorar el Código

Create MocionScreen.js

this is going to be merged
Orlando04 hace 2 años
padre
commit
c51876b8fa
Se han modificado 1 ficheros con 41 adiciones y 0 borrados
  1. 41
    0
      MocionesIUPI/screens/MocionScreen.js

+ 41
- 0
MocionesIUPI/screens/MocionScreen.js Ver fichero

@@ -0,0 +1,41 @@
1
+import React, { useEffect, useState } from 'react';
2
+import { ActivityIndicator, FlatList, Text, View } from 'react-native';
3
+
4
+export default App = () => {
5
+  const [isLoading, setLoading] = useState(true);
6
+  const [Description, setDescription] = useState([]); // this is looking for 'Description' and it's content
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
+  }
27
+
28
+  useEffect(() => {
29
+    getMociones();
30
+  }, []);
31
+
32
+  // here we want to display each mocion in a flatlist 
33
+  // it's supposed to be like buttons. Once clicked it would let you vote inside
34
+  return (
35
+    <View style={{ flex: 1, padding: 24 }}>
36
+      <Text>{Mocion}</Text>
37
+      <Text>{Description}</Text>
38
+      <Text>{PIN}</Text>
39
+    </View>
40
+  );
41
+};