Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
conflict resolve
  • Loading branch information
KaleemNeslit committed Jan 31, 2025
commit 7b9176ec0482109438465c6fa3e902e180cf24e5
44 changes: 34 additions & 10 deletions components/Webapp/Webapp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import WebView, {
WebViewMessageEvent,
WebViewNavigation,
} from "react-native-webview";
import React, { useCallback, useEffect, useRef, useState } from "react";
import ExpoNotifications from "@/components/ExpoNotifications/ExpoNotifications";
import { isInternalURL } from "@/util/isInternalURL";
import About from "@/components/About/About";
Expand All @@ -21,6 +20,9 @@ import { useURL } from "expo-linking";
import { useRouter } from "expo-router";
import * as Notifications from "expo-notifications";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { NotificationsListener } from "@/components/Webapp/NotificationsListener";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";

/**
* Enable a fake URL bar to debug the URL we're visiting.
*/
Expand Down Expand Up @@ -64,6 +66,24 @@ export default function Webapp({ handleSafeAreaVisibility }: WebAppProps) {
const touchStart = useRef<TouchStartGesture>({ start: 0, startY: 0 });
const [error, setError] = useState<string | undefined>(undefined);
const [isFirstLaunch, setIsFirstLaunch] = useState<boolean | null>(null);
const webViewRef = useRef<WebView | null>(null);

const [notificationStatus, setNotificationStatus] = useState<
Notifications.PermissionStatus | undefined
>(undefined);

const notificationsListener = useMemo(() => {
const postMessage = (msg: string) => {
if (webViewRef.current) {
webViewRef.current.postMessage(msg);
}
};

return new NotificationsListener(postMessage, (status) => {
console.log("Got listener notification permission status: " + status);
setNotificationStatus(status);
});
}, []);

console.log("expoURL: " + expoURL);
console.log("URL: " + url);
Expand Down Expand Up @@ -152,7 +172,9 @@ export default function Webapp({ handleSafeAreaVisibility }: WebAppProps) {
}
};

const handlePushMessage = (event: WebViewMessageEvent) => {
const handleMessage = (event: WebViewMessageEvent) => {
notificationsListener.handleMessage(event);

const msg = JSON.parse(event.nativeEvent.data);
if (msg.type === "about") {
setMode("about");
Expand Down Expand Up @@ -237,7 +259,7 @@ export default function Webapp({ handleSafeAreaVisibility }: WebAppProps) {
source={{ uri: url }}
ref={webViewRef}
sharedCookiesEnabled={true}
onMessage={(event) => handlePushMessage(event)}
onMessage={(event) => handleMessage(event)}
onShouldStartLoadWithRequest={handleNavigation}
webviewDebuggingEnabled={__DEV__}
onError={(event) => setError(event.nativeEvent.description)}
Expand All @@ -248,13 +270,15 @@ export default function Webapp({ handleSafeAreaVisibility }: WebAppProps) {
/>
)}

{userInfo && userInfo.userId !== 0 && (
<ExpoNotifications
userId={userInfo.userId}
knockJWT={userInfo.knockJWT}
onLink={changeURL}
/>
)}
{notificationStatus === "granted" &&
userInfo &&
userInfo.userId !== 0 && (
<ExpoNotifications
userId={userInfo.userId}
knockJWT={userInfo.knockJWT}
onLink={changeURL}
/>
)}
</>
)}
</View>
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.