Add notifications support.
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user