upd: notifikasi

Deskripsi:
- update notifikasi push routing ketika di klik

No Issues
This commit is contained in:
amel
2025-06-26 14:30:40 +08:00
parent 76c0ba0535
commit 32908e1362
6 changed files with 105 additions and 68 deletions

View File

@@ -7,10 +7,12 @@ import HeaderMemberList from "@/components/member/headerMemberList";
import HeaderRightPositionList from "@/components/position/headerRightPositionList";
import HeaderRightProjectList from "@/components/project/headerProjectList";
import { Headers } from "@/constants/Headers";
import { apiReadOneNotification } from "@/lib/api";
import { pushToPage } from "@/lib/pushToPage";
import store from "@/lib/store";
import { useAuthSession } from "@/providers/AuthProvider";
import messaging from "@react-native-firebase/messaging";
import { Redirect, router, Stack, usePathname } from "expo-router";
import { Redirect, router, Stack } from "expo-router";
import { StatusBar } from 'expo-status-bar';
import { useEffect } from "react";
import { Text } from "react-native";
@@ -18,56 +20,37 @@ import { Easing, Notifier } from 'react-native-notifier';
import { Provider } from "react-redux";
export default function RootLayout() {
const pathname = usePathname();
const { token, decryptToken, isLoading } = useAuthSession()
const handleNotificationPress = (category: any, content: any) => {
switch (category) {
case 'announcement':
router.push(`/announcement/${content}`);
break;
case 'discussion':
router.push(`/discussion/${content}`);
break;
case 'division':
router.push(`/division/${content}`);
break;
case 'member':
router.push(`/member/${content}`);
break;
case 'project':
router.push(`/project/${content}`);
break;
case 'announcement':
router.push(`/announcement/${content}`);
break;
// Add other cases as needed
default:
// Handle unknown category
console.warn(`Unknown category: ${category}`);
async function handleReadNotification(id: string, category: string, idContent: string) {
try {
const hasil = await decryptToken(String(token?.current))
const response = await apiReadOneNotification({ user: hasil, id: id })
pushToPage(category, idContent)
} catch (error) {
console.error(error)
}
};
}
useEffect(() => {
const unsubscribe = messaging().onMessage(async remoteMessage => {
const id = remoteMessage?.data?.id;
const category = remoteMessage?.data?.category;
const content = remoteMessage?.data?.content;
if (category != pathname.substring(1)) {
Notifier.showNotification({
title: remoteMessage.notification?.title,
description: remoteMessage.notification?.body,
duration: 3000,
animationDuration: 300,
showEasing: Easing.ease,
onPress: () => handleNotificationPress(category, content),
hideOnPress: true,
});
}
Notifier.showNotification({
title: remoteMessage.notification?.title,
description: remoteMessage.notification?.body,
duration: 3000,
animationDuration: 300,
showEasing: Easing.ease,
onPress: () => handleReadNotification(String(id), String(category), String(content)),
hideOnPress: true,
});
});
return unsubscribe;
}, []);
const { token, isLoading } = useAuthSession()
if (isLoading) {
return <Text>Loading...</Text>;