Browse Source

Segundo intento

ErnestoOrtiz2 3 years ago
parent
commit
0c06620f6b
1 changed files with 30 additions and 13 deletions
  1. 30
    13
      screens/main/Home_page.js

+ 30
- 13
screens/main/Home_page.js View File

@@ -1,4 +1,3 @@
1
-
2 1
 import React, {useState, useEffect} from 'react'
3 2
 import { Button, Text, View, StyleSheet} from 'react-native'
4 3
 import {FlatList, ListViewBase } from 'react-native'
@@ -9,7 +8,6 @@ import firebase from 'firebase';
9 8
 import { styles } from "../../config/styles";
10 9
 import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground} from "react-native";
11 10
 
12
-
13 11
 import { connect } from 'react-redux'
14 12
 import { bindActionCreators } from 'redux' 
15 13
 import { fetchUser } from '../../redux/actions/index'
@@ -17,12 +15,14 @@ import { fetchUser } from '../../redux/actions/index'
17 15
 export function Home_page({navigation}) {
18 16
   const [threads, setThreads] = useState([]);  
19 17
   const [loading, setLoading] = useState(true);
18
+  
19
+  const [roomName, setRoomName] = useState('');
20 20
 
21 21
   useEffect(() => {
22 22
 
23 23
     const fire = firebase.firestore()
24 24
     .collection('THREADS')
25
-    
25
+    .where("members", "array-contains", firebase.auth().currentUser.uid)
26 26
     .onSnapshot(querySnapshot => {
27 27
       const threads = querySnapshot.docs.map(documentSnapshot => {
28 28
         return{
@@ -47,9 +47,24 @@ export function Home_page({navigation}) {
47 47
   if (loading) {
48 48
     return <Loading />;
49 49
   }
50
+
51
+
52
+  function handleButtonPress2() {
53
+      firebase.firestore()
54
+        .collection('THREADS')
55
+        .add({
56
+          name: 'NombreFecha',
57
+          members: [
58
+            firebase.auth().currentUser.uid,
59
+            'BhlrNDOqLOYSSlaEDK0nxZpQ2tD3'
60
+          ]
61
+        })
62
+        //.then(() => {
63
+          //navigation.navigate('allChats');
64
+         //});
65
+  }
50 66
   
51 67
   return (
52
-    <View>
53 68
     <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
54 69
         <FlatList
55 70
           data={threads}
@@ -63,7 +78,6 @@ export function Home_page({navigation}) {
63 78
             >
64 79
             <List.Item
65 80
               title={item.name}
66
-              description='Item description'
67 81
               titleNumberOfLines={1}
68 82
               titleStyle={styles.listTitle}
69 83
               descriptionStyle={styles.listDescription}
@@ -73,9 +87,16 @@ export function Home_page({navigation}) {
73 87
         )}
74 88
       />
75 89
 
90
+                <TextInput
91
+                    labelName='Room Name'
92
+                    placeholder="new chat room"
93
+                    onChangeText={(text) => setRoomName(text)}
94
+                    clearButtonMode='while-editing'
95
+                />
96
+
76 97
       <Button
77
-        title='Ver mensajes'
78
-        onPress={() => navigation.navigate('Add')}
98
+        title='CrearChat'
99
+        onPress={() => handleButtonPress2()}
79 100
       />
80 101
 
81 102
         <Button
@@ -83,16 +104,12 @@ export function Home_page({navigation}) {
83 104
         onPress= {() => navigation.navigate('Room')}
84 105
         />
85 106
         </ImageBackground>
86
-      </View>
87 107
     );
88 108
   }
89 109
 
90 110
 const mapStateToProps = (store) => ({
91 111
   currentUser: store.userState.currentUser
92 112
 })
93
-const mapDispatchProps = (dispatch) => bindActiontors({fetchUser}, dispatch);
94
-
95
-export default connect(mapStateToProps, mapDispatchProps)(Home_page);
96
-
97
-
113
+const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch);
98 114
 
115
+export default connect(mapStateToProps, mapDispatchProps)(Home_page);