-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
244 lines (215 loc) · 6.43 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
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
/*Frameworks*/
import * as React from 'react';
import { Alert,Platform,LogBox} from 'react-native';
import { createAppContainer } from 'react-navigation';
import { createBottomTabNavigator } from 'react-navigation-tabs';
import { AntDesign,MaterialIcons,Ionicons } from '@expo/vector-icons';
import firebase from "firebase";
import {createStackNavigator} from "react-navigation-stack";
import * as Permissions from 'expo-permissions';
/*Screens*/
import LoginScreen from "./components/login/LoginScreen";
import SignupScreen from "./components/login/SignupScreen";
import logout_spoofScreen from "./components/login/Logout_spoofScreen";
import CreateVisitCardScreen from "./components/admin/CreateVisitCardScreen";
import MyVisitCardsScreen from "./components/admin/MyVisitCardsScreen";
import RecievedVisitCardsScreen from "./components/admin/RecievedVisitCardsScreen";
import ProfilScreen from "./components/admin/ProfilScreen";
import EditVisitCardScreen from "./components/admin/EditVisitCardScreen";
import SeeRecievedVisitCardItem from "./components/admin/items/SeeRecievedVisitCardItem";
import QrScannerScreen from "./components/admin/QrScannerScreen";
import MyQRCodeScreen from "./components/admin/MyQRCodeScreen";
/*Hvis det ikke er web fjern logbox*/
if(Platform.OS !== "web"){
LogBox.ignoreAllLogs(true)
}
/*Dette er min navigator til når man er logget ind*/
const AdminBottomNavigator = createBottomTabNavigator({
Mine:{
screen:MyVisitCardsScreen,
navigationOptions:{
tabBarIcon:({tintColor}) =>(
<MaterialIcons name="account-box" size={24} color={tintColor} />
)
}
},
Modtaget:{
screen:RecievedVisitCardsScreen,
navigationOptions:{
tabBarIcon:({tintColor}) =>(
<AntDesign name="inbox" size={24} color={tintColor} />
)
}
},
Profil:{
screen:ProfilScreen,
navigationOptions:{
tabBarIcon:({tintColor}) =>(
<AntDesign name="profile" size={24} color={tintColor} />
)
}
},
/*Sætter en spoof screen til at håndtere onpress som gør jeg logger ud med firebase*/
Logud: {
screen: logout_spoofScreen,
navigationOptions: ({navigation}) => ({
tabBarOnPress: (scene, jumpToIndex) => {
if(Platform.OS === 'web')
{
if(confirm('Vil du logge ud? ')){
try {
const response = firebase.auth().signOut();
} catch (e) {
console.log(e);
}
}
}else {
return Alert.alert( // Shows up the alert without redirecting anywhere
'Godkendt følgende'
, 'Vil du gerne logge ud?'
, [
{
text: 'Ja', onPress:async () => {
try {
const response = await firebase.auth().signOut();
} catch (e) {
console.log(e);
}
}
},
{text: 'Nej'}
]
);
}
}
,
tabBarIcon:({tintColor}) =>(
<AntDesign name="logout" size={24} color={tintColor} />
)
}),
}
});
const AdminStackNavigation = createStackNavigator({
Menu:{
screen:AdminBottomNavigator,
navigationOptions:{
tabBarIcon:({tintColor}) =>(
<AntDesign name="dashboard" size={24} color={tintColor} />
),
headerShown:false
}
},
Opret:{
screen:CreateVisitCardScreen,
navigationOptions:{
tabBarIcon:({tintColor}) =>(
<AntDesign name="dashboard" size={24} color={tintColor} />
),
headerShown:false
}
},
QR:{
screen:QrScannerScreen,
navigationOptions:{
tabBarIcon:({tintColor}) =>(
<AntDesign name="qrcode" size={24} color={tintColor} />
),
}
},
MinQRKode:{
screen:MyQRCodeScreen,
navigationOptions:{
tabBarIcon:({tintColor}) =>(
<AntDesign name="qrcode" size={24} color={tintColor} />
),
}
},
EditMyVisitCard:{
screen:EditVisitCardScreen,
navigationOptions:{
tabBarIcon:({tintColor}) =>(
<AntDesign name="dashboard" size={24} color={tintColor} />
)
}
},
SeeRecievedVisitCard:{
screen:SeeRecievedVisitCardItem,
navigationOptions:{
tabBarIcon:({tintColor}) =>(
<AntDesign name="dashboard" size={24} color={tintColor} />
),
headerShown:true
}
}
})
/*Min navigator hvis man ikke er logget ind*/
const PublicBottomNavigator = createBottomTabNavigator({
Login:{
screen: LoginScreen,
navigationOptions:{
tabBarIcon:({tintColor}) =>(
<AntDesign name="login" size={24} color={tintColor} />
)
}
},
Signup:{
screen:SignupScreen,
navigationOptions:{
tabBarIcon:({tintColor}) =>(
<MaterialIcons name="account-circle" size={24} color={tintColor} /> )
}
}
});
const LoginContainer = createAppContainer(PublicBottomNavigator);
const AdminContainer = createAppContainer(AdminStackNavigation);
export default class App extends React.Component{
/*Constructor til at init og observe auth*/
constructor() {
super();
this.init();
this.observeAuth();
}
state={
user:null
}
componentDidMount() {
this.updateMotionPermission();
}
/*Sørg for at states bliver nulsat efter de er blevet bvrugt*/
/*Init*/
init = () =>{
const fireBaseConfig = {
apiKey: "AIzaSyAlOUjJY2erM9bvxtre9RYVCVF_dLXOkmY",
authDomain: "eksamen-innovation.firebaseapp.com",
databaseURL: "https://eksamen-innovation.firebaseio.com",
projectId: "eksamen-innovation",
storageBucket: "eksamen-innovation.appspot.com",
messagingSenderId: "1004695638499",
appId: "1:1004695638499:web:bc9d8a5a25f8385bda90d6"
};
// vigtigt at tilføje nedestående if statement, da ellers init firebase flere gange
if (!firebase.apps.length) {
firebase.initializeApp(fireBaseConfig);
}
firebase.auth().signOut()
}
updateMotionPermission = async() => {
const { status } = await Permissions.askAsync(Permissions.MOTION);
this.setState({ hasMotionPermission: status === 'granted' });
}
/*Set Auth state*/
observeAuth = async () => {
await firebase.auth().onAuthStateChanged(user => {
this.setState({ user });
});
}
/*Render afhængig om jeg er logget ind*/
render() {
const {user} = this.state;
if(!user){
return <LoginContainer/>
}else {
return <AdminContainer/>
}
}
}