From 3cfe9b78267a090284d2d89305087f247882000c Mon Sep 17 00:00:00 2001 From: Brandon Cohen Date: Wed, 26 Feb 2025 02:12:36 -0600 Subject: [PATCH] feat: added the PWA badge indicator for requests pending (#3411) refactor: removed unnecessary code when sending web push notification fix: moved all notify user logic into webpush refactor: n refactor: remove all unnecessary prettier changes fix: n fix: n fix: n fix: n fix: increment sw version fix: n --- src/components/Layout/MobileMenu/index.tsx | 6 ++-- src/pages/_app.tsx | 36 +++++++--------------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/components/Layout/MobileMenu/index.tsx b/src/components/Layout/MobileMenu/index.tsx index 552e5326a..e89deda16 100644 --- a/src/components/Layout/MobileMenu/index.tsx +++ b/src/components/Layout/MobileMenu/index.tsx @@ -254,9 +254,11 @@ const MobileMenu = ({ router.pathname.match(link.activeRegExp) ? 'border-indigo-600 from-indigo-700 to-purple-700' : 'border-indigo-500 from-indigo-600 to-purple-600' - } !px-1 !py-[1px] leading-none`} + } flex h-4 w-4 items-center justify-center !px-[9px] !py-[9px] text-[9px]`} > - {pendingRequestsCount} + {pendingRequestsCount > 99 + ? '99+' + : pendingRequestsCount} )} diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 5269e87b8..d24c2f87d 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -140,32 +140,18 @@ const CoreApp: Omit = ({ clearAppBadge?: () => Promise; }; - const handleBadgeUpdate = () => { - if ('setAppBadge' in newNavigator) { - if ( - !router.pathname.match(/(login|setup|resetpassword)/) && - hasPermission(Permission.ADMIN) - ) { - requestsCount().then((data) => { - if (data.pending > 0) { - newNavigator.setAppBadge?.(data.pending); - } else { - newNavigator.clearAppBadge?.(); - } - }); - } else { - newNavigator.clearAppBadge?.(); - } + if ('setAppBadge' in navigator) { + if ( + !router.pathname.match(/(login|setup|resetpassword)/) && + hasPermission(Permission.ADMIN) + ) { + requestsCount().then((data) => + newNavigator?.setAppBadge?.(data.pending) + ); + } else { + newNavigator?.clearAppBadge?.(); } - }; - - handleBadgeUpdate(); - - window.addEventListener('focus', handleBadgeUpdate); - - return () => { - window.removeEventListener('focus', handleBadgeUpdate); - }; + } }, [hasPermission, router.pathname]); if (router.pathname.match(/(login|setup|resetpassword)/)) {