-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppContainer.js
More file actions
370 lines (321 loc) · 9.84 KB
/
AppContainer.js
File metadata and controls
370 lines (321 loc) · 9.84 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
// In App.js in a new project
// console.log
import * as React from "react";
import * as firebase from "firebase";
import { View, Text, Button,LogBox } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createDrawerNavigator } from "@react-navigation/drawer";
import RootStackScreen from "./Screens/StackScreens/RootStackScreen";
import { ActivityIndicator } from "react-native-paper";
import AuthContext from "./components/context";
import AuthNewContext from "./components/newContext";
import SupportScreen from "./Screens/SupportScreen";
import DrawerContent from "./Screens/DrawerContent";
import DrawerContent1 from "./Screens/DrawerContent1";
import AsyncStorage from "@react-native-async-storage/async-storage";
import HomeStackScreen from "./Screens/StackScreens/HomeStackScreen";
import DetailsStackScreen from "./Screens/StackScreens/DetailStackScreen";
import PaymentStackScreen from "./Screens/StackScreens/paymentStackScreen";
import MorePaymentStackScreen from "./Screens/StackScreens/MorepaymentStackScreen";
import ReservationStackScreen from "./Screens/StackScreens/ReservationStackScreen";
import ServiceStackScreen from "./Screens/StackScreens/ServiceStackScreen";
import * as Notifications from "expo-notifications";
import * as Permissions from "expo-permissions";
import morepaymentDetails from "./Screens/morepaymentDetails"
const Drawer = createDrawerNavigator();
LogBox.ignoreLogs(['Setting a timer']);
Notifications.setNotificationHandler({
handleNotification: async () => {
return {
shouldShowAlert: true,
};
},
});
// const [firebaseState,setFirebaseState]=React.useState({dataSource: new ListView.DataSource({
// rowHasChanged: (row1, row2) => row1 !== row2,
// })})
const firebaseConfig = {
apiKey: "AIzaSyBUqsaZQSoV67VgFkpozKHJfgD7OLeaXyE",
authDomain: "vvisit-d6347.firebaseapp.com",
databaseURL: "https://vvisit-d6347-default-rtdb.firebaseio.com",
projectId: "vvisit-d6347",
storageBucket: "vvisit-d6347.appspot.com",
};
try{
firebase.initializeApp(firebaseConfig);
}
catch(e){
}
function setcusData(userId, pushToken) {
firebase
.database()
.ref("users/" + userId)
.set({
UserId: userId,
pushToken: pushToken,
paymentD: 0,
services: "null",
});
}
function setSerData(userId, pushToken) {
firebase
.database()
.ref("users/" + userId)
.set({
UserId: userId,
pushToken: pushToken,
paymentD: 0,
servicesgranted: "null",
});
}
function AppContainer() {
let pushToken;
const [tokenState, setTokenState] = React.useState("a");
const [trigermy, setmytriger] = React.useState(true);
const myFunctions =()=>{
Permissions.getAsync(Permissions.NOTIFICATIONS)
.then((statusObj) => {
if (statusObj.status !== "granted") {
return Permissions.askAsync(Permissions.NOTIFICATIONS);
}
return statusObj;
})
.then((statusObj) => {
if (statusObj.status !== "granted") {
throw new Error("permission not granted");
}
})
.then(() => {
// console.log("getting token");
return Notifications.getExpoPushTokenAsync();
})
.then((response) => {
const token = response.data;
// console.log("token: " + token);
pushToken = token;
})
.catch((err) => {
return null;
});
}
React.useEffect(() => {
let cancel=false
myFunctions()
return () => {
// This is the cleanup function
cancel=true
}
}, []);
React.useEffect(() => {
let cancel1=false
const backgroundSubcription = Notifications.addNotificationResponseReceivedListener(
(response) => {
// console.log(response);
}
);
const foregroundsubscription = Notifications.addNotificationReceivedListener(
(notification) => {
// console.log(notification);
}
);
return () => {
foregroundsubscription.remove();
backgroundSubcription.remove();
cancel1=true
};
}, []);
const triggerNotificationHandler = () => {
// Notifications.scheduleNotificationAsync({
// content: {
// title: "My first local notification",
// body: "this is the first local notification ",
// },
// trigger: {
// seconds: 10,
// },
// });
};
// const [isLoading,setIsLoading]=React.useState(true);
// const [userToken,setUserToken]=React.useState(null);
// const [isLoading, setLoading] = React.useState(true);
const initialLoginState = {
isLoading: true,
userName: null,
userToken: null,
role: null,
};
const [roleState, setroleState] = React.useState(null);
const loginReducer = (prevState, action) => {
switch (action.type) {
case "RETRIVE_TOKEN":
return {
...prevState,
userToken: action.token,
isLoading: false,
};
case "LOGIN":
return {
...prevState,
userName: action.id,
userToken: action.token,
isLoading: false,
};
case "LOGOUT":
return {
...prevState,
userName: null,
userToken: null,
isLoading: false,
};
case "REGISTER":
return {
...prevState,
userName: action.id,
userToken: action.token,
isLoading: false,
};
}
};
const [loginState, dispatch] = React.useReducer(
loginReducer,
initialLoginState
);
const authContext = React.useMemo(
() => ({
signIn: async (condition, token, role) => {
setTokenState(token);
setroleState(role);
let userToken;
userToken = null;
// for(i;i<10;i++){
// if(userName===data1[i].id){
// break;
// }
// else continue;
// }
// // console.log('user name',data1[0].id)
// // console.log('pass',data1[0].releaseYear)
if (condition == true) {
if (role == "Customer") {
setcusData(token, pushToken);
} else {
setSerData(token, pushToken);
}
try {
userToken = "fksjf";
await AsyncStorage.setItem("userToken", userToken);
} catch (e) {
// console.log(e);
}
}
dispatch({ type: "LOGIN", token: userToken });
},
signOut: async () => {
// setUserToken(null);
// setIsLoading(false);
try {
await AsyncStorage.removeItem("userToken");
} catch (e) {
// console.log(e);
}
dispatch({ type: "LOGOUT" });
},
signUp:async (value) => {
//setUserToken('fksjf');
// setIsLoading(false);
},
}),
[]
);
React.useEffect(() => {
setTimeout(async () => {
// setIsLoading(false);
let userToken;
userToken = null;
try {
userToken = await AsyncStorage.getItem("userToken");
} catch (e) {
// console.log(e);
}
dispatch({ type: "REGISTER", token: userToken });
}, 1000);
}, []);
if (loginState.isLoading) {
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<ActivityIndicator size="large" />
</View>
);
}
return (
<AuthNewContext.Provider value={{trigermy, setmytriger}}>
<AuthContext.Provider value={authContext}>
<NavigationContainer>
{loginState.userToken !== null ? (
roleState === "Customer" ? (
<Drawer.Navigator
drawerContent={(props) => <DrawerContent {...props} /> } initialRouteName="HomeDrawer"
>
<Drawer.Screen name="HomeDrawer" component={HomeStackScreen} />
<Drawer.Screen
name="userDetails"
component={DetailsStackScreen}
initialParams={{ Name: tokenState }}
/>
<Drawer.Screen
name="reservation"
component={ReservationStackScreen}
initialParams={{ Name: tokenState }}
/>
<Drawer.Screen
name="Payments"
component={PaymentStackScreen}
initialParams={{ Name: tokenState }}
/>
<Drawer.Screen
name="morePayments"
component={morepaymentDetails}
/>
<Drawer.Screen name="SupportScreen" component={SupportScreen} />
</Drawer.Navigator>
) : (
<Drawer.Navigator
drawerContent={(props) => <DrawerContent1 {...props} />} initialRouteName="HomeDrawer"
>
<Drawer.Screen
name="userDetails"
component={DetailsStackScreen}
initialParams={{ Name: tokenState }}
/>
<Drawer.Screen name="HomeDrawer" component={HomeStackScreen} />
<Drawer.Screen
name="Services"
component={ServiceStackScreen}
initialParams={{ Name: tokenState }}
/>
<Drawer.Screen
name="reservation"
component={ReservationStackScreen}
initialParams={{ Name: tokenState }}
/>
<Drawer.Screen
name="Payments"
component={PaymentStackScreen}
initialParams={{ Name: tokenState }}
/>
<Drawer.Screen
name="morePayments"
component={morepaymentDetails}
/>
<Drawer.Screen name="SupportScreen" component={SupportScreen} />
</Drawer.Navigator>
)
) : (
<RootStackScreen />
)}
</NavigationContainer>
</AuthContext.Provider>
</AuthNewContext.Provider>
);
}
export default AppContainer;