-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
124 lines (87 loc) · 2.78 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
import React, { Component } from 'react';
import Routes from './src/Routes/Routetabstack';
import { withApollo } from '@apollo/client/react/hoc';
import NetInfo from "@react-native-community/netinfo";
import { getDeepLink } from './utilities';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {MainContext} from './src/util/maincontext';
class App extends Component {
_isMounted = false;
//This is the method to set the context data.
setAuthenticated = (authenticated) => {
this.setState({ authenticated });
};
setErrors = (errormessage) => {
this.setState({errormessage});
}
//This is the method to set the context data.
setProfile = (profile) => {
this.setState({ profile,loading:false,mutateloading:false,mutateid:'' });
};
//This is the method to set the context data.
setActivities = (activities) => {
this.setState({ activities,loading:false,mutateloading:false,mutateid:'' });
};
setLoading = (loading) => {
this.setState({ loading });
};
setMutateloading = (mutateloading) => {
this.setState({ mutateloading });
};
setMutateid = (mutateid) => {
this.setState({ mutateid });
};
//Let's declare our main state here, it would be global, and can be shared!
state = {
authenticated:false,
profile: null,
activities:[],
loading:false,
mutateloading:false,
mutateid:'',
errormessage: {errors: '', errortype:''},
setErrors: this.setErrors,
setAuthenticated: this.setAuthenticated,
setProfile: this.setProfile,
setActivities: this.setActivities,
setLoading: this.setLoading,
setMutateid: this.setMutateid,
setMutateloading: this.setMutateloading
}
componentDidMount() {
this._isMounted = true;
if (this._isMounted){
this.initialstateFunction();
}
}
componentWillUnmount() {
this._isMounted = false;
}
initialstateFunction = async() => {
NetInfo.fetch().then(async(networkState) => {
// if network available, fetch initial set of queries for activities,images,groups,members list for offline mode
if (networkState.isConnected){
let icuserinfo = await AsyncStorage.getItem("ICgetuserinfo");
if (icuserinfo && icuserinfo !== null) {
this.setState({authenticated:true,profile: await JSON.parse(icuserinfo)});
}
else
{
this.setState({authenticated:false})
}
}
else
{
this.setState({authenticated:false})
}
});
}
render() {
return (
<MainContext.Provider value={this.state}>
<Routes uriPrefix={getDeepLink()}/>
</MainContext.Provider>
)
}
}
export default withApollo(App);