Browse Source

Prueba de generalizacion para enviar notificaciones. Funciona.

ErnestoOrtiz2 3 years ago
parent
commit
7d0d07dfc6
1 changed files with 44 additions and 5 deletions
  1. 44
    5
      screens/main/Home_page.js

+ 44
- 5
screens/main/Home_page.js View File

37
   const notificationListener = useRef();
37
   const notificationListener = useRef();
38
   const responseListener = useRef();
38
   const responseListener = useRef();
39
 
39
 
40
+  //const [oneApp, setOneApp] = useState('')
41
+
40
 
42
 
41
   useEffect(() => {
43
   useEffect(() => {
42
     registerForPushNotificationsAsync().then(token => setExpoPushToken(token));
44
     registerForPushNotificationsAsync().then(token => setExpoPushToken(token));
62
       });
64
       });
63
 
65
 
64
       setThreads(threads);
66
       setThreads(threads);
65
-      console.log(threads);
67
+      //console.log(threads);
66
 
68
 
67
       if(loading){
69
       if(loading){
68
         setLoading(false);
70
         setLoading(false);
69
       }
71
       }
70
     });
72
     });
71
 
73
 
72
-    const cita = firebase.firestore().collection('APPOINTMENTS').where('Day', '==', 8).onSnapshot(snapShot => {
74
+    const cita = firebase.firestore().collection('APPOINTMENTS').where("participantes", "array-contains", 'qj5xBCSRNoaRMik4UULmslSktLp1').onSnapshot(snapShot => {
73
       const appointments = snapShot.docs.map(docSnap => {
75
       const appointments = snapShot.docs.map(docSnap => {
74
         return{
76
         return{
75
           _id:docSnap.id,
77
           _id:docSnap.id,
76
           Day:'',
78
           Day:'',
77
           Month:'',
79
           Month:'',
78
           Time:'',
80
           Time:'',
79
-          i_id:'',
80
-          uid1:'',
81
+          i_token:'',
82
+          u_token:'',
81
           ...docSnap.data()
83
           ...docSnap.data()
82
         };
84
         };
83
       });
85
       });
84
       setAppointments(appointments);
86
       setAppointments(appointments);
85
-      console.log(appointments);
87
+      console.log("appointment", appointments);
88
+      //console.log(appointments.Day);
86
     });
89
     });
90
+
91
+
92
+    const day = firebase.firestore().collection('APPOINTMENTS').where('Day', '==', 8).get().then((res) => {
93
+      console.log(`Day is ${res.docs[0].get('Day')}.`);
94
+      //const dia = return{`${res.doc[0].get('Day')}`};
95
+    });
96
+    //console.log("Day", dia);
87
       
97
       
88
     return () => {
98
     return () => {
89
       Notifications.removeNotificationSubscription(notificationListener.current);
99
       Notifications.removeNotificationSubscription(notificationListener.current);
96
   if (loading) {
106
   if (loading) {
97
     return <Loading />;
107
     return <Loading />;
98
   }
108
   }
109
+   
110
+  
99
 
111
 
100
   
112
   
101
   function handleButtonPress() {
113
   function handleButtonPress() {
236
           </TouchableOpacity>
248
           </TouchableOpacity>
237
         )}
249
         )}
238
             />
250
             />
251
+
252
+
253
+            <FlatList style={{
254
+             flex: 1,
255
+             width: screenWidth,
256
+         }}
257
+          data={appointments}
258
+          keyExtractor = {item => item._id}
259
+          ItemSeparatorComponent={() => <Divider />}
260
+          renderItem={({ item }) => {
261
+            return (
262
+              <Button
263
+              title ='Send notification'
264
+              onPress={ async () => {
265
+                await sendPushNotification(item.i_token);
266
+                }
267
+              }
268
+            /> 
269
+            )
270
+          }}
271
+            />
272
+
273
+
239
           <Button
274
           <Button
240
             title ='Send notification'
275
             title ='Send notification'
241
             onPress={async () => {
276
             onPress={async () => {
246
           title ='Availability'
281
           title ='Availability'
247
           onPress= {() => navigation.navigate('Availability')}
282
           onPress= {() => navigation.navigate('Availability')}
248
         />
283
         />
284
+        <Button
285
+          title ='Mapa'
286
+          onPress= {() => navigation.navigate('Map')}
287
+        />
249
           <Button
288
           <Button
250
             title ='Logout'
289
             title ='Logout'
251
             onPress= {() => firebase.auth().signOut()}
290
             onPress= {() => firebase.auth().signOut()}