Browse Source

Primeras modificaciones para implementar redux. Va a haber dos rutas.

ErnestoOrtiz2 3 years ago
parent
commit
6beb0778e5
6 changed files with 105 additions and 200 deletions
  1. 17
    20
      App.js
  2. 0
    92
      screens/Home_page.js
  3. 0
    0
      screens/auth/LoginScreen.js
  4. 0
    0
      screens/auth/RegisterScreen.js
  5. 88
    88
      screens/main/Home_page.js
  6. 0
    0
      screens/main/Loading.js

+ 17
- 20
App.js View File

@@ -1,17 +1,3 @@
1
-<<<<<<< HEAD
2
-import { StatusBar } from 'expo-status-bar';
3
-import React from 'react';
4
-import { StyleSheet, Text, View } from 'react-native';
5
-
6
-
7
-export default function App() {
8
-  return (
9
-    <View style={styles.container}>
10
-      <Text>"Hello world!"</Text>
11
-      <StatusBar style="auto" />
12
-    </View>
13
-  );
14
-=======
15 1
 import React, { Component } from 'react';
16 2
 import firebase from 'firebase'
17 3
 import { NavigationContainer } from '@react-navigation/native';
@@ -23,7 +9,11 @@ import { firebaseConfig } from './config/firebaseConfig';
23 9
 import { Text, View } from 'react-native';
24 10
 import { styles } from './config/styles';
25 11
 
26
-
12
+import HomeScreen from './screens/Home_page';
13
+import { Provider} from 'react-redux'
14
+import { createStore, applyMiddleware } from 'redux';
15
+import rootReducer from './redux/reducers'
16
+import thunk from 'redux-thunk'
27 17
 /*const seConfig = {
28 18
   apiKey: "AIzaSyDW-ABAQ3r_WR7C7WC_3VprL77NcAoitJI",
29 19
   authDomain: "freehand-d8ecd.firebaseapp.com",
@@ -37,12 +27,13 @@ import { styles } from './config/styles';
37 27
 //const app = firebase.initializeApp(seConfig);
38 28
 if (firebase.apps.length === 0) {
39 29
   firebase.initializeApp(firebaseConfig)
40
->>>>>>> master
41 30
 }
42 31
 
32
+const store = createStore(rootReducer, applyMiddleware(thunk));
33
+
43 34
 const Stack = createStackNavigator();
44 35
 
45
-export default class App extends Component {
36
+export class App extends Component {
46 37
   constructor(props){
47 38
     super(props);
48 39
     this.state = {
@@ -91,9 +82,15 @@ export default class App extends Component {
91 82
     }
92 83
 
93 84
     return(
94
-      <View style={styles.regcontainer}>
95
-        <Text>Cheese</Text>
96
-      </View>
85
+      <Provider store={store}>
86
+        <NavigationContainer>
87
+          <Stack.Navigator initialRouteName="Home">
88
+            <Stack.Screen name="HomeScreen" component={AddScreen} />
89
+          </Stack.Navigator>
90
+        </NavigationContainer>
91
+      </Provider>
97 92
     );
98 93
   }
99 94
 }
95
+
96
+

+ 0
- 92
screens/Home_page.js View File

@@ -1,92 +0,0 @@
1
-import React, {useState, useEffect} from 'react'
2
-import { Button, Text, View, StyleSheet} from 'react-native'
3
-import {FlatList, ListViewBase } from 'react-native'
4
-import {TouchableOpacity} from 'react-native-gesture-handler'
5
-import {List, Divider} from 'react-native-paper'
6
-import Loading from '../components/Loading'
7
-import firebase from 'firebase';
8
-
9
-
10
-export default function Home_page({navigation}) {
11
-  const [threads, setThreads] = useState([]);  
12
-  const [loading, setLoading] = useState(true);
13
-
14
-  useEffect(() => {
15
-
16
-    const fire = firebase.firestore()
17
-    .collection('THREADS')
18
-    
19
-    .onSnapshot(querySnapshot => {
20
-      const threads = querySnapshot.docs.map(documentSnapshot => {
21
-        return{
22
-          _id:documentSnapshot.id,
23
-          name:'',
24
-          ...documentSnapshot.data()
25
-        };
26
-
27
-      });
28
-
29
-      setThreads(threads);
30
-
31
-      if(loading){
32
-        setLoading(false);
33
-      }
34
-
35
-    });
36
-
37
-    return () => fire();
38
-  }, []);
39
-  
40
-  if (loading) {
41
-    return <Loading />;
42
-  }
43
-  
44
-  return (
45
-      <View style={styles.container}>
46
-        <FlatList
47
-          data={threads}
48
-          keyExtractor = {item => item._id}
49
-          ItemSeparatorComponent={() => <Divider />}
50
-          renderItem = {({item}) => (
51
-
52
-            <TouchableOpacity
53
-            onPress={() => navigation.navigate('Room', {thread: item})}
54
-            
55
-            >
56
-            <List.Item
57
-              title={item.name}
58
-              description='Item description'
59
-              titleNumberOfLines={1}
60
-              titleStyle={styles.listTitle}
61
-              descriptionStyle={styles.listDescription}
62
-              descriptionNumberOfLines={1}
63
-            />
64
-          </TouchableOpacity>
65
-        )}
66
-      />
67
-
68
-      <Button
69
-        title='Add Room'
70
-        onPress={() => navigation.navigate('Add')}
71
-      />
72
-
73
-        <Button
74
-        title ='Room'
75
-        onPress= {() => navigation.navigate('Room')}
76
-        />
77
-
78
-      </View>
79
-    );
80
-  }
81
-  const styles = StyleSheet.create({
82
-    container: {
83
-      backgroundColor: '#f5f5f5',
84
-      flex: 1
85
-    },
86
-    listTitle: {
87
-      fontSize: 22
88
-    },
89
-    listDescription: {
90
-      fontSize: 16
91
-    }
92
-  });

screens/LoginScreen.js → screens/auth/LoginScreen.js View File


screens/RegisterScreen.js → screens/auth/RegisterScreen.js View File


Home_page.js → screens/main/Home_page.js View File

@@ -1,88 +1,88 @@
1
-
2
-import React, {useState, useEffect} from 'react'
3
-import { Button, Text, View, StyleSheet} from 'react-native'
4
-import {FlatList, ListViewBase } from 'react-native'
5
-import {TouchableOpacity} from 'react-native-gesture-handler'
6
-import {List, Divider} from 'react-native-paper'
7
-import Loading from '../components/Loading'
8
-import firebase from 'firebase';
9
-import { styles } from "../config/styles";
10
-import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground} from "react-native";
11
-
12
-export default function Home_page({navigation}) {
13
-  const [threads, setThreads] = useState([]);  
14
-  const [loading, setLoading] = useState(true);
15
-
16
-  useEffect(() => {
17
-
18
-    const fire = firebase.firestore()
19
-    .collection('THREADS')
20
-    
21
-    .onSnapshot(querySnapshot => {
22
-      const threads = querySnapshot.docs.map(documentSnapshot => {
23
-        return{
24
-          _id:documentSnapshot.id,
25
-          name:'',
26
-          ...documentSnapshot.data()
27
-        };
28
-
29
-      });
30
-
31
-      setThreads(threads);
32
-
33
-      if(loading){
34
-        setLoading(false);
35
-      }
36
-
37
-    });
38
-
39
-    return () => fire();
40
-  }, []);
41
-  
42
-  if (loading) {
43
-    return <Loading />;
44
-  }
45
-  
46
-  return (
47
-    <View>
48
-    <ImageBackground style={styles.stdcontainer} source={require('../assets/yellow-white.jpg')}>
49
-        <FlatList
50
-          data={threads}
51
-          keyExtractor = {item => item._id}
52
-          ItemSeparatorComponent={() => <Divider />}
53
-          renderItem = {({item}) => (
54
-
55
-            <TouchableOpacity
56
-            onPress={() => navigation.navigate('Room', {thread: item})}
57
-            
58
-            >
59
-            <List.Item
60
-              title={item.name}
61
-              description='Item description'
62
-              titleNumberOfLines={1}
63
-              titleStyle={styles.listTitle}
64
-              descriptionStyle={styles.listDescription}
65
-              descriptionNumberOfLines={1}
66
-            />
67
-          </TouchableOpacity>
68
-        )}
69
-      />
70
-
71
-      <Button
72
-        title='Ver mensajes'
73
-        onPress={() => navigation.navigate('Add')}
74
-      />
75
-
76
-        <Button
77
-        title ='Hacer Busqueda'
78
-        onPress= {() => navigation.navigate('Room')}
79
-        />
80
-        </ImageBackground>
81
-      </View>
82
-    );
83
-  }
84
-
85
-
86
-
87
-
88
-
1
+
2
+import React, {useState, useEffect} from 'react'
3
+import { Button, Text, View, StyleSheet} from 'react-native'
4
+import {FlatList, ListViewBase } from 'react-native'
5
+import {TouchableOpacity} from 'react-native-gesture-handler'
6
+import {List, Divider} from 'react-native-paper'
7
+import Loading from '../components/Loading'
8
+import firebase from 'firebase';
9
+import { styles } from "../config/styles";
10
+import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground} from "react-native";
11
+
12
+export default function Home_page({navigation}) {
13
+  const [threads, setThreads] = useState([]);  
14
+  const [loading, setLoading] = useState(true);
15
+
16
+  useEffect(() => {
17
+
18
+    const fire = firebase.firestore()
19
+    .collection('THREADS')
20
+    
21
+    .onSnapshot(querySnapshot => {
22
+      const threads = querySnapshot.docs.map(documentSnapshot => {
23
+        return{
24
+          _id:documentSnapshot.id,
25
+          name:'',
26
+          ...documentSnapshot.data()
27
+        };
28
+
29
+      });
30
+
31
+      setThreads(threads);
32
+
33
+      if(loading){
34
+        setLoading(false);
35
+      }
36
+
37
+    });
38
+
39
+    return () => fire();
40
+  }, []);
41
+  
42
+  if (loading) {
43
+    return <Loading />;
44
+  }
45
+  
46
+  return (
47
+    <View>
48
+    <ImageBackground style={styles.stdcontainer} source={require('../assets/yellow-white.jpg')}>
49
+        <FlatList
50
+          data={threads}
51
+          keyExtractor = {item => item._id}
52
+          ItemSeparatorComponent={() => <Divider />}
53
+          renderItem = {({item}) => (
54
+
55
+            <TouchableOpacity
56
+            onPress={() => navigation.navigate('Room', {thread: item})}
57
+            
58
+            >
59
+            <List.Item
60
+              title={item.name}
61
+              description='Item description'
62
+              titleNumberOfLines={1}
63
+              titleStyle={styles.listTitle}
64
+              descriptionStyle={styles.listDescription}
65
+              descriptionNumberOfLines={1}
66
+            />
67
+          </TouchableOpacity>
68
+        )}
69
+      />
70
+
71
+      <Button
72
+        title='Ver mensajes'
73
+        onPress={() => navigation.navigate('Add')}
74
+      />
75
+
76
+        <Button
77
+        title ='Hacer Busqueda'
78
+        onPress= {() => navigation.navigate('Room')}
79
+        />
80
+        </ImageBackground>
81
+      </View>
82
+    );
83
+  }
84
+
85
+
86
+
87
+
88
+

Loading.js → screens/main/Loading.js View File