|
@@ -15,96 +15,12 @@ import { fetchUser } from '../../redux/actions/index'
|
15
|
15
|
import Constants from 'expo-constants';
|
16
|
16
|
import * as Notifications from 'expo-notifications';
|
17
|
17
|
|
18
|
|
-Notifications.setNotificationHandler({
|
19
|
|
- handleNotification: async () => ({
|
20
|
|
- shouldShowAlert: true,
|
21
|
|
- shouldPlaySound: true,
|
22
|
|
- shouldSetBadge: false,
|
23
|
|
- }),
|
24
|
|
-});
|
25
|
18
|
|
26
|
19
|
|
27
|
20
|
export function Cita({navigation}) {
|
28
|
|
- const [threads, setThreads] = useState([]);
|
29
|
|
- const [loading, setLoading] = useState(true);
|
30
|
|
- const [appointments, setAppointments] = useState([]);
|
31
|
|
-
|
32
|
|
- const [expoPushToken, setExpoPushToken] = useState('');
|
33
|
|
- const [notification, setNotification] = useState(false);
|
34
|
|
- const notificationListener = useRef();
|
35
|
|
- const responseListener = useRef();
|
36
|
|
-
|
37
|
|
- useEffect(() => {
|
38
|
|
- registerForPushNotificationsAsync().then(token => setExpoPushToken(token));
|
39
|
|
- notificationListener.current = Notifications.addNotificationReceivedListener(notification => {
|
40
|
|
- setNotification(notification);
|
41
|
|
- });
|
42
|
|
-
|
43
|
|
- responseListener.current = Notifications.addNotificationResponseReceivedListener(response => {
|
44
|
|
- console.log(response);
|
45
|
|
- navigation.navigate('Confirm');
|
46
|
|
- });
|
47
|
|
-
|
48
|
|
- const fire = firebase.firestore()
|
49
|
|
- .collection('THREADS')
|
50
|
|
- .where("members", "array-contains", firebase.auth().currentUser.uid)
|
51
|
|
- .onSnapshot(querySnapshot => {
|
52
|
|
- const threads = querySnapshot.docs.map(documentSnapshot => {
|
53
|
|
- return{
|
54
|
|
- _id:documentSnapshot.id,
|
55
|
|
- name:'',
|
56
|
|
- ...documentSnapshot.data()
|
57
|
|
- };
|
58
|
|
- });
|
59
|
|
-
|
60
|
|
- setThreads(threads);
|
61
|
|
- console.log(threads);
|
62
|
|
-
|
63
|
|
- if(loading){
|
64
|
|
- setLoading(false);
|
65
|
|
- }
|
66
|
|
- });
|
67
|
|
-
|
68
|
|
- const cita = firebase.firestore().collection('APPOINTMENTS').where('Day', '==', 8).onSnapshot(snapShot => {
|
69
|
|
- const appointments = snapShot.docs.map(docSnap => {
|
70
|
|
- return{
|
71
|
|
- _id:docSnap.id,
|
72
|
|
- Day:'',
|
73
|
|
- Month:'',
|
74
|
|
- Time:'',
|
75
|
|
- i_id:'',
|
76
|
|
- uid1:'',
|
77
|
|
- ...docSnap.data()
|
78
|
|
- };
|
79
|
|
- });
|
80
|
|
- setAppointments(appointments);
|
81
|
|
- console.log(appointments);
|
82
|
|
- });
|
83
|
|
-
|
84
|
|
- return () => {
|
85
|
|
- Notifications.removeNotificationSubscription(notificationListener.current);
|
86
|
|
- Notifications.removeNotificationSubscription(responseListener.current);
|
87
|
|
- fire();
|
88
|
|
- cita();
|
89
|
|
- }
|
90
|
|
- }, []);
|
91
|
|
-
|
92
|
|
- if (loading) {
|
93
|
|
- return <Loading />;
|
94
|
|
- }
|
|
21
|
+
|
95
|
22
|
|
96
|
23
|
|
97
|
|
- function handleButtonPress() {
|
98
|
|
- firebase.firestore()
|
99
|
|
- .collection('THREADS')
|
100
|
|
- .add({
|
101
|
|
- name: 'PedroFecha',
|
102
|
|
- members: [
|
103
|
|
- firebase.auth().currentUser.uid,
|
104
|
|
- '02yOZHxFcGUX4MNwjeEbAlCShdu1'
|
105
|
|
- ]
|
106
|
|
- })
|
107
|
|
- }
|
108
|
24
|
|
109
|
25
|
const dimensions = Dimensions.get('window');
|
110
|
26
|
const screenWidth = dimensions.width;
|
|
@@ -112,64 +28,6 @@ export function Cita({navigation}) {
|
112
|
28
|
|
113
|
29
|
return (
|
114
|
30
|
<ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
|
115
|
|
- <FlatList style={{
|
116
|
|
- flex: 1,
|
117
|
|
- width: screenWidth,
|
118
|
|
- }}
|
119
|
|
- data={threads}
|
120
|
|
- keyExtractor = {item => item._id}
|
121
|
|
- ItemSeparatorComponent={() => <Divider />}
|
122
|
|
- renderItem = {({item}) => (
|
123
|
|
- <TouchableOpacity
|
124
|
|
- onPress={() => navigation.navigate('Room', {thread: item})}
|
125
|
|
- >
|
126
|
|
- <List.Item
|
127
|
|
- title={item.name}
|
128
|
|
- titleNumberOfLines={1}
|
129
|
|
- titleStyle={styles.listTitle}
|
130
|
|
- descriptionStyle={styles.listDescription}
|
131
|
|
- descriptionNumberOfLines={1}
|
132
|
|
- />
|
133
|
|
- </TouchableOpacity>
|
134
|
|
- )}
|
135
|
|
- />
|
136
|
|
- <FlatList style={{
|
137
|
|
- flex: 1,
|
138
|
|
- width: screenWidth,
|
139
|
|
- }}
|
140
|
|
- data={appointments}
|
141
|
|
- keyExtractor = {item => item._id}
|
142
|
|
- ItemSeparatorComponent={() => <Divider />}
|
143
|
|
- renderItem = {({item}) => (
|
144
|
|
- <TouchableOpacity
|
145
|
|
- onPress={async () => {
|
146
|
|
- await sendPushNotification(expoPushToken); //item.push_token
|
147
|
|
- }}
|
148
|
|
- >
|
149
|
|
- <List.Item
|
150
|
|
- title={item.Month}
|
151
|
|
- titleNumberOfLines={1}
|
152
|
|
- titleStyle={styles.listTitle}
|
153
|
|
- descriptionStyle={styles.listDescription}
|
154
|
|
- descriptionNumberOfLines={1}
|
155
|
|
- />
|
156
|
|
- <List.Item
|
157
|
|
- title={item.Day}
|
158
|
|
- titleNumberOfLines={1}
|
159
|
|
- titleStyle={styles.listTitle}
|
160
|
|
- descriptionStyle={styles.listDescription}
|
161
|
|
- descriptionNumberOfLines={1}
|
162
|
|
- />
|
163
|
|
- <List.Item
|
164
|
|
- title={item.Time}
|
165
|
|
- titleNumberOfLines={1}
|
166
|
|
- titleStyle={styles.listTitle}
|
167
|
|
- descriptionStyle={styles.listDescription}
|
168
|
|
- descriptionNumberOfLines={1}
|
169
|
|
- />
|
170
|
|
- </TouchableOpacity>
|
171
|
|
- )}
|
172
|
|
- />
|
173
|
31
|
<Button
|
174
|
32
|
title ='Ver mapa'
|
175
|
33
|
onPress= {() => navigation.navigate('Map')}
|
|
@@ -181,60 +39,7 @@ export function Cita({navigation}) {
|
181
|
39
|
</ImageBackground>
|
182
|
40
|
);
|
183
|
41
|
}
|
184
|
|
-// Can use this function below, OR use Expo's Push Notification Tool-> https://expo.dev/notifications
|
185
|
|
-async function sendPushNotification(expoPushToken) {
|
186
|
|
- const message = {
|
187
|
|
- to: expoPushToken,
|
188
|
|
- sound: 'default',
|
189
|
|
- title: 'Freehand',
|
190
|
|
- body: 'Le solicitan una cita',
|
191
|
|
- data: { someData: 'goes here' },
|
192
|
|
- };
|
193
|
|
-
|
194
|
|
- await fetch('https://exp.host/--/api/v2/push/send', {
|
195
|
|
- method: 'POST',
|
196
|
|
- headers: {
|
197
|
|
- Accept: 'application/json',
|
198
|
|
- 'Accept-encoding': 'gzip, deflate',
|
199
|
|
- 'Content-Type': 'application/json',
|
200
|
|
- },
|
201
|
|
- body: JSON.stringify(message),
|
202
|
|
- });
|
203
|
|
-}
|
204
|
|
-
|
205
|
|
-async function registerForPushNotificationsAsync() {
|
206
|
|
- let token;
|
207
|
|
- if (Constants.isDevice) {
|
208
|
|
- const { status: existingStatus } = await Notifications.getPermissionsAsync();
|
209
|
|
- let finalStatus = existingStatus;
|
210
|
|
- if (existingStatus !== 'granted') {
|
211
|
|
- const { status } = await Notifications.requestPermissionsAsync();
|
212
|
|
- finalStatus = status;
|
213
|
|
- }
|
214
|
|
- if (finalStatus !== 'granted') {
|
215
|
|
- alert('Failed to get push token for push notification!');
|
216
|
|
- return;
|
217
|
|
- }
|
218
|
|
- token = (await Notifications.getExpoPushTokenAsync()).data;
|
219
|
|
- console.log(token);
|
220
|
|
- } else {
|
221
|
|
- alert('Must use physical device for Push Notifications');
|
222
|
|
- }
|
223
|
|
-
|
224
|
|
- if (Platform.OS === 'android') {
|
225
|
|
- Notifications.setNotificationChannelAsync('default', {
|
226
|
|
- name: 'default',
|
227
|
|
- importance: Notifications.AndroidImportance.MAX,
|
228
|
|
- vibrationPattern: [0, 250, 250, 250],
|
229
|
|
- lightColor: '#FF231F7C',
|
230
|
|
- });
|
231
|
|
- }
|
232
|
|
-
|
233
|
|
- firebase.firestore().collection('Interprete').doc(firebase.auth().currentUser.uid).update({'push_token': token})
|
234
|
|
- firebase.firestore().collection('Users').doc(firebase.auth().currentUser.uid).update({'push_token': token})
|
235
|
42
|
|
236
|
|
- return token;
|
237
|
|
-}
|
238
|
43
|
|
239
|
44
|
const mapStateToProps = (store) => ({
|
240
|
45
|
currentUser: store.userState.currentUser
|