diff options
| author | Fuwn <[email protected]> | 2024-04-14 23:15:58 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-04-14 23:15:58 -0700 |
| commit | 42b4aa7f02704b2ff11c54a7372f2604bec91cac (patch) | |
| tree | d24ce7a5397a5fb7bbaa7e0d8bbcf99e9ae7569c /src/lib | |
| parent | feat(popup): disable scroll while active (diff) | |
| download | due.moe-42b4aa7f02704b2ff11c54a7372f2604bec91cac.tar.xz due.moe-42b4aa7f02704b2ff11c54a7372f2604bec91cac.zip | |
feat(announcement): better format handling
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/Announcement.svelte | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/lib/Announcement.svelte b/src/lib/Announcement.svelte index 13e5622a..3b239a7c 100644 --- a/src/lib/Announcement.svelte +++ b/src/lib/Announcement.svelte @@ -14,11 +14,29 @@ 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 announcement && $announcementHash !== hash(announcement) && $announcementHash !== 0} <Popup fullscreen onLeave={dismiss}> - {announcement} + {#each maxWidth(announcement).split('\n') as line} + {line}<br /> + {/each} <p /> |