Skip to content

Commit

Permalink
Merge pull request guardian#4264 from bbc/t1699-notification-banner-bug
Browse files Browse the repository at this point in the history
modifications to correct bug linked to clean cookie operation
  • Loading branch information
rebecca-thompson authored Apr 23, 2024
2 parents 08f695c + 635e546 commit c3eca93
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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[] => {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c3eca93

Please sign in to comment.