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
-
2
 import React, {useState, useEffect} from 'react'
1
 import React, {useState, useEffect} from 'react'
3
 import { Button, Text, View, StyleSheet} from 'react-native'
2
 import { Button, Text, View, StyleSheet} from 'react-native'
4
 import {FlatList, ListViewBase } from 'react-native'
3
 import {FlatList, ListViewBase } from 'react-native'
9
 import { styles } from "../../config/styles";
8
 import { styles } from "../../config/styles";
10
 import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground} from "react-native";
9
 import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground} from "react-native";
11
 
10
 
12
-
13
 import { connect } from 'react-redux'
11
 import { connect } from 'react-redux'
14
 import { bindActionCreators } from 'redux' 
12
 import { bindActionCreators } from 'redux' 
15
 import { fetchUser } from '../../redux/actions/index'
13
 import { fetchUser } from '../../redux/actions/index'
17
 export function Home_page({navigation}) {
15
 export function Home_page({navigation}) {
18
   const [threads, setThreads] = useState([]);  
16
   const [threads, setThreads] = useState([]);  
19
   const [loading, setLoading] = useState(true);
17
   const [loading, setLoading] = useState(true);
18
+  
19
+  const [roomName, setRoomName] = useState('');
20
 
20
 
21
   useEffect(() => {
21
   useEffect(() => {
22
 
22
 
23
     const fire = firebase.firestore()
23
     const fire = firebase.firestore()
24
     .collection('THREADS')
24
     .collection('THREADS')
25
-    
25
+    .where("members", "array-contains", firebase.auth().currentUser.uid)
26
     .onSnapshot(querySnapshot => {
26
     .onSnapshot(querySnapshot => {
27
       const threads = querySnapshot.docs.map(documentSnapshot => {
27
       const threads = querySnapshot.docs.map(documentSnapshot => {
28
         return{
28
         return{
47
   if (loading) {
47
   if (loading) {
48
     return <Loading />;
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
   return (
67
   return (
52
-    <View>
53
     <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
68
     <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
54
         <FlatList
69
         <FlatList
55
           data={threads}
70
           data={threads}
63
             >
78
             >
64
             <List.Item
79
             <List.Item
65
               title={item.name}
80
               title={item.name}
66
-              description='Item description'
67
               titleNumberOfLines={1}
81
               titleNumberOfLines={1}
68
               titleStyle={styles.listTitle}
82
               titleStyle={styles.listTitle}
69
               descriptionStyle={styles.listDescription}
83
               descriptionStyle={styles.listDescription}
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
       <Button
97
       <Button
77
-        title='Ver mensajes'
78
-        onPress={() => navigation.navigate('Add')}
98
+        title='CrearChat'
99
+        onPress={() => handleButtonPress2()}
79
       />
100
       />
80
 
101
 
81
         <Button
102
         <Button
83
         onPress= {() => navigation.navigate('Room')}
104
         onPress= {() => navigation.navigate('Room')}
84
         />
105
         />
85
         </ImageBackground>
106
         </ImageBackground>
86
-      </View>
87
     );
107
     );
88
   }
108
   }
89
 
109
 
90
 const mapStateToProps = (store) => ({
110
 const mapStateToProps = (store) => ({
91
   currentUser: store.userState.currentUser
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);