mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-25 12:38:35 +00:00
store footer tab + latest code in nanostore
This commit is contained in:
parent
b67b049802
commit
70f7e73b9a
@ -10,7 +10,6 @@ function useStrudel({
|
|||||||
getTime,
|
getTime,
|
||||||
evalOnMount = false,
|
evalOnMount = false,
|
||||||
initialCode = '',
|
initialCode = '',
|
||||||
autolink = false,
|
|
||||||
beforeEval,
|
beforeEval,
|
||||||
afterEval,
|
afterEval,
|
||||||
editPattern,
|
editPattern,
|
||||||
@ -51,15 +50,13 @@ function useStrudel({
|
|||||||
setCode(code);
|
setCode(code);
|
||||||
beforeEval?.();
|
beforeEval?.();
|
||||||
},
|
},
|
||||||
afterEval: ({ pattern: _pattern, code }) => {
|
afterEval: (res) => {
|
||||||
|
const { pattern: _pattern, code } = res;
|
||||||
setActiveCode(code);
|
setActiveCode(code);
|
||||||
setPattern(_pattern);
|
setPattern(_pattern);
|
||||||
setEvalError();
|
setEvalError();
|
||||||
setSchedulerError();
|
setSchedulerError();
|
||||||
if (autolink) {
|
afterEval?.(res);
|
||||||
window.location.hash = '#' + encodeURIComponent(btoa(code));
|
|
||||||
}
|
|
||||||
afterEval?.();
|
|
||||||
},
|
},
|
||||||
onToggle: (v) => {
|
onToggle: (v) => {
|
||||||
setStarted(v);
|
setStarted(v);
|
||||||
|
|||||||
@ -7,14 +7,13 @@ import React, { useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|||||||
import { loadedSamples } from './Repl';
|
import { loadedSamples } from './Repl';
|
||||||
import { Reference } from './Reference';
|
import { Reference } from './Reference';
|
||||||
import { themes } from './themes.mjs';
|
import { themes } from './themes.mjs';
|
||||||
import { useSettings, settingsMap } from '../settings.mjs';
|
import { useSettings, settingsMap, setActiveFooter, defaultSettings } from '../settings.mjs';
|
||||||
|
|
||||||
export function Footer({ context }) {
|
export function Footer({ context }) {
|
||||||
// const [activeFooter, setActiveFooter] = useState('console');
|
const { isZen } = context;
|
||||||
// const { activeFooter, setActiveFooter, isZen } = useContext?.(ReplContext);
|
|
||||||
const { activeFooter, setActiveFooter, isZen } = context;
|
|
||||||
const footerContent = useRef();
|
const footerContent = useRef();
|
||||||
const [log, setLog] = useState([]);
|
const [log, setLog] = useState([]);
|
||||||
|
const { activeFooter } = useSettings();
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (footerContent.current && activeFooter === 'console') {
|
if (footerContent.current && activeFooter === 'console') {
|
||||||
@ -323,7 +322,7 @@ function SettingsTab() {
|
|||||||
className="bg-background p-2 max-w-[300px] rounded-md hover:opacity-50"
|
className="bg-background p-2 max-w-[300px] rounded-md hover:opacity-50"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (confirm('Sure?')) {
|
if (confirm('Sure?')) {
|
||||||
settingsMap.setKey(defaultSettings);
|
settingsMap.set(defaultSettings);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@ -23,9 +23,10 @@ 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 { useSettings } from '../settings.mjs';
|
import { settingsMap, useSettings, setLatestCode } from '../settings.mjs';
|
||||||
|
|
||||||
const initialTheme = localStorage.getItem('strudel-theme') || 'strudelTheme';
|
const { latestCode } = settingsMap.get();
|
||||||
|
console.log('latestCode', latestCode);
|
||||||
|
|
||||||
initAudioOnFirstClick();
|
initAudioOnFirstClick();
|
||||||
|
|
||||||
@ -114,7 +115,6 @@ export function Repl({ embedded = false }) {
|
|||||||
const isEmbedded = embedded || window.location !== window.parent.location;
|
const isEmbedded = embedded || window.location !== window.parent.location;
|
||||||
const [view, setView] = useState(); // codemirror view
|
const [view, setView] = useState(); // codemirror view
|
||||||
const [lastShared, setLastShared] = useState();
|
const [lastShared, setLastShared] = useState();
|
||||||
const [activeFooter, setActiveFooter] = useState('');
|
|
||||||
const [isZen, setIsZen] = useState(false);
|
const [isZen, setIsZen] = useState(false);
|
||||||
const [pending, setPending] = useState(false);
|
const [pending, setPending] = useState(false);
|
||||||
|
|
||||||
@ -125,14 +125,14 @@ export function Repl({ embedded = false }) {
|
|||||||
initialCode: '// LOADING',
|
initialCode: '// LOADING',
|
||||||
defaultOutput: webaudioOutput,
|
defaultOutput: webaudioOutput,
|
||||||
getTime,
|
getTime,
|
||||||
autolink: true,
|
|
||||||
beforeEval: () => {
|
beforeEval: () => {
|
||||||
cleanupUi();
|
cleanupUi();
|
||||||
cleanupDraw();
|
cleanupDraw();
|
||||||
setPending(true);
|
setPending(true);
|
||||||
},
|
},
|
||||||
afterEval: () => {
|
afterEval: ({ code }) => {
|
||||||
setPending(false);
|
setPending(false);
|
||||||
|
setLatestCode(code);
|
||||||
},
|
},
|
||||||
onToggle: (play) => !play && cleanupDraw(false),
|
onToggle: (play) => !play && cleanupDraw(false),
|
||||||
drawContext,
|
drawContext,
|
||||||
@ -141,16 +141,13 @@ export function Repl({ embedded = false }) {
|
|||||||
// init code
|
// init code
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
initCode().then((decoded) => {
|
initCode().then((decoded) => {
|
||||||
if (!decoded) {
|
|
||||||
setActiveFooter('intro'); // TODO: get rid
|
|
||||||
}
|
|
||||||
logger(
|
logger(
|
||||||
`Welcome to Strudel! ${
|
`Welcome to Strudel! ${
|
||||||
decoded ? `I have loaded the code from the URL.` : `A random code snippet named "${name}" has been loaded!`
|
decoded ? `I have loaded the code from the URL.` : `A random code snippet named "${name}" has been loaded!`
|
||||||
} Press play or hit ctrl+enter to run it!`,
|
} Press play or hit ctrl+enter to run it!`,
|
||||||
'highlight',
|
'highlight',
|
||||||
);
|
);
|
||||||
setCode(decoded || randomTune);
|
setCode(latestCode || decoded || randomTune);
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@ -252,8 +249,6 @@ export function Repl({ embedded = false }) {
|
|||||||
isDirty,
|
isDirty,
|
||||||
lastShared,
|
lastShared,
|
||||||
activeCode,
|
activeCode,
|
||||||
activeFooter,
|
|
||||||
setActiveFooter,
|
|
||||||
handleChangeCode,
|
handleChangeCode,
|
||||||
handleTogglePlay,
|
handleTogglePlay,
|
||||||
handleUpdate,
|
handleUpdate,
|
||||||
|
|||||||
@ -2,10 +2,12 @@ import { persistentMap } from '@nanostores/persistent';
|
|||||||
import { useStore } from '@nanostores/react';
|
import { useStore } from '@nanostores/react';
|
||||||
|
|
||||||
export const defaultSettings = {
|
export const defaultSettings = {
|
||||||
|
activeFooter: 'intro',
|
||||||
keybindings: 'codemirror',
|
keybindings: 'codemirror',
|
||||||
theme: 'strudelTheme',
|
theme: 'strudelTheme',
|
||||||
fontFamily: 'monospace',
|
fontFamily: 'monospace',
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
|
latestCode: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const settingsMap = persistentMap('strudel-settings', defaultSettings);
|
export const settingsMap = persistentMap('strudel-settings', defaultSettings);
|
||||||
@ -13,3 +15,7 @@ export const settingsMap = persistentMap('strudel-settings', defaultSettings);
|
|||||||
export function useSettings() {
|
export function useSettings() {
|
||||||
return useStore(settingsMap);
|
return useStore(settingsMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const setActiveFooter = (tab) => settingsMap.setKey('activeFooter', tab);
|
||||||
|
|
||||||
|
export const setLatestCode = (code) => settingsMap.setKey('latestCode', code);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user