From 74a9cadf7d501c721f01238aca0d19326b228b8d Mon Sep 17 00:00:00 2001 From: madkarmaa Date: Wed, 11 Sep 2024 12:54:51 +0200 Subject: [PATCH] feat: add read announcement logic --- .../Announcements/AnnouncementCard.svelte | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/layout/Announcements/AnnouncementCard.svelte b/src/layout/Announcements/AnnouncementCard.svelte index 006797a9..807bdce6 100644 --- a/src/layout/Announcements/AnnouncementCard.svelte +++ b/src/layout/Announcements/AnnouncementCard.svelte @@ -13,8 +13,23 @@ let showContent = false; let read: boolean; + function isAnnouncementRead(): boolean { + return (localStorage.getItem('read_announcements') ?? '').split(',').includes(String(id)); + } + + function setAnnouncementRead() { + const ids = (localStorage.getItem('read_announcements') ?? '').split(',').filter((id) => !!id); + if (!ids.includes(String(id))) + localStorage.setItem('read_announcements', ids.concat(String(id)).join(',')); + } + + const showAnnouncement = () => { + showContent = true; + setAnnouncementRead(); + }; + onMount(() => { - read = (localStorage.getItem('read_announcements') as string).split(',').includes(String(id)); + read = isAnnouncementRead(); }); @@ -35,7 +50,7 @@ {#if $$slots.channel}
{/if} - +