feat(notification): add click-to-open functionality and cleanup test notification
- Update useFirebaseNotificationProcessor to handle notification clicks by opening the URL from data.url. - Implement notificationclick event handler in sw.ts to redirect users when a notification is clicked. - Simplify the registration success notification in index.tsx by removing the unnecessary JSON body argument. - Ensure seamless navigation when users interact with push notifications by passing the URL through the notification payload.
This commit is contained in:
parent
2774037012
commit
58cf736e82
@ -16,6 +16,10 @@ export const useFirebaseNotificationProcessor = () => {
|
|||||||
title: data.title,
|
title: data.title,
|
||||||
description: data.body,
|
description: data.body,
|
||||||
icon: data.icon,
|
icon: data.icon,
|
||||||
|
onClick: () => {
|
||||||
|
if (!data.url) return;
|
||||||
|
open(data.url, '_blank'); // 打开通知
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -92,7 +92,7 @@ const server = Bun.serve({
|
|||||||
const [hasOldToken] = await Promise.all([
|
const [hasOldToken] = await Promise.all([
|
||||||
prisma.notificationToken.count({ where }).then(num => num > 0),
|
prisma.notificationToken.count({ where }).then(num => num > 0),
|
||||||
]);
|
]);
|
||||||
await sendNotification(token, { title: '通知已注册!', body: JSON.stringify({ hasOldToken }) });
|
await sendNotification(token, { title: '通知已注册!' });
|
||||||
if (hasOldToken) {
|
if (hasOldToken) {
|
||||||
return Response.json({
|
return Response.json({
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
@ -37,4 +37,10 @@ onBackgroundMessage(messaging, (payload: MessagePayload) => {
|
|||||||
self.registration.showNotification(notificationTitle, notificationOptions);
|
self.registration.showNotification(notificationTitle, notificationOptions);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.addEventListener('notificationclick', ev => {
|
||||||
|
const url = ev.notification.data.url;
|
||||||
|
if (!url) return;
|
||||||
|
open(url);
|
||||||
|
});
|
||||||
|
|
||||||
console.log('sw', self);
|
console.log('sw', self);
|
||||||
Loading…
Reference in New Issue
Block a user