Browse Source

Fix al bug de confirm 'new', funciona ...a veces. A veces inexplicablemente, el mismo codigo tira errores.

ErnestoOrtiz2 2 years ago
parent
commit
f651d86983
2 changed files with 25 additions and 38 deletions
  1. 4
    2
      screens/main/Confirm.js
  2. 21
    36
      screens/main/Home_page.js

+ 4
- 2
screens/main/Confirm.js View File

24
 });
24
 });
25
 
25
 
26
 
26
 
27
-export function Confirm({navigation}) {
27
+export function Confirm({route, navigation}) {
28
   const [threads, setThreads] = useState([]);  
28
   const [threads, setThreads] = useState([]);  
29
   const [loading, setLoading] = useState(true);
29
   const [loading, setLoading] = useState(true);
30
   const [appointments, setAppointments] = useState([]); 
30
   const [appointments, setAppointments] = useState([]); 
45
       navigation.navigate('Search');
45
       navigation.navigate('Search');
46
     });
46
     });
47
 
47
 
48
-    const cita = firebase.firestore().collection('APPOINTMENTS').where("new", "==", 'true').onSnapshot(snapShot => {
48
+    console.log("en confirm", route.params.tag._id);
49
+    //const cita = firebase.firestore().collection('APPOINTMENTS').where("new", "==", "true").onSnapshot(snapShot => {
50
+    const cita = firebase.firestore().collection('APPOINTMENTS').where("citaID", "==", route.params.tag.citaID).onSnapshot(snapShot => {
49
       const appointments = snapShot.docs.map(docSnap => {
51
       const appointments = snapShot.docs.map(docSnap => {
50
         return{
52
         return{
51
           _id:docSnap.id,
53
           _id:docSnap.id,

+ 21
- 36
screens/main/Home_page.js View File

24
 });
24
 });
25
 
25
 
26
 
26
 
27
+const double = [];
28
+
27
 export function Home_page({navigation}) {
29
 export function Home_page({navigation}) {
28
 
30
 
29
   const [threads, setThreads] = useState([]);  
31
   const [threads, setThreads] = useState([]);  
47
     });
49
     });
48
 
50
 
49
     responseListener.current = Notifications.addNotificationResponseReceivedListener(response => {
51
     responseListener.current = Notifications.addNotificationResponseReceivedListener(response => {
50
-      console.log("response", response);
51
-      console.log("response date", response.notification.date);
52
-      const idDate = response.notification.date;
52
+      //console.log("response", response);
53
       if (response.notification.request.content.body == 'Le solicitan una cita'){
53
       if (response.notification.request.content.body == 'Le solicitan una cita'){
54
-        navigation.navigate('Confirm');
54
+        //console.log("en pedir response", {appointments});
55
+        //console.log("el id", appointments[0]._id);
56
+        navigation.navigate('Confirm',{tag: appointments[0]})
55
       } 
57
       } 
56
     });
58
     });
57
 
59
 
96
   });
98
   });
97
 
99
 
98
 
100
 
99
-    const fire = firebase.firestore()
100
-    .collection('THREADS')
101
-    .where("members", "array-contains", firebase.auth().currentUser.uid)
102
-    .onSnapshot(querySnapshot => {
103
-      const threads = querySnapshot.docs.map(documentSnapshot => {
104
-        return{
105
-          _id:documentSnapshot.id,
106
-          name:'',
107
-          ...documentSnapshot.data()
108
-        };
109
-      });
110
-
111
-      setThreads(threads);
112
-
113
-      if(loading){
114
-        setLoading(false);
115
-      }
116
-    });
117
-
118
     const cita = firebase.firestore().collection('APPOINTMENTS').where("participantes", "array-contains", firebase.auth().currentUser.uid).onSnapshot(snapShot => {
101
     const cita = firebase.firestore().collection('APPOINTMENTS').where("participantes", "array-contains", firebase.auth().currentUser.uid).onSnapshot(snapShot => {
119
       const appointments = snapShot.docs.map(docSnap => {
102
       const appointments = snapShot.docs.map(docSnap => {
120
         return{
103
         return{
139
     return () => {
122
     return () => {
140
       Notifications.removeNotificationSubscription(notificationListener.current);
123
       Notifications.removeNotificationSubscription(notificationListener.current);
141
       Notifications.removeNotificationSubscription(responseListener.current);
124
       Notifications.removeNotificationSubscription(responseListener.current);
142
-      fire();
143
       cita();
125
       cita();
144
       Iuser_data();
126
       Iuser_data();
145
       user_data();
127
       user_data();
331
             />
313
             />
332
 
314
 
333
 
315
 
334
-            <FlatList style={{
316
+          <FlatList style={{
335
              flex: 1,
317
              flex: 1,
336
              width: screenWidth,
318
              width: screenWidth,
337
-            }}
338
-            data={appointments}
339
-            keyExtractor = {item => item._id}
340
-            renderItem={({ item }) => {
319
+         }}
320
+          data={appointments}
321
+          keyExtractor = {item => item._id}
322
+          ItemSeparatorComponent={() => <Divider />}
323
+          renderItem={({ item }) => {
341
             if(item.new == 'true'){
324
             if(item.new == 'true'){
342
             return (
325
             return (
343
               <Button
326
               <Button
344
-                title ='Pedir Cita'
345
-                onPress={ async () => {
346
-                  await sendPushNotification(item.i_token);
347
-                  citaId(item._id);
348
-                  }
327
+              title ='Pedir Cita'
328
+              onPress={ async () => {
329
+                await sendPushNotification(item.i_token);
330
+                citaId(item._id);
331
+                console.log("appointment", appointments);
332
+                double = appointments.map((number) => number);
349
                 }
333
                 }
350
-              /> 
334
+              }
335
+            /> 
351
             )
336
             )
352
-            }}}
337
+          }}}
353
             />
338
             />
354
 
339
 
355
 
340