-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
101 lines (100 loc) · 4.06 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
import React, {useState} from 'react';
import 'react-native-gesture-handler';
import {AsyncStorage, StyleSheet} from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import Register from "./src/components/Register/Register";
import Login from "./src/components/Login/Login";
import Home from "./src/components/Home/Home";
import Message from "./src/components/User/Message";
import Image from "./src/components/Image/Image";
import * as eva from '@eva-design/eva';
import {ApplicationProvider, IconRegistry} from '@ui-kitten/components';
import {EvaIconsPack} from "@ui-kitten/eva-icons";
import FlashMessage, {showMessage} from "react-native-flash-message";
import config from "./src/config";
import axios from "axios";
import {createBottomTabNavigator} from "@react-navigation/bottom-tabs";
import ShowImage from "./src/components/Image/ShowImage";
import ShowUserToSnap from "./src/components/User/ShowUserToSnap";
export default function App() {
const [user, setUser] = useState(false);
const [users, setUsers] = useState([]);
(async () => {
let token = await AsyncStorage.getItem('token', (err, result) => {
return result;
});
if (token){
setUser(token)
}
})()
if (user){
axios.interceptors.request.use(function (config) {
config.headers.token = user;
return config;
}, function (error) {
showMessage({
message: "Une erreur est survenue, lors de l'interception de la requête",
type: 'error',
})
return Promise.reject(error);
});
}
StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
home: {
margin: 1,
}
});
const logout = () => {setUser(false);AsyncStorage.removeItem('token');}
const Stack = createStackNavigator();
const Tab = createBottomTabNavigator();
function CreateUserLogStack(){
const AppDrawerNavigation = () => {
return (
// https://reactnavigation.org/docs/stack-navigator#animation-related-options
<Tab.Navigator>
<Tab.Screen name={"Home"} options={{title: 'Accueil'}}>
{props => <Home {...props} logout={logout} user={user}/>}
</Tab.Screen>
<Tab.Screen name={"Image"} options={{title: 'Image'}} component={ShowImage} />
<Tab.Screen name={"Message"} options={{title: 'Message'}} component={Message} />
</Tab.Navigator>
)
}
return (
<Stack.Navigator screenOptions={{gestureEnabled: true}} headerMode={'none'}>
{!user ? (
<>
{/*L'utilisateur n'est pas connecté*/}
<Stack.Screen name="Login" options={{title: 'Connexion'}}
>{props => <Login {...props} setUser={setUser} urlApi={config.urlApi}/>}</Stack.Screen>
<Stack.Screen name="Register" options={{title: 'Inscription'}}
>{props => <Register {...props} urlApi={config.urlApi}/>}</Stack.Screen>
</>
) : (
<>
{/*L'utilisateur est connecté*/}
<Stack.Screen name={"Home"} options={{title: 'my_snapchat'}} component={AppDrawerNavigation}/>
<Stack.Screen name={"ShowUserToSnap"} component={ShowUserToSnap}/>
</>
)}
</Stack.Navigator>
);
}
return (
<>
<IconRegistry icons={EvaIconsPack} />
<ApplicationProvider {...eva} theme={eva.light}>
<NavigationContainer>
<CreateUserLogStack />
<FlashMessage position="top" />
</NavigationContainer>
</ApplicationProvider>
</>
);
}