-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
75 lines (67 loc) · 2.1 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
//import React in the code
import React from "react";
//import all the components we are going to use
import TrainerNav from "./navigation/TrainerNavigator";
import TraineeNav from "./navigation/TraineeNavigator";
import AsyncStorage from "@react-native-async-storage/async-storage";
import SignNav from "./navigation/SignNavigation";
import { Provider } from "react-redux";
import store from "./store";
import { LogBox } from "react-native";
LogBox.ignoreLogs([
"Your project is accessing the following APIs from a deprecated global rather than a module import: Constants (expo-constants).",
]);
//The beginning of the class
export default class app extends React.Component {
state = {
token: null,
user: "",
userId: null
}
//Check whether to token and the type of user exist in the local storage of the device and store them as states
async componentDidMount() {
//AsyncStorage.removeItem("fb_token");
//AsyncStorage.removeItem("user");
//AsyncStorage.removeItem("userId");
let token = await AsyncStorage.getItem("fb_token");
let user = await AsyncStorage.getItem("user");
let userId = await AsyncStorage.getItem("userId");
if (user) {
this.setState({ user });
} else {
this.setState({ user: "" });
}
if (token) {
this.setState({ token });
} else {
this.setState({ token: false });
}
if (userId) {
this.setState({ userId });
} else {
this.setState({ userId: false });
}
}
render() {
if (this.state.token && this.state.userId && this.state.user == "trainee") {
return (
//Return the navigation stack of the trainee
<Provider store={store}>
<TraineeNav />
</Provider >)
} else if (this.state.token && this.state.userId && this.state.user == "trainer") {
return (
//Return the navigation stack of the trainer
<Provider store={store}>
<TrainerNav />
</Provider >)
}
else {
return (
//Return the navigation stack of signing
<Provider store={store}>
<SignNav />
</Provider>)
}
}
}