Add store for UUID and conditional loading of the LDB page for public/staff boards

This commit is contained in:
Fred Boniface
2023-06-19 13:22:17 +01:00
parent e4f18c389f
commit 847545760b
4 changed files with 137 additions and 2 deletions

23
src/lib/stores/uuid.js Normal file
View File

@@ -0,0 +1,23 @@
import { writable } from 'svelte/store'
import { browser } from '$app/environment';
export const uuid = writable(fromLocalStorage('uuid', null))
toLocalStorage(uuid, 'uuid');
function fromLocalStorage(storageKey, fallback) {
if (browser) {
const storedValue = localStorage.getItem(storageKey);
if (storedValue !== 'undefined') {
return storedValue
}
}
return fallback
}
function toLocalStorage(store, storageKey) {
if (browser) {
store.subscribe(value => {
localStorage.setItem(storageKey, value)
})
}
}