Parcourir la source

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

ErnestoOrtiz2 il y a 3 ans
Parent
révision
f651d86983
2 fichiers modifiés avec 25 ajouts et 38 suppressions
  1. 4
    2
      screens/main/Confirm.js
  2. 21
    36
      screens/main/Home_page.js

+ 4
- 2
screens/main/Confirm.js Voir le fichier

@@ -24,7 +24,7 @@ Notifications.setNotificationHandler({
24 24
 });
25 25
 
26 26
 
27
-export function Confirm({navigation}) {
27
+export function Confirm({route, navigation}) {
28 28
   const [threads, setThreads] = useState([]);  
29 29
   const [loading, setLoading] = useState(true);
30 30
   const [appointments, setAppointments] = useState([]); 
@@ -45,7 +45,9 @@ export function Confirm({navigation}) {
45 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 51
       const appointments = snapShot.docs.map(docSnap => {
50 52
         return{
51 53
           _id:docSnap.id,

+ 21
- 36
screens/main/Home_page.js Voir le fichier

@@ -24,6 +24,8 @@ Notifications.setNotificationHandler({
24 24
 });
25 25
 
26 26
 
27
+const double = [];
28
+
27 29
 export function Home_page({navigation}) {
28 30
 
29 31
   const [threads, setThreads] = useState([]);  
@@ -47,11 +49,11 @@ export function Home_page({navigation}) {
47 49
     });
48 50
 
49 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 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,25 +98,6 @@ export function Home_page({navigation}) {
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 101
     const cita = firebase.firestore().collection('APPOINTMENTS').where("participantes", "array-contains", firebase.auth().currentUser.uid).onSnapshot(snapShot => {
119 102
       const appointments = snapShot.docs.map(docSnap => {
120 103
         return{
@@ -139,7 +122,6 @@ export function Home_page({navigation}) {
139 122
     return () => {
140 123
       Notifications.removeNotificationSubscription(notificationListener.current);
141 124
       Notifications.removeNotificationSubscription(responseListener.current);
142
-      fire();
143 125
       cita();
144 126
       Iuser_data();
145 127
       user_data();
@@ -331,25 +313,28 @@ export function Home_page({navigation}) {
331 313
             />
332 314
 
333 315
 
334
-            <FlatList style={{
316
+          <FlatList style={{
335 317
              flex: 1,
336 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 324
             if(item.new == 'true'){
342 325
             return (
343 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