Browse Source

Cambios para que se envien los usernames

gilberto.cancel 2 years ago
parent
commit
52fe541c1d
1 changed files with 74 additions and 6 deletions
  1. 74
    6
      screens/main/Home_page.js

+ 74
- 6
screens/main/Home_page.js View File

31
   const [appointments, setAppointments] = useState([]); 
31
   const [appointments, setAppointments] = useState([]); 
32
 
32
 
33
   const[interpreter, setState] = useState();
33
   const[interpreter, setState] = useState();
34
+  const [Iuser, setIUser] = useState({})
35
+  const [Uuser, setUser] = useState({})
34
 
36
 
35
   const [expoPushToken, setExpoPushToken] = useState('');
37
   const [expoPushToken, setExpoPushToken] = useState('');
36
   const [notification, setNotification] = useState(false);
38
   const [notification, setNotification] = useState(false);
51
       } 
53
       } 
52
     });
54
     });
53
 
55
 
56
+    const user_email = firebase.auth().currentUser.email;
57
+
58
+  const Iuser_data = firebase.firestore()
59
+  .collection('Interprete')
60
+  .where("email", "==", user_email)
61
+  .onSnapshot(snapShot => {
62
+    const user = snapShot.docs.map(docSnap => {
63
+      return{
64
+        _id:docSnap.id,
65
+        email:'',
66
+        username:'',
67
+        ...docSnap.data()
68
+      };
69
+    });
70
+      setIUser(user)
71
+
72
+      if(loading){
73
+        setLoading(false);
74
+      }
75
+  });
76
+
77
+  const user_data = firebase.firestore()
78
+  .collection('Users')
79
+  .where("email", "==", user_email)
80
+  .onSnapshot(snapShot => {
81
+    const user = snapShot.docs.map(docSnap => {
82
+      return{
83
+        _id:docSnap.id,
84
+        email:'',
85
+        username:'',
86
+        ...docSnap.data()
87
+      };
88
+    });
89
+      setUser(user)
90
+
91
+      if(loading){
92
+        setLoading(false);
93
+      }
94
+  });
95
+
96
+
54
     const fire = firebase.firestore()
97
     const fire = firebase.firestore()
55
     .collection('THREADS')
98
     .collection('THREADS')
56
     .where("members", "array-contains", firebase.auth().currentUser.uid)
99
     .where("members", "array-contains", firebase.auth().currentUser.uid)
74
       const appointments = snapShot.docs.map(docSnap => {
117
       const appointments = snapShot.docs.map(docSnap => {
75
         return{
118
         return{
76
           _id:docSnap.id,
119
           _id:docSnap.id,
120
+          User:'',
121
+          Interpreter:'',
77
           new:'',
122
           new:'',
78
           Day:'',
123
           Day:'',
79
           Month:'',
124
           Month:'',
94
       Notifications.removeNotificationSubscription(responseListener.current);
139
       Notifications.removeNotificationSubscription(responseListener.current);
95
       fire();
140
       fire();
96
       cita();
141
       cita();
142
+      Iuser_data();
143
+      user_data();
97
     }
144
     }
98
   }, []);
145
   }, []);
99
   
146
   
106
   const screenWidth = dimensions.width;
153
   const screenWidth = dimensions.width;
107
 
154
 
108
   
155
   
109
-  function check_user_type_INT(){
110
-
111
-    
156
+  function check_user_type_INT(){ 
112
 
157
 
113
     firebase.firestore()
158
     firebase.firestore()
114
     .collection("Interprete")
159
     .collection("Interprete")
138
       })
183
       })
139
   }
184
   }
140
   
185
   
186
+
141
   check_user_type_INT();
187
   check_user_type_INT();
142
   console.log("interpreter", interpreter);
188
   console.log("interpreter", interpreter);
189
+
190
+  
143
   if(interpreter == false){
191
   if(interpreter == false){
192
+    const user_name = Uuser[0].username;
144
     return (
193
     return (
145
       <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
194
       <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
146
       <FlatList style={{
195
       <FlatList style={{
157
           navigation.navigate('Cita',{tag: item, Pin: item})
206
           navigation.navigate('Cita',{tag: item, Pin: item})
158
         }}
207
         }}
159
         >
208
         >
209
+          <List.Item
210
+            title='Interprete: '
211
+            description={item.Interpreter}
212
+            titleNumberOfLines={1}
213
+            titleStyle={styles.listTitle}
214
+            descriptionStyle={styles.listDescription}
215
+            descriptionNumberOfLines={1}
216
+          />
160
            <List.Item
217
            <List.Item
161
             title='Mes:'
218
             title='Mes:'
162
             description={item.Month}
219
             description={item.Month}
207
             />
264
             />
208
         <Button
265
         <Button
209
           title ='Hacer Busqueda'
266
           title ='Hacer Busqueda'
210
-          onPress= {() => navigation.navigate('Search', {U_Token: expoPushToken})}
267
+          onPress= {() => navigation.navigate('Search', {U_Token: expoPushToken, Username: user_name})}
211
         />
268
         />
212
         <Button
269
         <Button
213
           title ='Logout'
270
           title ='Logout'
217
       );
274
       );
218
     }
275
     }
219
     else{
276
     else{
277
+      //En caso de que se necesite el username del interprete que esta logged in.
278
+      //const user_name = Iuser[0].username;
220
       return (
279
       return (
221
         <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
280
         <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
222
         <FlatList style={{
281
         <FlatList style={{
229
           renderItem = {({item}) => (
288
           renderItem = {({item}) => (
230
           <TouchableOpacity
289
           <TouchableOpacity
231
           onPress={async () => {
290
           onPress={async () => {
232
-            console.log("item._id, home, interpreter", item._id)
291
+            console.log("item._id, home, interpreter", item)
233
             navigation.navigate('Cita',{tag: item, Pin: item})
292
             navigation.navigate('Cita',{tag: item, Pin: item})
234
           }}
293
           }}
235
           >
294
           >
236
           <List.Item
295
           <List.Item
296
+            title='Usuario:'
297
+            description={item.User}
298
+            titleNumberOfLines={1}
299
+            titleStyle={styles.listTitle}
300
+            descriptionStyle={styles.listDescription}
301
+            descriptionNumberOfLines={1}
302
+          />
303
+          <List.Item
237
             title='Mes:'
304
             title='Mes:'
238
             description={item.Month}
305
             description={item.Month}
239
             titleNumberOfLines={1}
306
             titleNumberOfLines={1}
356
 })
423
 })
357
 const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch);
424
 const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch);
358
 
425
 
359
-export default connect(mapStateToProps, mapDispatchProps)(Home_page);
426
+export default connect(mapStateToProps, mapDispatchProps)(Home_page);
427
+