Skip to content

Commit

Permalink
Fix passing params to the sim URL
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-matt-hillsdon committed May 28, 2024
1 parent 0e556c4 commit e40445b
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/simulator/Simulator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
useToken,
VStack,
} from "@chakra-ui/react";
import { useEffect, useRef, useState } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
import { IntlShape, useIntl } from "react-intl";
import HideSplitViewButton from "../common/SplitView/HideSplitViewButton";
import { topBarHeight } from "../deployment/misc";
Expand Down Expand Up @@ -43,14 +43,20 @@ const Simulator = ({
minWidth,
simFocus,
}: SimulatorProps) => {
const production =
"https://python-simulator.usermbit.org/v/0.1/simulator.html";
const staging =
"https://python-simulator.usermbit.org/staging/simulator.html?flag=sw";
const url = stage === "PRODUCTION" ? production : staging;
// For testing with sim branches:
//const branch = "upgrade-mpy";
//const url = `https://review-python-simulator.usermbit.org/${branch}/simulator.html`;
const [brand500] = useToken("colors", ["brand.500"]);
const url = useMemo(() => {
const production =
"https://python-simulator.usermbit.org/v/0.1/simulator.html";
const staging =
"https://python-simulator.usermbit.org/staging/simulator.html?flag=sw";

// For testing with sim branches:
//const branch = "upgrade-mpy";
//const url = new URL(`https://review-python-simulator.usermbit.org/${branch}/simulator.html`);
const url = new URL(stage === "PRODUCTION" ? production : staging);
url.searchParams.append("color", brand500);
return url.toString();
}, [brand500]);

const ref = useRef<HTMLIFrameElement>(null);
const intl = useIntl();
Expand All @@ -72,7 +78,6 @@ const Simulator = ({
updateTranslations(simulator.current, intl);
}, [simulator, intl]);
const simControlsRef = useRef<HTMLDivElement>(null);
const [brand500] = useToken("colors", ["brand.500"]);
const [running, setRunning] = useState<RunningStatus>(RunningStatus.STOPPED);
const previouslyShown = usePrevious(shown);

Expand Down Expand Up @@ -117,7 +122,7 @@ const Simulator = ({
<Box
ref={ref}
as="iframe"
src={`${url}?color=${encodeURIComponent(brand500)}`}
src={url}
title={simulatorTitle}
name={simulatorTitle}
frameBorder="no"
Expand Down

0 comments on commit e40445b

Please sign in to comment.