generated from Bamdoliro/repository-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
66 lines (58 loc) · 2.12 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
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import useSocket from "./src/hooks/useSocket";
import { useEffect, useState } from "react";
import { QueryClient, QueryClientProvider } from "react-query";
import { getAccessToken } from "./src/utils/storage/token";
import MainNavigation from "./src/routes/MainNavigation";
import AuthNavigation from "./src/routes/AuthNavigation";
import SplashScreen from "./src/screens/SplashScreen";
import {BottomSheetModalProvider} from "@gorhom/bottom-sheet";
const Stack = createNativeStackNavigator();
const queryClient = new QueryClient();
export default function App() {
const [splash, setSplash] = useState(false);
const [login, setLogin] = useState(null);
const socket = useSocket();
const setLoginToken = async () => {
setLogin(await getAccessToken());
}
const subscribeChat = async () => {
if (await getAccessToken()) {
socket.current?.emit("subscribe");
}
}
useEffect(() => {
subscribeChat();
}, [socket]);
return (
splash ? (
<QueryClientProvider client={queryClient} >
<BottomSheetModalProvider>
<NavigationContainer>
{login ?
<MainNavigation
Stack={Stack}
setLogout={() => {
setLogin(null)
socket.current?.disconnect();
}}
socket={socket}
/>
:
<AuthNavigation
Stack={Stack}
setLogin={() => setLoginToken()}
/>
}
</NavigationContainer>
</BottomSheetModalProvider>
</QueryClientProvider>
) : (
<SplashScreen
setLoginToken={setLoginToken}
setSplash={setSplash}
/>
)
);
};