diff --git a/routes/_utils/store.js b/routes/_utils/store.js new file mode 100644 index 0000000..7381a5d --- /dev/null +++ b/routes/_utils/store.js @@ -0,0 +1,31 @@ +import { Store } from 'svelte/store.js' + +const key = 'ui-store' + +class LocalStorageStore extends Store { + constructor(state) { + super(state) + if (process.browser) { + let cached = localStorage.getItem(key) + if (cached) { + this.set(JSON.parse(cached)) + } + } + } + + save() { + if (process.browser) { + localStorage.setItem(key, JSON.stringify(this._state)) + } + } +} + +const store = new LocalStorageStore({ + instanceNameInSearch: '' +}) + +if (process.browser) { + window.store = store +} + +export { store } \ No newline at end of file diff --git a/routes/index.html b/routes/index.html index dfa4e45..7367ebb 100644 --- a/routes/index.html +++ b/routes/index.html @@ -16,24 +16,23 @@