Skip to content

Commit 9c6f1b0

Browse files
committed
fix: Set announcement as read when opened
1 parent b9aa549 commit 9c6f1b0

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/routes/announcements/AnnouncementBanner.svelte

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,34 @@
1313
1414
$: {
1515
if ($query.data?.announcements && $query.data.announcements.length > 0) {
16-
const announcement = $query.data.announcements[0];
17-
if (!$read_announcements.has(announcement.id)) {
16+
const nonArchived = $query.data.announcements.filter((a) => !a.archived_at);
17+
const announcement = nonArchived[0];
18+
19+
if (announcement && !$read_announcements.has(announcement.id)) {
1820
latestUnreadAnnouncement = announcement;
1921
} else {
2022
latestUnreadAnnouncement = undefined;
2123
}
2224
}
2325
}
2426
25-
const handleClick = () =>
26-
latestUnreadAnnouncement && goto(`/announcements/${latestUnreadAnnouncement.id}`);
27+
function setAsRead() {
28+
if (!latestUnreadAnnouncement) return;
29+
$read_announcements.add(latestUnreadAnnouncement.id);
30+
localStorage.setItem('read_announcements', JSON.stringify(Array.from($read_announcements)));
31+
latestUnreadAnnouncement = undefined;
32+
}
33+
34+
function handleClick() {
35+
if (latestUnreadAnnouncement) {
36+
goto(`/announcements/${latestUnreadAnnouncement.id}`);
37+
setAsRead();
38+
}
39+
}
2740
2841
function handleClose() {
2942
if (latestUnreadAnnouncement && browser) {
30-
$read_announcements.add(latestUnreadAnnouncement.id);
31-
localStorage.setItem('read_announcements', JSON.stringify(Array.from($read_announcements)));
32-
latestUnreadAnnouncement = undefined;
43+
setAsRead();
3344
}
3445
}
3546

0 commit comments

Comments
 (0)