mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-12 14:18:36 +00:00
improve code init logic
This commit is contained in:
parent
faaed61384
commit
853a31b638
@ -25,6 +25,7 @@ import {
|
||||
setActivePattern,
|
||||
getActivePattern,
|
||||
getUserPattern,
|
||||
initUserCode,
|
||||
} from '../settings.mjs';
|
||||
import Loader from './Loader';
|
||||
import { settingPatterns } from '../settings.mjs';
|
||||
@ -184,12 +185,7 @@ export function Repl({ embedded = false }) {
|
||||
let msg;
|
||||
if (decoded) {
|
||||
setCode(decoded);
|
||||
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('');
|
||||
}
|
||||
initUserCode(decoded);
|
||||
msg = `I have loaded the code from the URL.`;
|
||||
} else if (latestCode) {
|
||||
setCode(latestCode);
|
||||
|
||||
@ -36,6 +36,11 @@ export function getActivePattern() {
|
||||
export function useActivePattern() {
|
||||
return useStore($activePattern);
|
||||
}
|
||||
export function initUserCode(code) {
|
||||
const userPatterns = getUserPatterns();
|
||||
const match = Object.entries(userPatterns).find(([_, pat]) => pat.code === code);
|
||||
setActivePattern(match?.[0] || '');
|
||||
}
|
||||
|
||||
export function useSettings() {
|
||||
const state = useStore(settingsMap);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user