-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
102 lines (96 loc) · 3.43 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
import AsyncStorage from "@react-native-async-storage/async-storage";
import { createAsyncStoragePersister } from "@tanstack/query-async-storage-persister";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { PersistQueryClientProvider } from "@tanstack/react-query-persist-client";
import { StatusBar } from "expo-status-bar";
import { useState } from "react";
import "react-native-gesture-handler";
import { SafeAreaView } from "react-native-safe-area-context";
import { Toast } from "react-native-toast-message/lib/src/Toast";
import { Provider } from "react-redux";
import { PersistGate } from "redux-persist/integration/react";
import NothingToShow from "./src/components/NothingToShow";
import Loader from "./src/components/ui/Loader";
import toastConfig from "./src/config/toastMessageConfig";
import useDBInitialize from "./src/hooks/useDBInitialize";
import RootNavigator from "./src/navigators/RootNavigator";
import { persistor, store } from "./src/store/store";
import { Colors } from "./src/utils/Colors";
// Create a client
export const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 1000 * 60 * 60 * 24,
cacheTime: 1000 * 60 * 60 * 24 * 7, //1 week
refetchOnMount: false,
},
},
});
export default function App() {
// load my custom fonts
// useLoadMyFonts();
// DB setup hook
const { dbInitialized, dbInitError, dbInitLoading } = useDBInitialize();
const [queryCacheHyderated, setQueryCacheHyderated] = useState(false);
const asyncStoragePersister = createAsyncStoragePersister({
storage: AsyncStorage,
// if there are multiple updates within a 4000-millisecond interval, they will be batched together and written to AsyncStorage only once
throttleTime: 4000, // Set the throttleTime to 4000 milliseconds
});
function enterApp() {
if (dbInitLoading) {
return <Loader loading={dbInitLoading} />;
} else if (!dbInitLoading && dbInitError) {
return (
// when reached here, the db initialization hsa failed and the app is in unclean state, show nothing/error
<NothingToShow
title={"Something went wrong while loading content"}
problemType="error"
/>
);
} else if (dbInitialized && queryCacheHyderated) {
return (
<>
{/* RootNavigation */}
<RootNavigator />
{/* toast messages */}
<Toast
config={toastConfig}
autoHide={true}
position={"bottom"}
bottomOffset={50}
keyboardOffset={20}
/>
</>
);
} else return null;
}
return (
<>
<StatusBar
style="light"
animated={true}
backgroundColor={Colors.tertiary}
/>
<Provider store={store}>
{/* REDUX persistor */}
<PersistGate persistor={persistor}>
<QueryClientProvider client={queryClient}>
{/* REACT TAN STACK QUERY persistor */}
<PersistQueryClientProvider
client={queryClient}
persistOptions={{ persister: asyncStoragePersister }}
onSuccess={() => {
setQueryCacheHyderated(true);
}}
>
<SafeAreaView className="flex-1 bg-secondary">
{enterApp()}
</SafeAreaView>
</PersistQueryClientProvider>
</QueryClientProvider>
</PersistGate>
</Provider>
</>
);
}