Browse Source

Hice el query para traer los datos de la cita al home page y los desplege en un flatlist.

ErnestoOrtiz2 2 years ago
parent
commit
3a751c3169
1 changed files with 55 additions and 8 deletions
  1. 55
    8
      screens/main/Home_page.js

+ 55
- 8
screens/main/Home_page.js View File

1
 import React, {useState, useEffect, useRef} from 'react'
1
 import React, {useState, useEffect, useRef} from 'react'
2
-import { Button, Text, View, StyleSheet} from 'react-native'
2
+import { Button, Text, View, StyleSheet, SafeAreaView} from 'react-native'
3
 import {FlatList, ListViewBase } from 'react-native'
3
 import {FlatList, ListViewBase } from 'react-native'
4
 import {TouchableOpacity} from 'react-native-gesture-handler'
4
 import {TouchableOpacity} from 'react-native-gesture-handler'
5
 import {List, Divider} from 'react-native-paper'
5
 import {List, Divider} from 'react-native-paper'
15
 import Constants from 'expo-constants';
15
 import Constants from 'expo-constants';
16
 import * as Notifications from 'expo-notifications';
16
 import * as Notifications from 'expo-notifications';
17
 
17
 
18
+
18
 Notifications.setNotificationHandler({
19
 Notifications.setNotificationHandler({
19
   handleNotification: async () => ({
20
   handleNotification: async () => ({
20
     shouldShowAlert: true,
21
     shouldShowAlert: true,
27
 export function Home_page({navigation}) {
28
 export function Home_page({navigation}) {
28
   const [threads, setThreads] = useState([]);  
29
   const [threads, setThreads] = useState([]);  
29
   const [loading, setLoading] = useState(true);
30
   const [loading, setLoading] = useState(true);
31
+  const [appointments, setAppointments] = useState([]); 
30
   
32
   
31
   const [roomName, setRoomName] = useState('');
33
   const [roomName, setRoomName] = useState('');
32
 
34
 
58
           name:'',
60
           name:'',
59
           ...documentSnapshot.data()
61
           ...documentSnapshot.data()
60
         };
62
         };
61
-
62
       });
63
       });
63
 
64
 
64
       setThreads(threads);
65
       setThreads(threads);
66
+      console.log(threads);
65
 
67
 
66
       if(loading){
68
       if(loading){
67
         setLoading(false);
69
         setLoading(false);
68
       }
70
       }
69
-
70
     });
71
     });
71
 
72
 
73
+    const cita = firebase.firestore().collection('APPOINTMENTS').where('Day', '==', 8).onSnapshot(snapShot => {
74
+      const appointments = snapShot.docs.map(docSnap => {
75
+        return{
76
+          _id:docSnap.id,
77
+          Day:'',
78
+          Month:'',
79
+          Time:'',
80
+          ...docSnap.data()
81
+        };
82
+      });
83
+      setAppointments(appointments);
84
+      console.log(appointments);
85
+    });
86
+  
87
+      
72
     //return () => fire();
88
     //return () => fire();
73
     return () => {
89
     return () => {
74
       Notifications.removeNotificationSubscription(notificationListener.current);
90
       Notifications.removeNotificationSubscription(notificationListener.current);
75
       Notifications.removeNotificationSubscription(responseListener.current);
91
       Notifications.removeNotificationSubscription(responseListener.current);
76
       fire();
92
       fire();
93
+      cita();
77
     }
94
     }
78
   }, []);
95
   }, []);
79
   
96
   
115
          //});
132
          //});
116
   }
133
   }
117
 
134
 
135
+  
118
   return (
136
   return (
119
       <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
137
       <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
120
         <FlatList
138
         <FlatList
135
           </TouchableOpacity>
153
           </TouchableOpacity>
136
         )}
154
         )}
137
         />
155
         />
156
+        <FlatList
157
+          data={appointments}
158
+          keyExtractor = {item => item._id}
159
+          ItemSeparatorComponent={() => <Divider />}
160
+          renderItem = {({item}) => (
161
+          <TouchableOpacity
162
+          onPress={async () => {
163
+            await sendPushNotification(expoPushToken);
164
+          }}
165
+          >
166
+            <List.Item
167
+              title={item.Month}
168
+              titleNumberOfLines={1}
169
+              titleStyle={styles.listTitle}
170
+              descriptionStyle={styles.listDescription}
171
+              descriptionNumberOfLines={1}
172
+            />
173
+            <List.Item
174
+              title={item.Day}
175
+              titleNumberOfLines={1}
176
+              titleStyle={styles.listTitle}
177
+              descriptionStyle={styles.listDescription}
178
+              descriptionNumberOfLines={1}
179
+            />
180
+            <List.Item
181
+              title={item.Time}
182
+              titleNumberOfLines={1}
183
+              titleStyle={styles.listTitle}
184
+              descriptionStyle={styles.listDescription}
185
+              descriptionNumberOfLines={1}
186
+            />
187
+          </TouchableOpacity>
188
+        )}
189
+        />
138
       <Text>Your expo push token: {expoPushToken}</Text>
190
       <Text>Your expo push token: {expoPushToken}</Text>
139
       <View style={{ alignItems: 'center', justifyContent: 'center' }}>
191
       <View style={{ alignItems: 'center', justifyContent: 'center' }}>
140
         <Text>Title: {notification && notification.request.content.title} </Text>
192
         <Text>Title: {notification && notification.request.content.title} </Text>
159
         title ='Logout'
211
         title ='Logout'
160
         onPress= {() => firebase.auth().signOut()}
212
         onPress= {() => firebase.auth().signOut()}
161
       />
213
       />
162
-      <Button
163
-        title ='SendMessage'
164
-        onPress= {() => sendMessage(expoPushToken)}
165
-      />
166
         </ImageBackground>
214
         </ImageBackground>
167
     );
215
     );
168
   }
216
   }
219
   return token;
267
   return token;
220
 }
268
 }
221
 
269
 
222
-
223
 const mapStateToProps = (store) => ({
270
 const mapStateToProps = (store) => ({
224
   currentUser: store.userState.currentUser
271
   currentUser: store.userState.currentUser
225
 })
272
 })