Open History to see the last commit
1import { useEffect, useRef } from "react";
2import * as Notifications from "expo-notifications";
3import { useLinkTo } from "@react-navigation/native";
4
5import { routeAgentNotificationResponseOnce } from "./notificationPayload";
6import { consumeLastAgentNotificationResponse } from "./notificationResponseConsumer";
7
8export function useAgentNotificationNavigation(): void {
9 const linkTo = useLinkTo();
10 const handledResponseIds = useRef(new Set<string>());
11
12 useEffect(() => {
13 const handleResponse = (response: Notifications.NotificationResponse): void => {
14 routeAgentNotificationResponseOnce({
15 handledResponseIds: handledResponseIds.current,
16 response,
17 navigate: linkTo,
18 });
19 };
20
21 const subscription = Notifications.addNotificationResponseReceivedListener(handleResponse);
22 void consumeLastAgentNotificationResponse({
23 getLastResponse: () => Notifications.getLastNotificationResponseAsync(),
24 clearLastResponse: () => Notifications.clearLastNotificationResponseAsync(),
25 handleResponse,
26 });
27
28 return () => {
29 subscription.remove();
30 };
31 }, [linkTo]);
32}