Sfoglia il codice sorgente

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

ErnestoOrtiz2 2 anni fa
parent
commit
3a751c3169
1 ha cambiato i file con 55 aggiunte e 8 eliminazioni
  1. 55
    8
      screens/main/Home_page.js

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

@@ -1,5 +1,5 @@
1 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 3
 import {FlatList, ListViewBase } from 'react-native'
4 4
 import {TouchableOpacity} from 'react-native-gesture-handler'
5 5
 import {List, Divider} from 'react-native-paper'
@@ -15,6 +15,7 @@ import { fetchUser } from '../../redux/actions/index'
15 15
 import Constants from 'expo-constants';
16 16
 import * as Notifications from 'expo-notifications';
17 17
 
18
+
18 19
 Notifications.setNotificationHandler({
19 20
   handleNotification: async () => ({
20 21
     shouldShowAlert: true,
@@ -27,6 +28,7 @@ Notifications.setNotificationHandler({
27 28
 export function Home_page({navigation}) {
28 29
   const [threads, setThreads] = useState([]);  
29 30
   const [loading, setLoading] = useState(true);
31
+  const [appointments, setAppointments] = useState([]); 
30 32
   
31 33
   const [roomName, setRoomName] = useState('');
32 34
 
@@ -58,22 +60,37 @@ export function Home_page({navigation}) {
58 60
           name:'',
59 61
           ...documentSnapshot.data()
60 62
         };
61
-
62 63
       });
63 64
 
64 65
       setThreads(threads);
66
+      console.log(threads);
65 67
 
66 68
       if(loading){
67 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 88
     //return () => fire();
73 89
     return () => {
74 90
       Notifications.removeNotificationSubscription(notificationListener.current);
75 91
       Notifications.removeNotificationSubscription(responseListener.current);
76 92
       fire();
93
+      cita();
77 94
     }
78 95
   }, []);
79 96
   
@@ -115,6 +132,7 @@ export function Home_page({navigation}) {
115 132
          //});
116 133
   }
117 134
 
135
+  
118 136
   return (
119 137
       <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
120 138
         <FlatList
@@ -135,6 +153,40 @@ export function Home_page({navigation}) {
135 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 190
       <Text>Your expo push token: {expoPushToken}</Text>
139 191
       <View style={{ alignItems: 'center', justifyContent: 'center' }}>
140 192
         <Text>Title: {notification && notification.request.content.title} </Text>
@@ -159,10 +211,6 @@ export function Home_page({navigation}) {
159 211
         title ='Logout'
160 212
         onPress= {() => firebase.auth().signOut()}
161 213
       />
162
-      <Button
163
-        title ='SendMessage'
164
-        onPress= {() => sendMessage(expoPushToken)}
165
-      />
166 214
         </ImageBackground>
167 215
     );
168 216
   }
@@ -219,7 +267,6 @@ async function registerForPushNotificationsAsync() {
219 267
   return token;
220 268
 }
221 269
 
222
-
223 270
 const mapStateToProps = (store) => ({
224 271
   currentUser: store.userState.currentUser
225 272
 })