-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppBase.tsx
126 lines (112 loc) · 3.25 KB
/
AppBase.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { StatusBar } from "expo-status-bar";
import React, { useEffect, useMemo } from "react";
import { SafeAreaProvider } from "react-native-safe-area-context";
import * as zipson from "zipson";
import "./polyfill";
import { useColorScheme } from "react-native";
import Navigation from "./navigation";
import { QueryClient, QueryClientProvider } from "react-query";
import { persistQueryClient } from "react-query/persistQueryClient-experimental";
import { Provider as JotaiProvider } from "jotai";
import "./lang/i18n";
import CheckStatus from "./BackgroundLocation";
import useSetting, {
LiveLocationErrorAtom, store,
} from "./hooks/useSetting";
import { useTranslation } from "react-i18next";
import "expo-firebase-analytics";
import * as Sentry from "sentry-expo";
import EvaWrapper from "./EvaWrapper";
import { extendTheme, NativeBaseProvider, useColorMode } from "native-base";
import { UsersSetHandler } from "./hooks/useUserSettings";
import { ClanCellStyleHandler } from "./components/Clan/Cell";
Sentry.init({
dsn: "https://[email protected]/5418530",
} as any);
const queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchOnMount: true,
refetchOnWindowFocus: true,
staleTime: 900000,
retry: 1,
},
},
});
persistQueryClient({
queryClient,
persistor: {
persistClient(client) {
try {
client.clientState.queries.forEach(query => {
query.state.isFetching = false;
});
return store.set("@cz3/querycache", zipson.stringify(client));
} catch {
return store.set("@cz3/querycache", zipson.stringify(client));
}
},
restoreClient() {
return zipson.parse(store.getString("@cz3/querycache") ?? "null");
},
removeClient() {
return store.delete("@cz3/querycache");
},
},
});
function ColorModeHandler() {
const colorScheme = useColorScheme();
const colorMode = useColorMode();
useEffect(() => {
colorMode.setColorMode(colorScheme);
}, [colorScheme]);
return null;
}
function AppBase() {
const colorScheme = useColorScheme();
const [liveLocationError, setLiveLocationError] = useSetting(
LiveLocationErrorAtom
);
React.useEffect(() => {
if (!liveLocationError) {
CheckStatus().then(value => setLiveLocationError(value));
}
}, [liveLocationError]);
const { i18n } = useTranslation();
const theme = useMemo(() => {
const defaultTheme = extendTheme({});
return extendTheme({
config: {
initialColorMode: colorScheme,
},
colors: {
regularGray: defaultTheme.colors.blueGray,
primary: defaultTheme.colors.teal,
},
});
}, [colorScheme]);
return (
<>
<NativeBaseProvider theme={theme}>
<ColorModeHandler />
<UsersSetHandler />
<ClanCellStyleHandler />
<EvaWrapper>
<Navigation key={i18n.language} colorScheme={colorScheme} />
<StatusBar />
</EvaWrapper>
</NativeBaseProvider>
</>
);
}
export default function AppProviders() {
return (
<SafeAreaProvider>
<JotaiProvider>
<QueryClientProvider client={queryClient}>
<AppBase />
</QueryClientProvider>
</JotaiProvider>
</SafeAreaProvider>
);
}