-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
88 lines (53 loc) · 2.13 KB
/
App.tsx
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
import { useLayoutEffect, useState } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import * as SecureStore from 'expo-secure-store';
import { store } from 'redux/store';
import { Provider } from 'react-redux';
import { useSelector, useDispatch} from "react-redux";
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import Onboarding from 'screens/Onboarding';
import Authentication from 'screens/Authentication';
import ProductsScreen from 'screens/ProductsScreen';
import ProductDetail from 'screens/ProductDetail';
import CartScreen from 'screens/CartScreen';
import CheckoutScreen from 'screens/CheckoutScreen';
import ProfileScreen from 'screens/ProfileScreen';
import OrderScreen from 'screens/OrdersScreen';
import { addAuthToken } from 'redux/authSlice';
const Stack = createNativeStackNavigator();
export default function AppWrapper () {
return (
<Provider store={store}>
<App />
</Provider>
)
}
function App() {
let token = useSelector((state:any) => state.user.token)
const dispatch = useDispatch()
useLayoutEffect (()=>{
const checkToken = async() => {
const data: any = await SecureStore.getItemAsync("userToken");
dispatch(addAuthToken(data))
}
checkToken()
},[])
return (
// <Provider store={store}>
<NavigationContainer>
<Stack.Navigator screenOptions={{ headerShown: false }}>
{ token === null &&
<Stack.Screen name="Onboarding" component={Onboarding} />
}
<Stack.Screen name="Products" component={ProductsScreen} />
<Stack.Screen name="Authentication" component={Authentication} />
<Stack.Screen name="Detail" component={ProductDetail} />
<Stack.Screen name="Cart" component={CartScreen} initialParams={{token}} />
<Stack.Screen name="Checkout" component={CheckoutScreen} />
<Stack.Screen name="Profile" component={ProfileScreen} />
<Stack.Screen name="Orders" component={OrderScreen} />
</Stack.Navigator>
</NavigationContainer>
// </Provider>
);
}