Add store for UUID and conditional loading of the LDB page for public/staff boards
This commit is contained in:
23
src/lib/stores/uuid.js
Normal file
23
src/lib/stores/uuid.js
Normal 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)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user