From 02b9bd82cf682c1ca12c5135ccf2a345bd69380b Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Sat, 6 Jan 2024 17:33:24 -0500 Subject: [PATCH] highlight viewing pattern --- website/src/repl/Repl.jsx | 17 ++++++++-------- website/src/repl/panel/PatternsTab.jsx | 28 ++++++++++++++++++++------ website/src/settings.mjs | 13 ++++++++++++ 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/website/src/repl/Repl.jsx b/website/src/repl/Repl.jsx index 6756ac5e..62839ecd 100644 --- a/website/src/repl/Repl.jsx +++ b/website/src/repl/Repl.jsx @@ -18,7 +18,8 @@ import { settingsMap, updateUserCode, useSettings, - useActivePattern, + getViewingPattern, + setViewingPattern, } from '../settings.mjs'; import { Header } from './Header'; import Loader from './Loader'; @@ -34,7 +35,7 @@ export const ReplContext = createContext(null); const { latestCode } = settingsMap.get(); -let modulesLoading, presets, drawContext, clearCanvas, isIframe, viewingPatternID; +let modulesLoading, presets, drawContext, clearCanvas, isIframe; if (typeof window !== 'undefined') { initAudioOnFirstClick(); modulesLoading = loadModules(); @@ -76,7 +77,11 @@ export function Repl({ embedded = false }) { updateUserCode(code); // setPending(false); setLatestCode(code); + const viewingPatternID = getViewingPattern(); window.location.hash = '#' + code2hash(code); + if (viewingPatternID != null) { + setActivePattern(viewingPatternID); + } }, bgFill: false, }); @@ -144,7 +149,6 @@ export function Repl({ embedded = false }) { // payload = {reset?: boolean, code?: string, evaluate?: boolean, patternID?: string } const handleUpdate = async (payload) => { const { reset = false, code = null, evaluate = true, patternID = null } = payload; - console.log(payload); if (reset) { clearCanvas(); resetLoadedSounds(); @@ -153,15 +157,10 @@ export function Repl({ embedded = false }) { } if (code != null) { editorRef.current.setCode(code); - viewingPatternID = patternID; + setViewingPattern(patternID); } - console.log(isDirty); if (evaluate) { editorRef.current.evaluate(); - - if (viewingPatternID != null) { - setActivePattern(viewingPatternID); - } } }; const handleShuffle = async () => { diff --git a/website/src/repl/panel/PatternsTab.jsx b/website/src/repl/panel/PatternsTab.jsx index 23d00d3b..61488d53 100644 --- a/website/src/repl/panel/PatternsTab.jsx +++ b/website/src/repl/panel/PatternsTab.jsx @@ -9,8 +9,8 @@ import { importPatterns, newUserPattern, renameActivePattern, - setActivePattern, useActivePattern, + useViewingPattern, useSettings, } from '../../settings.mjs'; import * as tunes from '../tunes.mjs'; @@ -19,10 +19,14 @@ function classNames(...classes) { return classes.filter(Boolean).join(' '); } -function PatternButton({ isActive, onClick, label }) { +function PatternButton({ showOutline, onClick, label, showHiglight }) { return ( {label} @@ -30,11 +34,17 @@ function PatternButton({ isActive, onClick, label }) { ); } -function PatternButtons({ patterns, activePattern, onClick }) { +function PatternButtons({ patterns, activePattern, onClick, viewingPattern }) { return (
{Object.entries(patterns).map(([key, data]) => ( - onClick(key, data)} /> + onClick(key, data)} + /> ))}
); @@ -43,6 +53,7 @@ function PatternButtons({ patterns, activePattern, onClick }) { export function PatternsTab({ context }) { const { userPatterns } = useSettings(); const activePattern = useActivePattern(); + const viewingPattern = useViewingPattern(); const isExample = useMemo(() => activePattern && !!tunes[activePattern], [activePattern]); const onPatternClick = (key, data) => { const { code } = data; @@ -76,7 +87,12 @@ export function PatternsTab({ context }) { )} - +