Browse Source

Files temporeros para llegar a los chats exclusivos a dos usuarios.

ErnestoOrtiz2 3 years ago
parent
commit
19c619d39c
2 changed files with 18 additions and 96 deletions
  1. 16
    23
      screens/main/Home_page.js
  2. 2
    73
      screens/main/RoomScreen.js

+ 16
- 23
screens/main/Home_page.js View File

49
   }
49
   }
50
 
50
 
51
 
51
 
52
-  function handleButtonPress2() {
52
+  function handleButtonPress() {
53
       firebase.firestore()
53
       firebase.firestore()
54
         .collection('THREADS')
54
         .collection('THREADS')
55
         .add({
55
         .add({
56
-          name: 'NombreFecha',
56
+          name: 'PedroFecha',
57
           members: [
57
           members: [
58
             firebase.auth().currentUser.uid,
58
             firebase.auth().currentUser.uid,
59
-            'BhlrNDOqLOYSSlaEDK0nxZpQ2tD3'
59
+            '02yOZHxFcGUX4MNwjeEbAlCShdu1'
60
           ]
60
           ]
61
         })
61
         })
62
         //.then(() => {
62
         //.then(() => {
63
           //navigation.navigate('allChats');
63
           //navigation.navigate('allChats');
64
          //});
64
          //});
65
   }
65
   }
66
-  
66
+
67
   return (
67
   return (
68
-    <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
68
+      <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
69
         <FlatList
69
         <FlatList
70
           data={threads}
70
           data={threads}
71
           keyExtractor = {item => item._id}
71
           keyExtractor = {item => item._id}
72
           ItemSeparatorComponent={() => <Divider />}
72
           ItemSeparatorComponent={() => <Divider />}
73
           renderItem = {({item}) => (
73
           renderItem = {({item}) => (
74
-
75
-            <TouchableOpacity
74
+          <TouchableOpacity
76
             onPress={() => navigation.navigate('Room', {thread: item})}
75
             onPress={() => navigation.navigate('Room', {thread: item})}
77
-            
78
-            >
76
+          >
79
             <List.Item
77
             <List.Item
80
               title={item.name}
78
               title={item.name}
81
               titleNumberOfLines={1}
79
               titleNumberOfLines={1}
85
             />
83
             />
86
           </TouchableOpacity>
84
           </TouchableOpacity>
87
         )}
85
         )}
88
-      />
89
-
90
-                <TextInput
91
-                    labelName='Room Name'
92
-                    placeholder="new chat room"
93
-                    onChangeText={(text) => setRoomName(text)}
94
-                    clearButtonMode='while-editing'
95
-                />
96
-
86
+        />
87
+      <Button
88
+        title='Calendario'
89
+        onPress={() => navigation.navigate('Calendar')}
90
+      />  
97
       <Button
91
       <Button
98
         title='CrearChat'
92
         title='CrearChat'
99
-        onPress={() => handleButtonPress2()}
93
+        onPress={() => handleButtonPress()}
100
       />
94
       />
101
-
102
-        <Button
95
+      <Button
103
         title ='Hacer Busqueda'
96
         title ='Hacer Busqueda'
104
-        onPress= {() => navigation.navigate('Room')}
105
-        />
97
+        onPress= {() => navigation.navigate('Busqueda')}
98
+      />
106
         </ImageBackground>
99
         </ImageBackground>
107
     );
100
     );
108
   }
101
   }

+ 2
- 73
screens/main/RoomScreen.js View File

1
+
1
 import React, { useState, useEffect, useCallback } from 'react';
2
 import React, { useState, useEffect, useCallback } from 'react';
2
 import { GiftedChat } from 'react-native-gifted-chat';
3
 import { GiftedChat } from 'react-native-gifted-chat';
3
 import firebase from 'firebase';
4
 import firebase from 'firebase';
6
 import { fetchUser } from '../../redux/actions/index'
7
 import { fetchUser } from '../../redux/actions/index'
7
 
8
 
8
 export function RoomScreen({ route }) {
9
 export function RoomScreen({ route }) {
9
-  //const { currentUser } = props;
10
   const { thread } = route.params;
10
   const { thread } = route.params;
11
-  /*const [messages, setMessages] = useState([
12
-    /**
13
-     * Mock message data
14
-     */
15
-    // example of system message
16
-   /* {
17
-      _id: 0,
18
-      text: 'New room created.',
19
-      createdAt: new Date().getTime(),
20
-      system: true
21
-    },
22
-    // example of chat message
23
-    {
24
-      _id: 1,
25
-      text: 'Henlo!',
26
-      createdAt: new Date().getTime(),
27
-      user: {
28
-        _id: 2,
29
-        name: 'Test User'
30
-      }
31
-    }
32
-  ]);*/
33
-
34
   const [messages, setMessages] = useState([])
11
   const [messages, setMessages] = useState([])
35
 
12
 
36
-
37
-  /** the useEffect is used when we first render the component
38
-   *  solo va a corrar al principio.
39
-   */
40
   useEffect(() => {
13
   useEffect(() => {
41
-    //readUser()
42
     const unsubscribe = firebase.firestore() 
14
     const unsubscribe = firebase.firestore() 
43
     .collection('THREADS')
15
     .collection('THREADS')
44
     .doc(thread._id)
16
     .doc(thread._id)
70
     await Promise.all(writes)
42
     await Promise.all(writes)
71
   }
43
   }
72
 
44
 
73
-  /*async function handleSend(messages, newMessage = []) {
74
-    const text = messages[0].text;
75
-    setMessages(GiftedChat.append(messages, newMessage));
76
-
77
-  //aqui podemos usar current user que no lo hemos usado, ya tenemos conectado redux
78
-    firebase.firestore() 
79
-      .collection('Users')
80
-      .doc(firebase.auth().currentUser.uid)
81
-      .collection('THREADS')
82
-      .doc(thread._id)
83
-      .collection('MESSAGES')
84
-      .add({
85
-        text,
86
-        createdAt: new Date().getTime(),
87
-      });
88
-
89
-    //Esto se ve, pero no genraliza, solo funciona desde currentUser y se graba en la otra cuenta, 
90
-    //pero la otra cuenta no puede responder porque pasa a ser current user. 
91
-    //Ademas no guarda que usuario dijo que.
92
-      firebase.firestore() 
93
-      .collection('Users')
94
-      .doc('HGGAJlcIfwdpUoYfcBKLZFcDude2')
95
-      .collection('THREADS')
96
-      .doc(thread._id)
97
-      .collection('MESSAGES')
98
-      .add({
99
-        text,
100
-        createdAt: new Date().getTime(),
101
-      });
102
-  }*/
103
-
104
-  // helper method that is sends a message
105
-  /*function handleSend(newMessage = []) {
106
-    setMessages(GiftedChat.append(messages, newMessage));
107
-  }*/
45
+  
108
 
46
 
109
   return (
47
   return (
110
-    /*<GiftedChat
111
-      messages={messages}
112
-      onSend={newMessage => handleSend(messages, newMessage)}
113
-      user={{ _id: 1 }}
114
-      showUserAvatar
115
-      alwaysShowSend
116
-      scrollToBottom
117
-    />*/
118
-
119
     <GiftedChat messages={messages} user={{ _id: 1 }} onSend={handleSend} />
48
     <GiftedChat messages={messages} user={{ _id: 1 }} onSend={handleSend} />
120
   );
49
   );
121
 }
50
 }