From 9ab322751a732d8cbc1ddf4f2ecf5022d7242baa Mon Sep 17 00:00:00 2001 From: Marijn Besseling Date: Sun, 7 Sep 2025 20:56:09 +0200 Subject: WIP migration --- Blog/Components/Pages/Note.razor.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Blog/Components/Pages/Note.razor.js (limited to 'Blog/Components/Pages/Note.razor.js') 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 @@ +import { getById, debounce, writeError, resetLog } from "/common.module.js"; +import lzString from "/lz-string.module.js"; + +let input = undefined; +export function onLoad() { + input = getById("input"); + input.addEventListener("input", debounce(() => { + if (input.value === '') { + window.location.hash = '' + } + else { + window.location.hash = '#' + lzString.compressToEncodedURIComponent(input.value); + } + resetLog(); + }, 10)) + + window.addEventListener('hashchange', loadState); + loadState(); +} + +export function onUpdate() { + loadState(); +} + +function loadState() { + if (window.location.hash !== '') { + input.value = lzString.decompressFromEncodedURIComponent(window.location.hash.substring(1)); + if (input.value === '') { + //Hash but no content? + writeError("Failed to load note from url.") + } + } +} \ No newline at end of file -- cgit v1.2.3