mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-22 19:18:31 +00:00
fix: do not sync activePattern between tabs
+ only deselect activePattern if code in url differs
This commit is contained in:
parent
1f16ebc5b2
commit
faaed61384
@ -17,7 +17,15 @@ import { prebake } from './prebake.mjs';
|
|||||||
import * as tunes from './tunes.mjs';
|
import * as tunes from './tunes.mjs';
|
||||||
import PlayCircleIcon from '@heroicons/react/20/solid/PlayCircleIcon';
|
import PlayCircleIcon from '@heroicons/react/20/solid/PlayCircleIcon';
|
||||||
import { themes } from './themes.mjs';
|
import { themes } from './themes.mjs';
|
||||||
import { settingsMap, useSettings, setLatestCode, updateUserCode, setActivePattern } from '../settings.mjs';
|
import {
|
||||||
|
settingsMap,
|
||||||
|
useSettings,
|
||||||
|
setLatestCode,
|
||||||
|
updateUserCode,
|
||||||
|
setActivePattern,
|
||||||
|
getActivePattern,
|
||||||
|
getUserPattern,
|
||||||
|
} from '../settings.mjs';
|
||||||
import Loader from './Loader';
|
import Loader from './Loader';
|
||||||
import { settingPatterns } from '../settings.mjs';
|
import { settingPatterns } from '../settings.mjs';
|
||||||
import { code2hash, hash2code } from './helpers.mjs';
|
import { code2hash, hash2code } from './helpers.mjs';
|
||||||
@ -131,7 +139,6 @@ export function Repl({ embedded = false }) {
|
|||||||
isLineWrappingEnabled,
|
isLineWrappingEnabled,
|
||||||
panelPosition,
|
panelPosition,
|
||||||
isZen,
|
isZen,
|
||||||
activePattern,
|
|
||||||
} = useSettings();
|
} = useSettings();
|
||||||
|
|
||||||
const paintOptions = useMemo(() => ({ fontFamily }), [fontFamily]);
|
const paintOptions = useMemo(() => ({ fontFamily }), [fontFamily]);
|
||||||
@ -177,7 +184,12 @@ export function Repl({ embedded = false }) {
|
|||||||
let msg;
|
let msg;
|
||||||
if (decoded) {
|
if (decoded) {
|
||||||
setCode(decoded);
|
setCode(decoded);
|
||||||
setActivePattern('');
|
const activePattern = getActivePattern();
|
||||||
|
if (getUserPattern(activePattern)?.code !== decoded) {
|
||||||
|
// code in url is not the last active patterns code => must be something else
|
||||||
|
// deselect last active pattern to not overwrite it on next evaluation
|
||||||
|
setActivePattern('');
|
||||||
|
}
|
||||||
msg = `I have loaded the code from the URL.`;
|
msg = `I have loaded the code from the URL.`;
|
||||||
} else if (latestCode) {
|
} else if (latestCode) {
|
||||||
setCode(latestCode);
|
setCode(latestCode);
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import {
|
|||||||
newUserPattern,
|
newUserPattern,
|
||||||
renameActivePattern,
|
renameActivePattern,
|
||||||
setActivePattern,
|
setActivePattern,
|
||||||
|
useActivePattern,
|
||||||
useSettings,
|
useSettings,
|
||||||
} from '../../settings.mjs';
|
} from '../../settings.mjs';
|
||||||
import * as tunes from '../tunes.mjs';
|
import * as tunes from '../tunes.mjs';
|
||||||
@ -19,7 +20,8 @@ function classNames(...classes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function PatternsTab({ context }) {
|
export function PatternsTab({ context }) {
|
||||||
const { userPatterns, activePattern } = useSettings();
|
const { userPatterns } = useSettings();
|
||||||
|
const activePattern = useActivePattern();
|
||||||
const isExample = useMemo(() => activePattern && !!tunes[activePattern], [activePattern]);
|
const isExample = useMemo(() => activePattern && !!tunes[activePattern], [activePattern]);
|
||||||
return (
|
return (
|
||||||
<div className="px-4 w-full dark:text-white text-stone-900 space-y-4 pb-4">
|
<div className="px-4 w-full dark:text-white text-stone-900 space-y-4 pb-4">
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { persistentMap } from '@nanostores/persistent';
|
import { persistentMap, persistentAtom } from '@nanostores/persistent';
|
||||||
import { useStore } from '@nanostores/react';
|
import { useStore } from '@nanostores/react';
|
||||||
import { register } from '@strudel.cycles/core';
|
import { register } from '@strudel.cycles/core';
|
||||||
import * as tunes from './repl/tunes.mjs';
|
import * as tunes from './repl/tunes.mjs';
|
||||||
@ -20,11 +20,23 @@ export const defaultSettings = {
|
|||||||
soundsFilter: 'all',
|
soundsFilter: 'all',
|
||||||
panelPosition: 'bottom',
|
panelPosition: 'bottom',
|
||||||
userPatterns: '{}',
|
userPatterns: '{}',
|
||||||
activePattern: '',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const settingsMap = persistentMap('strudel-settings', defaultSettings);
|
export const settingsMap = persistentMap('strudel-settings', defaultSettings);
|
||||||
|
|
||||||
|
// active pattern is separate, because it shouldn't sync state across tabs
|
||||||
|
// reason: https://github.com/tidalcycles/strudel/issues/857
|
||||||
|
const $activePattern = persistentAtom('activePattern', '', { listen: false });
|
||||||
|
export function setActivePattern(key) {
|
||||||
|
$activePattern.set(key);
|
||||||
|
}
|
||||||
|
export function getActivePattern() {
|
||||||
|
return $activePattern.get();
|
||||||
|
}
|
||||||
|
export function useActivePattern() {
|
||||||
|
return useStore($activePattern);
|
||||||
|
}
|
||||||
|
|
||||||
export function useSettings() {
|
export function useSettings() {
|
||||||
const state = useStore(settingsMap);
|
const state = useStore(settingsMap);
|
||||||
return {
|
return {
|
||||||
@ -117,7 +129,7 @@ export function getUserPattern(key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function renameActivePattern() {
|
export function renameActivePattern() {
|
||||||
let activePattern = getSetting('activePattern');
|
let activePattern = getActivePattern();
|
||||||
let userPatterns = getUserPatterns();
|
let userPatterns = getUserPatterns();
|
||||||
if (!userPatterns[activePattern]) {
|
if (!userPatterns[activePattern]) {
|
||||||
alert('Cannot rename examples');
|
alert('Cannot rename examples');
|
||||||
@ -140,7 +152,7 @@ export function renameActivePattern() {
|
|||||||
|
|
||||||
export function updateUserCode(code) {
|
export function updateUserCode(code) {
|
||||||
const userPatterns = getUserPatterns();
|
const userPatterns = getUserPatterns();
|
||||||
let activePattern = getSetting('activePattern');
|
let activePattern = getActivePattern();
|
||||||
// check if code is that of an example tune
|
// check if code is that of an example tune
|
||||||
const [example] = Object.entries(tunes).find(([_, tune]) => tune === code) || [];
|
const [example] = Object.entries(tunes).find(([_, tune]) => tune === code) || [];
|
||||||
if (example && (!activePattern || activePattern === example)) {
|
if (example && (!activePattern || activePattern === example)) {
|
||||||
@ -161,7 +173,7 @@ export function updateUserCode(code) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function deleteActivePattern() {
|
export function deleteActivePattern() {
|
||||||
let activePattern = getSetting('activePattern');
|
let activePattern = getActivePattern();
|
||||||
if (!activePattern) {
|
if (!activePattern) {
|
||||||
console.warn('cannot delete: no pattern selected');
|
console.warn('cannot delete: no pattern selected');
|
||||||
return;
|
return;
|
||||||
@ -179,7 +191,7 @@ export function deleteActivePattern() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function duplicateActivePattern() {
|
export function duplicateActivePattern() {
|
||||||
let activePattern = getSetting('activePattern');
|
let activePattern = getActivePattern();
|
||||||
let latestCode = getSetting('latestCode');
|
let latestCode = getSetting('latestCode');
|
||||||
if (!activePattern) {
|
if (!activePattern) {
|
||||||
console.warn('cannot duplicate: no pattern selected');
|
console.warn('cannot duplicate: no pattern selected');
|
||||||
@ -191,10 +203,6 @@ export function duplicateActivePattern() {
|
|||||||
setActivePattern(activePattern);
|
setActivePattern(activePattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setActivePattern(key) {
|
|
||||||
settingsMap.setKey('activePattern', key);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function importUserPatternJSON(jsonString) {}
|
export function importUserPatternJSON(jsonString) {}
|
||||||
|
|
||||||
export async function importPatterns(fileList) {
|
export async function importPatterns(fileList) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user