-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.tsx
59 lines (46 loc) · 1.62 KB
/
Main.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
import React, { useContext, useEffect, useState } from "react";
import { useIsConnected } from "react-native-offline";
import { Loading } from "./components/Loading";
import NoInternet from "./components/NoInternet";
import { ICustomWebViewProps } from "./components/webview/sharedProps";
import { handlePushRegistration } from "./helpers/events";
import { StructureContext } from "./helpers/context";
// eslint-disable-next-line import/order, import/no-unresolved, import/no-useless-path-segments
const CustomWebView: React.FC<ICustomWebViewProps> = require("./components/webview").default;
export const Main: React.FC = () => {
const {
offlineScreenComponent: OfflineScreenComponent = NoInternet,
...props
} = useContext(StructureContext);
const [loading, setLoading] = useState<boolean>(true);
const [webviewUrl, setWebviewUrl] = useState<string>(props.siteUrl);
const [applePayEnabled, setApplePayEnabled] = useState<boolean>(false);
const isConnected = useIsConnected();
const reloadWebView = (enableApplePay: boolean) => {
setLoading(true);
setApplePayEnabled(enableApplePay);
setTimeout(() =>
setLoading(false), 250);
};
useEffect(() => {
setLoading(false);
}, []);
useEffect(() => {
if (!props.requestNotificationPermission)
return;
handlePushRegistration(props.onPushRegistered!);
}, [props.requestNotificationPermission]);
if (loading)
return <Loading />;
if (!isConnected)
return <OfflineScreenComponent />;
return (
<CustomWebView
webviewUrl={webviewUrl}
setWebviewUrl={setWebviewUrl}
reloadWebView={reloadWebView}
applePayEnabled={applePayEnabled}
/>
);
};
export default Main;