From f4d25ee1275d4783933ec173a5bc60b99181d855 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Mon, 1 Apr 2024 17:33:05 -0700
Subject: feat(layout): announcement feature

---
 src/lib/Announcement.svelte | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 src/lib/Announcement.svelte

(limited to 'src/lib/Announcement.svelte')

diff --git a/src/lib/Announcement.svelte b/src/lib/Announcement.svelte
new file mode 100644
index 00000000..13e5622a
--- /dev/null
+++ b/src/lib/Announcement.svelte
@@ -0,0 +1,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>
-- 
cgit v1.2.3

