Explorar el Código

Cambios para que se envien los usernames

gilberto.cancel hace 3 años
padre
commit
52fe541c1d
Se han modificado 1 ficheros con 74 adiciones y 6 borrados
  1. 74
    6
      screens/main/Home_page.js

+ 74
- 6
screens/main/Home_page.js Ver fichero

@@ -31,6 +31,8 @@ export function Home_page({navigation}) {
31 31
   const [appointments, setAppointments] = useState([]); 
32 32
 
33 33
   const[interpreter, setState] = useState();
34
+  const [Iuser, setIUser] = useState({})
35
+  const [Uuser, setUser] = useState({})
34 36
 
35 37
   const [expoPushToken, setExpoPushToken] = useState('');
36 38
   const [notification, setNotification] = useState(false);
@@ -51,6 +53,47 @@ export function Home_page({navigation}) {
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 97
     const fire = firebase.firestore()
55 98
     .collection('THREADS')
56 99
     .where("members", "array-contains", firebase.auth().currentUser.uid)
@@ -74,6 +117,8 @@ export function Home_page({navigation}) {
74 117
       const appointments = snapShot.docs.map(docSnap => {
75 118
         return{
76 119
           _id:docSnap.id,
120
+          User:'',
121
+          Interpreter:'',
77 122
           new:'',
78 123
           Day:'',
79 124
           Month:'',
@@ -94,6 +139,8 @@ export function Home_page({navigation}) {
94 139
       Notifications.removeNotificationSubscription(responseListener.current);
95 140
       fire();
96 141
       cita();
142
+      Iuser_data();
143
+      user_data();
97 144
     }
98 145
   }, []);
99 146
   
@@ -106,9 +153,7 @@ export function Home_page({navigation}) {
106 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 158
     firebase.firestore()
114 159
     .collection("Interprete")
@@ -138,9 +183,13 @@ export function Home_page({navigation}) {
138 183
       })
139 184
   }
140 185
   
186
+
141 187
   check_user_type_INT();
142 188
   console.log("interpreter", interpreter);
189
+
190
+  
143 191
   if(interpreter == false){
192
+    const user_name = Uuser[0].username;
144 193
     return (
145 194
       <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
146 195
       <FlatList style={{
@@ -157,6 +206,14 @@ export function Home_page({navigation}) {
157 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 217
            <List.Item
161 218
             title='Mes:'
162 219
             description={item.Month}
@@ -207,7 +264,7 @@ export function Home_page({navigation}) {
207 264
             />
208 265
         <Button
209 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 269
         <Button
213 270
           title ='Logout'
@@ -217,6 +274,8 @@ export function Home_page({navigation}) {
217 274
       );
218 275
     }
219 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 279
       return (
221 280
         <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
222 281
         <FlatList style={{
@@ -229,11 +288,19 @@ export function Home_page({navigation}) {
229 288
           renderItem = {({item}) => (
230 289
           <TouchableOpacity
231 290
           onPress={async () => {
232
-            console.log("item._id, home, interpreter", item._id)
291
+            console.log("item._id, home, interpreter", item)
233 292
             navigation.navigate('Cita',{tag: item, Pin: item})
234 293
           }}
235 294
           >
236 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 304
             title='Mes:'
238 305
             description={item.Month}
239 306
             titleNumberOfLines={1}
@@ -356,4 +423,5 @@ const mapStateToProps = (store) => ({
356 423
 })
357 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
+