Pārlūkot izejas kodu

working json

the code in this commit works, but the website needs to be online

the json the website sends doesnt work with the current code
Orlando04 2 gadus atpakaļ
vecāks
revīzija
924947454b
3 mainītis faili ar 1898 papildinājumiem un 69 dzēšanām
  1. 37
    63
      MocionesIUPI/App.js
  2. 1852
    4
      MocionesIUPI/package-lock.json
  3. 9
    2
      MocionesIUPI/package.json

+ 37
- 63
MocionesIUPI/App.js Parādīt failu

@@ -1,66 +1,40 @@
1
-import React from 'react';
2
-import { StatusBar } from 'expo-status-bar';
3
-import { render } from 'react-dom';
4
-import { StyleSheet, Text, View, ActivityIndicator } from 'react-native';
5
-
6
-export default class App extends React.Component {
7
-  
8
-  contructor(props) {
9
-    super(props);
10
-
11
-    this.state = {
12
-      isLoading: true,
13
-      dataSource: null,
14
-    }
15
-  }
16
-  
17
-  componentDidMount() {
18
-
19
-    return fetch('https://facebook.github.io/react-native/movies.json')
20
-      .then ( (response) => response.json() )
21
-      .then ( (responseJson) => {
22
-
23
-        this.setState({
24
-          isLoading: false,
25
-          dataSource: responseJson.movies,
26
-        })
27
-
28
-      })
29
-
30
-      .catch((error) => {
31
-        console.log(error)
32
-
33
-      });
34
-  }
35
-
36
-  render() {
37
-
38
-    if (this.state.isLoading){
39
-
40
-      return(
41
-        <View style={style.container}>
42
-          <ActivityIndicator />
43
-        </View>
44
-      )
45
-    } 
46
-    
47
-    else {
48
-      
49
-      return (
50
-        <View style={styles.container}>
51
-          <Text>Open up App.js to start working on your app!</Text>
52
-          <StatusBar style="auto" />
53
-        </View>
54
-      );
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 [data, setData] = useState([]);
7
+
8
+  // this connects us to the API and fetches the json file with the mociones
9
+  const getMociones = async () => {
10
+     try {
11
+      const response = await fetch('http://127.0.0.1:5000/send?PIN=121071');
12
+      const json = await response.json();
13
+      setData(json.Description);
14
+    } catch (error) {
15
+      console.error(error);
16
+    } finally {
17
+      setLoading(false);
55 18
     }
56 19
   }
57
-}
58 20
 
59
-const styles = StyleSheet.create({
60
-  container: {
61
-    flex: 1,
62
-    backgroundColor: '#fff',
63
-    alignItems: 'center',
64
-    justifyContent: 'center',
65
-  },
66
-});
21
+  useEffect(() => {
22
+    getMociones();
23
+  }, []);
24
+
25
+  // here we want to display each mocion in a flatlist 
26
+  // it's supposed to be like buttons. Once clicked it would let you vote inside
27
+  return (
28
+    <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
+      )}
38
+    </View>
39
+  );
40
+};

+ 1852
- 4
MocionesIUPI/package-lock.json
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


+ 9
- 2
MocionesIUPI/package.json Parādīt failu

@@ -9,13 +9,20 @@
9 9
     "web": "expo start --web"
10 10
   },
11 11
   "dependencies": {
12
+    "@apollo/client": "^3.7.2",
13
+    "@expo/webpack-config": "^0.17.2",
12 14
     "expo": "~47.0.6",
13 15
     "expo-status-bar": "~1.4.2",
16
+    "graphql": "^15.8.0",
17
+    "native-base": "^3.4.25",
14 18
     "react": "18.1.0",
19
+    "react-dom": "18.1.0",
15 20
     "react-native": "0.70.5",
16 21
     "react-native-web": "~0.18.9",
17
-    "react-dom": "18.1.0",
18
-    "@expo/webpack-config": "^0.17.2"
22
+    "styled-components": "^5.3.6",
23
+    "styled-system": "^5.1.5",
24
+    "react-native-svg": "13.4.0",
25
+    "react-native-safe-area-context": "4.4.1"
19 26
   },
20 27
   "devDependencies": {
21 28
     "@babel/core": "^7.12.9"