mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-24 20:18:34 +00:00
Merge pull request #1091 from kasparsj/use-sessionStorage
Use sessionStorage for viewingPatternData and activePattern
This commit is contained in:
commit
55c7f2b575
@ -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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user