-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApps.js
More file actions
102 lines (87 loc) · 2.84 KB
/
Apps.js
File metadata and controls
102 lines (87 loc) · 2.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
import React, {Component} from 'react';
import {TouchableOpacity, StyleSheet, Text} from 'react-native';
import Home from './components/Home';
import UsersList from './components/UsersList';
import Login from './components/Login';
import SignUp from './components/SignUp';
import MyProfile from './components/MyProfile';
import Books from './components/Books';
import BookDetail from './components/BookDetail';
//import Test from './components/test';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import {SafeAreaView} from 'react-native-safe-area-context';
const Stack = createNativeStackNavigator();
export default class Apps extends Component {
constructor(props) {
super(props);
this.state = {
loggedIn: false,
};
this.isLoggedIn = this.isLoggedIn.bind(this);
this.logout = this.logout.bind(this);
}
async isLoggedIn() {
const jwt = await AsyncStorage.getItem('jwt');
if (jwt) {
return true;
} else {
return false;
}
}
async logout() {
await AsyncStorage.removeItem('jwt');
this.setState({
loggedIn: false,
});
}
async componentDidMount() {
this.setState({
loggedIn: await this.isLoggedIn(),
});
}
render() {
return (
<SafeAreaView style={{flex: 1}}>
<NavigationContainer>
{this.state.loggedIn === true ? (
<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Users" component={UsersList} />
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="Profile" component={MyProfile} />
<Stack.Screen name="Books" component={Books} />
<Stack.Screen name="BookDetail" component={BookDetail} />
<Stack.Screen name="Login" component={Login} />
<Stack.Screen name="SignUp" component={SignUp} />
</Stack.Navigator>
) : (
<Stack.Navigator initialRouteName="Login">
<Stack.Screen name="Users" component={UsersList} />
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="Profile" component={MyProfile} />
<Stack.Screen name="Books" component={Books} />
<Stack.Screen name="BookDetail" component={BookDetail} />
<Stack.Screen name="Login" component={Login} />
<Stack.Screen name="SignUp" component={SignUp} />
</Stack.Navigator>
)}
</NavigationContainer>
</SafeAreaView>
);
}
}
const styles = StyleSheet.create({
blackText: {
color: 'black',
},
logout: {
color: 'white',
backgroundColor: 'red',
padding: 10,
width: '20%',
},
whiteText: {
color: 'white',
},
});