-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
131 lines (117 loc) · 4.16 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import React from 'react';
import { AsyncStorage } from 'react-native';
import { createAppContainer, NavigationEvents } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import * as Location from 'expo-location';
import * as TaskManager from 'expo-task-manager';
import { YellowBox } from 'react-native';
import axios from 'axios';
import InitializingScreen from './src/components/InitializingScreen'
import SignInScreen from './src/components/SignInScreen'
import SignUpScreen from './src/components/SignUpScreen'
import MainMenuScreen from './src/components/MainMenuScreen'
import UserProfileScreen from './src/components/UserProfileScreen'
import TextModal from './src/components/TextModal'
import ContactsIndexScreen from './src/components/ContactsIndexScreen'
import ContactFormModal from './src/components/ContactFormModal'
import ViewContactScreen from './src/components/ViewContactScreen'
import CheckInModeScreen from './src/components/CheckInModeScreen'
import SLocationModal from './src/components/SLocationModal'
import CheckInPeriodModal from './src/components/CheckInPeriodModal'
import TripSearchScreen from './src/components/TripSearchScreen'
import TripConfirmScreen from './src/components/TripConfirmScreen'
import MapScreen from './src/components/MapScreen'
import TripCompleteModal from './src/components/TripCompleteModal'
console.disableYellowBox = true;
TaskManager.defineTask("CROSSING_SLOCATION", async ({ data: { eventType, region }, error }) => {
if (error) {
console.log('CROSS SLOCATION GEOFENCE ERROR', error);
return;
}
if (eventType === Location.GeofencingEventType.Enter || eventType === Location.GeofencingEventType.Exit) {
console.log("You've crossed slocation geofence:", region);
const userID = await AsyncStorage.getItem('BUDDY_ID');
const data = {
last_check_in: Date.now()
};
axios.patch(`https://buddy-api-ada.herokuapp.com/users/${ userID }`, data)
.then((response) => {
console.log('Successfully updated last check in time: ', response.data);
})
.catch((err) => {
console.log('Error updating last check in time', err);
});
}
});
TaskManager.defineTask("ARRIVE_AT_DEST", async ({ data: { eventType, region }, error }) => {
if (error) {
console.log('ARRIVE AT DEST ERROR: ', error);
return;
}
if (eventType === Location.GeofencingEventType.Enter) {
console.log("You've arrived at your destination", region);
const tripID = await AsyncStorage.getItem('TRIP_ID');
const data = {
status: "COMPLETE"
};
axios.patch(`https://buddy-api-ada.herokuapp.com/trips/${ tripID }`, data)
.then((response) => {
console.log('Successfully updated trip status to COMPLETE: ', response.data);
AsyncStorage.removeItem('TRIP_ID');
Location.stopGeofencingAsync("ARRIVE_AT_DEST");
})
.catch((err) => {
console.log('Error updating trip status to COMPLETE', err);
});
}
});
export default class App extends React.Component {
render() {
const MainStack = createStackNavigator(
{
Initializing: InitializingScreen,
SignIn: SignInScreen,
SignUp: SignUpScreen,
MainMenu: MainMenuScreen,
UserProfile: UserProfileScreen,
ContactsIndex: ContactsIndexScreen,
ViewContact: ViewContactScreen,
CheckInMode: CheckInModeScreen,
TripSearch: TripSearchScreen,
TripConfirm: TripConfirmScreen,
MapScreen: MapScreen
},
{
initialRouteName: 'Initializing',
}
);
const RootStack = createStackNavigator(
{
Main: {
screen: MainStack,
},
TextModal: {
screen: TextModal,
},
ContactFormModal: {
screen: ContactFormModal,
},
SLocationModal: {
screen: SLocationModal,
},
CheckInPeriodModal: {
screen: CheckInPeriodModal,
},
TripCompleteModal: {
screen: TripCompleteModal,
}
},
{
mode: 'modal',
headerMode: 'none',
}
);
const AppContainer = createAppContainer(RootStack);
return <AppContainer />;
}
}