Merge pull request #1091 from kasparsj/use-sessionStorage

Use sessionStorage for viewingPatternData and activePattern
This commit is contained in:
Felix Roos 2024-05-13 06:31:20 +02:00 committed by GitHub
commit 55c7f2b575
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,16 +21,25 @@ export const patternFilterName = {
user: 'user', user: 'user',
}; };
export let $viewingPatternData = persistentAtom( const sessionAtom = (name, initial = undefined) => {
'viewingPatternData', const storage = typeof sessionStorage !== 'undefined' ? sessionStorage : {};
{ const store = atom(typeof storage[name] !== 'undefined' ? storage[name] : initial);
id: '', store.listen((newValue) => {
code: '', if (typeof newValue === 'undefined') {
collection: collectionName.user, delete storage[name];
created_at: Date.now(), } else {
}, storage[name] = newValue;
{ listen: false }, }
); });
return store;
};
export let $viewingPatternData = sessionAtom('viewingPatternData', {
id: '',
code: '',
collection: collectionName.user,
created_at: Date.now(),
});
export const getViewingPatternData = () => { export const getViewingPatternData = () => {
return parseJSON($viewingPatternData.get()); return parseJSON($viewingPatternData.get());
@ -68,7 +77,7 @@ export async function loadDBPatterns() {
} }
// reason: https://github.com/tidalcycles/strudel/issues/857 // reason: https://github.com/tidalcycles/strudel/issues/857
const $activePattern = persistentAtom('activePattern', '', { listen: false }); const $activePattern = sessionAtom('activePattern', '');
export function setActivePattern(key) { export function setActivePattern(key) {
$activePattern.set(key); $activePattern.set(key);