mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-23 19:48:31 +00:00
state
This commit is contained in:
parent
1e2c26123b
commit
1bc86c359e
@ -18,6 +18,7 @@ import {
|
|||||||
settingsMap,
|
settingsMap,
|
||||||
updateUserCode,
|
updateUserCode,
|
||||||
useSettings,
|
useSettings,
|
||||||
|
useActivePattern,
|
||||||
} from '../settings.mjs';
|
} from '../settings.mjs';
|
||||||
import { Header } from './Header';
|
import { Header } from './Header';
|
||||||
import Loader from './Loader';
|
import Loader from './Loader';
|
||||||
@ -33,7 +34,7 @@ export const ReplContext = createContext(null);
|
|||||||
|
|
||||||
const { latestCode } = settingsMap.get();
|
const { latestCode } = settingsMap.get();
|
||||||
|
|
||||||
let modulesLoading, presets, drawContext, clearCanvas, isIframe;
|
let modulesLoading, presets, drawContext, clearCanvas, isIframe, viewingPatternID;
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
initAudioOnFirstClick();
|
initAudioOnFirstClick();
|
||||||
modulesLoading = loadModules();
|
modulesLoading = loadModules();
|
||||||
@ -140,8 +141,10 @@ export function Repl({ embedded = false }) {
|
|||||||
|
|
||||||
const handleTogglePlay = async () => editorRef.current?.toggle();
|
const handleTogglePlay = async () => editorRef.current?.toggle();
|
||||||
|
|
||||||
// payload = {reset: boolean, code: string, evaluate: boolean}
|
// payload = {reset?: boolean, code?: string, evaluate?: boolean, patternID?: string }
|
||||||
const handleUpdate = async ({ reset = false, code = null, evaluate = true }) => {
|
const handleUpdate = async (payload) => {
|
||||||
|
const { reset = false, code = null, evaluate = true, patternID = null } = payload;
|
||||||
|
console.log(payload);
|
||||||
if (reset) {
|
if (reset) {
|
||||||
clearCanvas();
|
clearCanvas();
|
||||||
resetLoadedSounds();
|
resetLoadedSounds();
|
||||||
@ -150,9 +153,15 @@ export function Repl({ embedded = false }) {
|
|||||||
}
|
}
|
||||||
if (code != null) {
|
if (code != null) {
|
||||||
editorRef.current.setCode(code);
|
editorRef.current.setCode(code);
|
||||||
|
viewingPatternID = patternID;
|
||||||
}
|
}
|
||||||
if (evaluate && isDirty) {
|
console.log(isDirty);
|
||||||
|
if (evaluate) {
|
||||||
editorRef.current.evaluate();
|
editorRef.current.evaluate();
|
||||||
|
|
||||||
|
if (viewingPatternID != null) {
|
||||||
|
setActivePattern(viewingPatternID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const handleShuffle = async () => {
|
const handleShuffle = async () => {
|
||||||
|
|||||||
@ -46,8 +46,7 @@ export function PatternsTab({ context }) {
|
|||||||
const isExample = useMemo(() => activePattern && !!tunes[activePattern], [activePattern]);
|
const isExample = useMemo(() => activePattern && !!tunes[activePattern], [activePattern]);
|
||||||
const onPatternClick = (key, data) => {
|
const onPatternClick = (key, data) => {
|
||||||
const { code } = data;
|
const { code } = data;
|
||||||
setActivePattern(key);
|
context.handleUpdate({ patternID: key, code, evaluate: false });
|
||||||
context.handleUpdate({ code, evaluate: false });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const examplePatterns = {};
|
const examplePatterns = {};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user