Add notifications support.

This commit is contained in:
Patrick Fic
2025-10-24 10:36:30 -07:00
parent 0809a01c90
commit 75ee01e896
12 changed files with 236 additions and 11 deletions

View File

@@ -7,6 +7,7 @@ import {
DefaultTheme,
ThemeProvider,
} from "@react-navigation/native";
import * as Notifications from "expo-notifications";
import { Stack } from "expo-router";
import {
Icon,
@@ -25,6 +26,7 @@ import { client } from "../graphql/client";
import { useTheme as usePaperTheme } from "../hooks/useTheme";
import { persistor, store } from "../redux/store";
import "../translations/i18n";
import { registerForPushNotificationsAsync } from "../util/notificationHandler";
function AuthenticatedLayout() {
const { t } = useTranslation();
@@ -109,6 +111,33 @@ function AppContent({ currentUser, checkUserSession, bodyshop }: any) {
checkUserSession();
}, [checkUserSession]);
useEffect(() => {
registerForPushNotificationsAsync()
.then((token) => console.log("Expo Push Token:", token))
.catch((error: any) =>
console.log("Error getting Expo Push Token:", error)
);
const notificationListener = Notifications.addNotificationReceivedListener(
async (notification) => {
console.log("Notification received:", notification);
Notifications.setBadgeCountAsync(
(await Notifications.getBadgeCountAsync()) + 1
);
}
);
const responseListener =
Notifications.addNotificationResponseReceivedListener((response) => {
console.log("Notification response received:", response);
});
return () => {
notificationListener.remove();
responseListener.remove();
};
}, []);
if (currentUser.authorized === null) {
return (
<ThemedLayout>