diff options
| author | Fuwn <[email protected]> | 2024-04-01 17:33:05 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-04-01 17:33:05 -0700 |
| commit | f4d25ee1275d4783933ec173a5bc60b99181d855 (patch) | |
| tree | b1e9bc225cef7b12dc70c1de91e5e189e9060787 /src | |
| parent | feat(sequelspy): show days instead of weeks for long (diff) | |
| download | due.moe-f4d25ee1275d4783933ec173a5bc60b99181d855.tar.xz due.moe-f4d25ee1275d4783933ec173a5bc60b99181d855.zip | |
feat(layout): announcement feature
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/Announcement.svelte | 33 | ||||
| -rw-r--r-- | src/routes/+layout.svelte | 3 | ||||
| -rw-r--r-- | src/stores/announcementHash.ts | 12 |
3 files changed, 48 insertions, 0 deletions
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> diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index d5409f9a..98544a75 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -25,6 +25,7 @@ import subtitles from '$lib/Data/Static/subtitles.json'; import settingsSyncPulled from '$stores/settingsSyncPulled'; import settingsSyncTimes from '$stores/settingsSyncTimes'; + import Announcement from '$lib/Announcement.svelte'; injectSpeedInsights(); @@ -117,6 +118,8 @@ <HeadTitle /> +<Announcement /> + <div class="container"> <div class="card card-centered header"> <div> diff --git a/src/stores/announcementHash.ts b/src/stores/announcementHash.ts new file mode 100644 index 00000000..4a44d670 --- /dev/null +++ b/src/stores/announcementHash.ts @@ -0,0 +1,12 @@ +import { browser } from '$app/environment'; +import { writable } from 'svelte/store'; + +const announcementHash = writable<number>( + browser ? parseInt(localStorage.getItem('announcementHash') || '1') : 0 +); + +announcementHash.subscribe((value) => { + if (browser) localStorage.setItem('announcementHash', value.toString()); +}); + +export default announcementHash; |