diff options
Diffstat (limited to 'src/lib/Announcement.svelte')
| -rw-r--r-- | src/lib/Announcement.svelte | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/src/lib/Announcement.svelte b/src/lib/Announcement.svelte index 40a11d33..7bcc9df7 100644 --- a/src/lib/Announcement.svelte +++ b/src/lib/Announcement.svelte @@ -1,53 +1,53 @@ <script lang="ts"> - import Popup from './Layout/Popup.svelte'; - import announcementHash from '$stores/announcementHash'; - import { env } from '$env/dynamic/public'; - import identity from '$stores/identity'; - - const announcement = env.PUBLIC_ANNOUNCEMENT; - const dismissButton = env.PUBLIC_ANNOUNCEMENT_DISMISS; - const loggedIn = $identity !== undefined && $identity.id !== -2; - - 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)); - }; - - const maxWidth = (input: string, max = 100) => { - let output = ''; - let line = ''; - - for (const word of input.split(' ')) { - if (line.length + word.length > max) { - output += line + '\n'; - line = ''; - } - - line += word + ' '; - } - - return output + line; - }; + import Popup from './Layout/Popup.svelte'; + import announcementHash from '$stores/announcementHash'; + import { env } from '$env/dynamic/public'; + import identity from '$stores/identity'; + + const announcement = env.PUBLIC_ANNOUNCEMENT; + const dismissButton = env.PUBLIC_ANNOUNCEMENT_DISMISS; + const loggedIn = $identity !== undefined && $identity.id !== -2; + + 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)); + }; + + const maxWidth = (input: string, max = 100) => { + let output = ''; + let line = ''; + + for (const word of input.split(' ')) { + if (line.length + word.length > max) { + output += line + '\n'; + line = ''; + } + + line += word + ' '; + } + + return output + line; + }; </script> {#if loggedIn && announcement && $announcementHash !== hash(announcement) && $announcementHash !== 0} - <Popup fullscreen onLeave={dismiss}> - {#each maxWidth(announcement).split('\n') as line} - {line}<br /> - {/each} + <Popup fullscreen onLeave={dismiss}> + {#each maxWidth(announcement).split('\n') as line} + {line}<br /> + {/each} - <p /> + <p /> - <button on:click={dismiss} class="dismiss">{dismissButton || 'Dismiss'}</button> - </Popup> + <button on:click={dismiss} class="dismiss">{dismissButton || 'Dismiss'}</button> + </Popup> {/if} <style> - .dismiss { - float: right; - } + .dismiss { + float: right; + } </style> |