From 635e546e3afa50dabcde565469797368117395ea Mon Sep 17 00:00:00 2001 From: AndyKilmory Date: Tue, 23 Apr 2024 14:30:04 +0100 Subject: [PATCH] modifications to correct bug linked to clean cookie operation --- .../gr-notifications-banner/gr-notifications-banner.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kahuna/public/js/components/gr-notifications-banner/gr-notifications-banner.tsx b/kahuna/public/js/components/gr-notifications-banner/gr-notifications-banner.tsx index e009744a85..66497d679f 100644 --- a/kahuna/public/js/components/gr-notifications-banner/gr-notifications-banner.tsx +++ b/kahuna/public/js/components/gr-notifications-banner/gr-notifications-banner.tsx @@ -80,7 +80,11 @@ const todayStr = (): string => { const getCookie = (cookieName: string): string => { const decodedCookie = decodeURIComponent(document.cookie); const cookieArray = decodedCookie.split(';'); - return cookieArray.find((cookie) => cookie.trim().startsWith(cookieName)); + const temp = cookieArray.find((cookie) => cookie.trim().startsWith(cookieName)); + if (temp) { + return temp.trim().replace((cookieName + "="), ""); + } + return null; }; const mergeArraysByKey = (array1: Notification[], array2: Notification[], key: keyof Notification): Notification[] => { @@ -171,7 +175,7 @@ const NotificationsBanner: React.FC = () => { const current_notif_ids = announce.map(ann => ann.announceId).join(","); const notif_ids = notif_cookie.split(','); const new_notif_ids = notif_ids.filter(n_id => current_notif_ids.includes(n_id)).join(","); - document.cookie = (`${NOTIFICATION_COOKIE}=${new_notif_ids}; max-age=${cookie_age}`); + document.cookie = `${NOTIFICATION_COOKIE}=${new_notif_ids}; max-age=${cookie_age}`; } // Clean up the event listener when the component unmounts