aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Announcement.svelte
blob: 13e5622a7abb495a994a37eafdc101553d36f042 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<script lang="ts">
	import Popup from './Popup.svelte';
	import announcementHash from '$stores/announcementHash';
	import { env } from '$env/dynamic/public';

	const announcement = env.PUBLIC_ANNOUNCEMENT;
	const dismissButton = env.PUBLIC_ANNOUNCEMENT_DISMISS;

	const hash = (s: string) =>
		s
			.split('')
			.reduce((previous, current) => ((previous << 5) - previous + current.charCodeAt(0)) | 0, 0);

	const dismiss = () => {
		if (announcement) announcementHash.set(hash(announcement));
	};
</script>

{#if announcement && $announcementHash !== hash(announcement) && $announcementHash !== 0}
	<Popup fullscreen onLeave={dismiss}>
		{announcement}

		<p />

		<button on:click={dismiss} class="dismiss">{dismissButton || 'Dismiss'}</button>
	</Popup>
{/if}

<style>
	.dismiss {
		float: right;
	}
</style>