This repository has been archived by the owner on Sep 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
110 lines (100 loc) · 2.91 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { setBackgroundColorAsync } from "expo-navigation-bar";
import { enableScreens } from "react-native-screens";
import { useEffect, useRef, useState } from "react";
import Navigation from "@/navigation/Navigation";
import { Animated, Image } from "react-native";
import { getColors, getToken, loginInstance, post, setToken } from "@/utils";
import { StatusBar } from "expo-status-bar";
import { ToastManager } from "@commonents";
import * as Sentry from "@sentry/react-native";
import { path } from "@/constants";
const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: true,
retryDelay: 300,
staleTime: 10000,
},
},
});
Sentry.init({
dsn: process.env.EXPO_PUBLIC_SENTRY_DSN,
debug: true,
});
interface PropType {
option: boolean;
anim: Animated.Value;
}
const Splash = ({ option, anim }: PropType) => {
if (option) {
return (
<Animated.View
style={{
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
width: "100%",
height: "100%",
position: "absolute",
opacity: anim,
}}
>
<Image
source={require("./app/assets/SPLogo.gif")}
style={{ width: 300, height: 100 }}
/>
</Animated.View>
);
}
};
function App() {
const fadeAnim = useRef(new Animated.Value(1)).current;
const [token, setTokens] = useState(undefined);
const [loaded, setLoaded] = useState([false, false]);
enableScreens(false);
useEffect(() => {
const color = async () => {
await setBackgroundColorAsync(getColors(["primary", 1000]));
};
const tokenFn = async () => {
const { account, accessToken, name } = await getToken();
if (account) {
const data = { account_id: account[0], password: account[1] };
Sentry.configureScope((scope: Sentry.Scope) => {
scope.setUser({
id: data.account_id,
username: name,
});
});
loginInstance.post(`${path.user}/login`, data).then((res) => {
setToken(res?.data.access_token, account, name);
setLoaded((prev) => [true, prev[1]]);
});
} else {
setLoaded((prev) => [true, prev[1]]);
}
setTokens(accessToken);
};
tokenFn();
color();
setTimeout(() => {
Animated.timing(fadeAnim, {
toValue: 0,
duration: 100,
useNativeDriver: true,
}).start(() => setLoaded((prev) => [prev[0], true]));
}, 1600);
}, []);
if (token !== undefined) {
return (
<QueryClientProvider client={queryClient}>
{loaded[0] === true && <Navigation auth={!!token} />}
<Splash option={!loaded[1]} anim={fadeAnim} />
<ToastManager />
<StatusBar style="dark" />
</QueryClientProvider>
);
}
}
export default Sentry.wrap(App);