diff options
| author | Marijn Besseling <njirambem@gmail.com> | 2025-09-07 20:56:09 +0200 |
|---|---|---|
| committer | Marijn Besseling <njirambem@gmail.com> | 2025-09-07 20:56:09 +0200 |
| commit | 9ab322751a732d8cbc1ddf4f2ecf5022d7242baa (patch) | |
| tree | 49abc49c7d148b2f575aa5daef32875d44729561 /Blog/Components/Pages/Note.razor.js | |
WIP migration
Diffstat (limited to 'Blog/Components/Pages/Note.razor.js')
| -rw-r--r-- | Blog/Components/Pages/Note.razor.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Blog/Components/Pages/Note.razor.js b/Blog/Components/Pages/Note.razor.js new file mode 100644 index 0000000..3d47d23 --- /dev/null +++ b/Blog/Components/Pages/Note.razor.js | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | import { getById, debounce, writeError, resetLog } from "/common.module.js"; | ||
| 2 | import lzString from "/lz-string.module.js"; | ||
| 3 | |||
| 4 | let input = undefined; | ||
| 5 | export function onLoad() { | ||
| 6 | input = getById("input"); | ||
| 7 | input.addEventListener("input", debounce(() => { | ||
| 8 | if (input.value === '') { | ||
| 9 | window.location.hash = '' | ||
| 10 | } | ||
| 11 | else { | ||
| 12 | window.location.hash = '#' + lzString.compressToEncodedURIComponent(input.value); | ||
| 13 | } | ||
| 14 | resetLog(); | ||
| 15 | }, 10)) | ||
| 16 | |||
| 17 | window.addEventListener('hashchange', loadState); | ||
| 18 | loadState(); | ||
| 19 | } | ||
| 20 | |||
| 21 | export function onUpdate() { | ||
| 22 | loadState(); | ||
| 23 | } | ||
| 24 | |||
| 25 | function loadState() { | ||
| 26 | if (window.location.hash !== '') { | ||
| 27 | input.value = lzString.decompressFromEncodedURIComponent(window.location.hash.substring(1)); | ||
| 28 | if (input.value === '') { | ||
| 29 | //Hash but no content? | ||
| 30 | writeError("Failed to load note from url.") | ||
| 31 | } | ||
| 32 | } | ||
| 33 | } \ No newline at end of file | ||