Skip to content

Commit

Permalink
feat: add read announcement logic
Browse files Browse the repository at this point in the history
  • Loading branch information
madkarmaa committed Sep 11, 2024
1 parent de023ca commit 74a9cad
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/layout/Announcements/AnnouncementCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
</script>

Expand All @@ -35,7 +50,7 @@
{#if $$slots.channel}
<div class="channel"><slot name="channel" /></div>
{/if}
<button class="read-more" on:click={() => (showContent = true)}>Read more</button>
<button class="read-more" on:click={showAnnouncement}>Read more</button>
</div>

<Dialogue bind:modalOpen={showContent} fullscreen>
Expand Down

0 comments on commit 74a9cad

Please sign in to comment.