import React, {useState, useEffect, useRef} from 'react' import { Button, Text, View, StyleSheet, Dimensions} from 'react-native' import {FlatList, ListViewBase } from 'react-native' import {TouchableOpacity} from 'react-native-gesture-handler' import {List, Divider} from 'react-native-paper' import Loading from './Loading' import firebase from 'firebase'; import { styles } from "../../config/styles"; import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground} from "react-native"; import { connect } from 'react-redux' import { bindActionCreators } from 'redux' import { fetchUser } from '../../redux/actions/index' import Constants from 'expo-constants'; import * as Notifications from 'expo-notifications'; Notifications.setNotificationHandler({ handleNotification: async () => ({ shouldShowAlert: true, shouldPlaySound: true, shouldSetBadge: false, }), }); export function Home_page({navigation}) { const [threads, setThreads] = useState([]); const [loading, setLoading] = useState(true); const [appointments, setAppointments] = useState([]); const [expoPushToken, setExpoPushToken] = useState(''); const [notification, setNotification] = useState(false); const notificationListener = useRef(); const responseListener = useRef(); useEffect(() => { registerForPushNotificationsAsync().then(token => setExpoPushToken(token)); notificationListener.current = Notifications.addNotificationReceivedListener(notification => { setNotification(notification); }); responseListener.current = Notifications.addNotificationResponseReceivedListener(response => { console.log(response); navigation.navigate('Confirm'); }); const fire = firebase.firestore() .collection('THREADS') .where("members", "array-contains", firebase.auth().currentUser.uid) .onSnapshot(querySnapshot => { const threads = querySnapshot.docs.map(documentSnapshot => { return{ _id:documentSnapshot.id, name:'', ...documentSnapshot.data() }; }); setThreads(threads); console.log(threads); if(loading){ setLoading(false); } }); const cita = firebase.firestore().collection('APPOINTMENTS').where('Day', '==', 8).onSnapshot(snapShot => { const appointments = snapShot.docs.map(docSnap => { return{ _id:docSnap.id, Day:'', Month:'', Time:'', i_id:'', uid1:'', ...docSnap.data() }; }); setAppointments(appointments); console.log(appointments); }); return () => { Notifications.removeNotificationSubscription(notificationListener.current); Notifications.removeNotificationSubscription(responseListener.current); fire(); cita(); } }, []); if (loading) { return ; } function handleButtonPress() { firebase.firestore() .collection('THREADS') .add({ name: 'PedroFecha', members: [ firebase.auth().currentUser.uid, '02yOZHxFcGUX4MNwjeEbAlCShdu1' ] }) } const dimensions = Dimensions.get('window'); const screenWidth = dimensions.width; return ( item._id} ItemSeparatorComponent={() => } renderItem = {({item}) => ( { navigation.navigate('Cita') }} > )} />