Skip to content

Commit

Permalink
Merge branch 'stwong2/imp-71-connect-notifications-to-updates-screen'…
Browse files Browse the repository at this point in the history
… of https://github.com/calblueprint/impact-fund into stephanie/deployment
  • Loading branch information
ronniebeggs committed Jun 5, 2024
2 parents 4a2eb15 + 0305e34 commit 0074a75
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 43 deletions.
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Ignore the PR template
/.github
/ios
/ios
/supabase
Binary file modified assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 6 additions & 40 deletions src/app/(BottomTabNavigation)/AllCases/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// import * as Linking from 'expo-linking';
import * as Notifications from 'expo-notifications';
import { router } from 'expo-router';
import React, { useContext, useState, useEffect, useRef } from 'react';
import React, { useContext, useEffect, useRef } from 'react';
import { FlatList, Text, View } from 'react-native';

import styles from './styles';
Expand Down Expand Up @@ -31,12 +31,10 @@ Notifications.setNotificationHandler({
});

function CasesScreen() {
const notificationListener = useRef<Notifications.Subscription>();
const responseListener = useRef<Notifications.Subscription>();

const { allCases, loading } = useContext(CaseContext);
const { session } = useSession();
const [notificationResponse, setNotificationResponse] = useState<string>('');

// const [url, setUrl] = useState<Linking.ParsedURL | null>(null);

Expand Down Expand Up @@ -87,49 +85,18 @@ function CasesScreen() {
});
}

notificationListener.current =
Notifications.addNotificationReceivedListener(notification => {
const updateId = notification.request.content.data.updateId;
const debugString =
'NotificationRecieved: ' +
notification +
', ' +
notification.request +
', ' +
notification.request.content +
', ' +
notification.request.content.data;
console.log(debugString);
setNotificationResponse(debugString);
router.push(`/AllCases/Updates/UpdateView/${updateId}`);
});

// triggered when a user presses on the notification
responseListener.current =
Notifications.addNotificationResponseReceivedListener(response => {
const updateId = response.notification.request.content.data.updateId;
const debugString =
'NotificationResponseRecieved: ' +
response +
', ' +
response.notification +
', ' +
response.notification.request +
', ' +
response.notification.request.content +
', ' +
response.notification.request.content.data;
console.log(debugString);
setNotificationResponse(debugString);
const caseId = response.notification.request.content.data.updateId;
router.push(`/AllCases/CaseScreen/${caseId}`);
router.push(`/AllCases/Updates/${caseId}`);
router.push(`/AllCases/Updates/UpdateView/${updateId}`);
});

return () => {
Notifications.removeNotificationSubscription(
notificationListener.current!,
);

return () =>
Notifications.removeNotificationSubscription(responseListener.current!);
};
}, []);

return (
Expand All @@ -143,7 +110,6 @@ function CasesScreen() {
ListHeaderComponent={() => (
<>
<View style={styles.headerContainer}>
<Text>Notifications Debug: {notificationResponse}</Text>
<Text style={fonts.tabHeading}>My Cases</Text>
</View>
</>
Expand Down
5 changes: 3 additions & 2 deletions supabase/functions/push/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
*/
Deno.serve(async req => {
// fetch the notifcation request from the supabase edge function
const { update, expoPushToken, category, updateId } = await req.json();
const { update, expoPushToken, category, updateId, caseUUID } =
await req.json();

const res = await fetch('https://exp.host/--/api/v2/push/send', {
method: 'POST',
Expand All @@ -22,7 +23,7 @@ Deno.serve(async req => {
sound: 'default',
title: category,
body: update,
data: { updateId: updateId },
data: { updateId: updateId, caseId: caseUUID },
}),
}).then(res => res.json());

Expand Down

0 comments on commit 0074a75

Please sign in to comment.