Skip to content

Commit

Permalink
Add cache buster to bell icon
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDaub committed Sep 25, 2024
1 parent f14ef4d commit 5a93f72
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/web/src/Bell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ const Bell = (props) => {
}
const isEligible =
address && eligible(props.allowlist, props.delegations, address);
const link = isEligible ? `/activity?address=${address}` : "/kiwipass-mint";

const [notificationCount, setNotificationCount] = useState(0);
const [readNotifications, setReadNotifications] = useState(0);
const [cacheBuster, setCacheBuster] = useState("");
const [documentTitle] = useState(document.title);
const [isFull, setIsFull] = useState(false);
const link = isEligible
? `/activity?address=${address}${
cacheBuster ? `&cacheBuster=${cacheBuster}` : ""
}`
: "/kiwipass-mint";

const handleClick = () => {
setIsFull(!isFull);
Expand All @@ -38,10 +43,13 @@ const Bell = (props) => {
const notifications = await fetchNotifications(address);
setReadNotifications(notifications.length);

const count = notifications.reduce((acc, notification) => {
return notification.timestamp > lastUpdate ? acc + 1 : acc;
}, 0);
setNotificationCount(count);
const newNotifications = notifications
.filter((elem) => elem.timestamp > lastUpdate)
.sort((a, b) => b.timestamp - a.timestamp);
if (newNotifications.length > 0) {
setCacheBuster(`0x${newNotifications[0].message.index}`);
}
setNotificationCount(newNotifications.length);
};
fetchAndUpdateNotifications();
}
Expand Down

0 comments on commit 5a93f72

Please sign in to comment.