Test loading demo by path

This commit is contained in:
ochafik 2024-12-25 13:58:44 +00:00 • committed by Olivier Chafik
commit 58a513dd11
3 changed files with 18 additions and 4 deletions

View file

@ -57,6 +57,10 @@ export async function readStateFromFragment(): Promise<State | null> {
// For testing
const src = decodeURIComponent(serialized.substring('src:'.length));
return createInitialState(null, src);
} else if (serialized.startsWith('testpath:')) {
// For testing
const path = decodeURIComponent(serialized.substring('testpath:'.length));
return createInitialState(null, '...', path);
}
let obj;
try {

View file

@ -6,7 +6,7 @@ import { State } from './app-state';
export const defaultSourcePath = '/playground.scad';
export const defaultModelColor = '#f9d72c';
export function createInitialState(state: State | null, content: string = defaultScad): State {
export function createInitialState(state: State | null, content = defaultScad, activePath = defaultSourcePath): State {
type Mode = State['view']['layout']['mode'];
const mode: Mode = window.matchMedia("(min-width: 768px)").matches
@ -14,8 +14,8 @@ export function createInitialState(state: State | null, content: string = defaul
const initialState: State = {
params: {
activePath: defaultSourcePath,
sources: [{path: defaultSourcePath, content}],
activePath: activePath,
sources: [{path: activePath, content}],
features: [],
exportFormat2D: 'svg',
exportFormat3D: 'glb',