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