Test move this out of component mount
It needs to run faster
This commit is contained in:
parent
e41e49884f
commit
098df0ad2c
1 changed files with 35 additions and 19 deletions
|
@ -15,6 +15,22 @@ import Link from './link';
|
||||||
import Modal from './modal';
|
import Modal from './modal';
|
||||||
import Notification from './notification';
|
import Notification from './notification';
|
||||||
|
|
||||||
|
{
|
||||||
|
if ('serviceWorker' in navigator) {
|
||||||
|
console.log('👂👂👂 Listen to message');
|
||||||
|
navigator.serviceWorker.addEventListener('message', (event) => {
|
||||||
|
console.log('💥💥💥 Message event', event);
|
||||||
|
const { type, id, accessToken } = event?.data || {};
|
||||||
|
if (type === 'notification') {
|
||||||
|
states.routeNotification = {
|
||||||
|
id,
|
||||||
|
accessToken,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default memo(function NotificationService() {
|
export default memo(function NotificationService() {
|
||||||
if (!('serviceWorker' in navigator)) return null;
|
if (!('serviceWorker' in navigator)) return null;
|
||||||
|
|
||||||
|
@ -82,25 +98,25 @@ export default memo(function NotificationService() {
|
||||||
})();
|
})();
|
||||||
}, [id, accessToken]);
|
}, [id, accessToken]);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
// useLayoutEffect(() => {
|
||||||
// Listen to message from service worker
|
// // Listen to message from service worker
|
||||||
const handleMessage = (event) => {
|
// const handleMessage = (event) => {
|
||||||
console.log('💥💥💥 Message event', event);
|
// console.log('💥💥💥 Message event', event);
|
||||||
const { type, id, accessToken } = event?.data || {};
|
// const { type, id, accessToken } = event?.data || {};
|
||||||
if (type === 'notification') {
|
// if (type === 'notification') {
|
||||||
states.routeNotification = {
|
// states.routeNotification = {
|
||||||
id,
|
// id,
|
||||||
accessToken,
|
// accessToken,
|
||||||
};
|
// };
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
console.log('👂👂👂 Listen to message');
|
// console.log('👂👂👂 Listen to message');
|
||||||
navigator.serviceWorker.addEventListener('message', handleMessage);
|
// navigator.serviceWorker.addEventListener('message', handleMessage);
|
||||||
return () => {
|
// return () => {
|
||||||
console.log('👂👂👂 Remove listen to message');
|
// console.log('👂👂👂 Remove listen to message');
|
||||||
navigator.serviceWorker.removeEventListener('message', handleMessage);
|
// navigator.serviceWorker.removeEventListener('message', handleMessage);
|
||||||
};
|
// };
|
||||||
}, []);
|
// }, []);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (navigator?.clearAppBadge) {
|
if (navigator?.clearAppBadge) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue