Skip to content

Commit

Permalink
Kiosk: Remove direct dom manipulation (#9692)
Browse files Browse the repository at this point in the history
* Remove direct dom manipulation

* tweak adding game css

* prettier

* Removed unneeded css attribute

* update readme

* Remove unwanted memo dependency
  • Loading branch information
eanders-ms authored Sep 21, 2023
1 parent 3514eb4 commit 5b4bd1c
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 66 deletions.
1 change: 1 addition & 0 deletions kiosk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Follow the "Test in staging environment" instructions, but get your auth token f
- Open a sound file editor (such as Audacity or Adobe Audition).
- Import the downloaded audio file.
- Edit and clip out the specific sound effect you want.
- Run a high-pass filter to reduce volume of low-end frequencies.
- Export the edited audio as an .ogg file.

5. Save the .ogg file to /pxt/docs/kiosk-data/sfx:
Expand Down
6 changes: 1 addition & 5 deletions kiosk/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@
<script type="text/javascript" src="/blb/target.js"></script>
<script type="text/javascript" src="/blb/pxtlib.js"></script>
<script type="text/javascript" src="/blb/pxtsim.js"></script>

<div class="content">
<div id="root"></div>
</div>

<div class="footer"></div>
<div id="root"></div>

</body>
</html>
4 changes: 4 additions & 0 deletions kiosk/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import AddingGame from "./Components/AddingGame";
import ScanQR from "./Components/ScanQR";
import QrSuccess from "./Components/QrSuccess";
import GameOver from "./Components/GameOver";
import PlayingGame from "./Components/PlayingGame";
import Footer from "./Components/Footer";
import Notifications from "./Components/Notifications";
import { useLocationHash, usePromise } from "./Hooks";
import { launchGame } from "./Transforms/launchGame";
Expand Down Expand Up @@ -76,11 +78,13 @@ function App() {
{kioskState === KioskState.ScanQR && <ScanQR />}
{kioskState === KioskState.QrSuccess && <QrSuccess />}
{kioskState === KioskState.GameOver && <GameOver />}
{kioskState === KioskState.PlayingGame && <PlayingGame />}
<Notifications />
</>
) : (
<></>
)}
{kioskState !== KioskState.PlayingGame && <Footer />}
</>
);
}
Expand Down
3 changes: 3 additions & 0 deletions kiosk/src/Components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Footer() {
return <div className="footer"></div>;
}
2 changes: 1 addition & 1 deletion kiosk/src/Components/GameList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const GameList: React.FC<IProps> = ({
loop={true}
slidesPerView={1.5}
centeredSlides={true}
spaceBetween={130}
spaceBetween={10}
pagination={{ type: "fraction" }}
onSwiper={swiper => {
localSwiper.current = swiper;
Expand Down
26 changes: 26 additions & 0 deletions kiosk/src/Components/PlayingGame.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useContext, useMemo } from "react";
import { AppStateContext } from "../State/AppStateContext";
import configData from "../config.json";
import "../Kiosk.css";

export default function PlayingGame() {
const { state: kiosk, dispatch } = useContext(AppStateContext);
const { launchedGameId: gameId } = kiosk;

const playUrl = useMemo(() => {
if (gameId) {
const playUrlBase = `${configData.PlayUrlRoot}?id=${gameId}&hideSimButtons=1&noFooter=1&single=1&fullscreen=1&autofocus=1`;
const playQueryParam = kiosk.builtGamesCache[gameId]
? "&server=1"
: "&sendBuilt=1";
return playUrlBase + playQueryParam;
}
}, [gameId]);
return (
<iframe
className="sim-embed"
sandbox="allow-popups allow-forms allow-scripts allow-same-origin"
src={playUrl}
></iframe>
);
}
12 changes: 5 additions & 7 deletions kiosk/src/Kiosk.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ html, body {
color: var(--main-text-color);
}

.content {
width: 100%;
height: 100%;
#root {
width: 100vw;
height: 100vh;
}

h1 {
Expand All @@ -54,8 +54,8 @@ h2 {
width: 100%;
height: 100%;
top:0;
left: -2%;
position: absolute;
border: 0;
}

.footer {
Expand All @@ -65,7 +65,6 @@ h2 {
width: 20%;
left: 1.5%;
bottom: 0;
margin-bottom: 2vh;
background: url("footer.png");
background-repeat: no-repeat;
background-size: 100%;
Expand Down Expand Up @@ -198,6 +197,7 @@ h2 {
display: flex;
flex-direction: column;
align-items: baseline;
align-self: center;
width: 60%;
line-height: 200%;
}
Expand All @@ -214,7 +214,6 @@ h2 {
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
}

.innerQRCodeContent {
Expand Down Expand Up @@ -257,7 +256,6 @@ h2 {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
width: 95%;
height: 100%;
margin-top: 1%;
Expand Down
25 changes: 0 additions & 25 deletions kiosk/src/Services/Gamespace.ts

This file was deleted.

5 changes: 1 addition & 4 deletions kiosk/src/Transforms/exitGame.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { stateAndDispatch } from "../State";
import { KioskState } from "../Types";
import * as Actions from "../State/Actions";
import { navigate } from "./navigate";
import * as Gamespace from "../Services/Gamespace";

export function exitGame(nextState: KioskState): void {
const { state } = stateAndDispatch();

if (state.kioskState !== KioskState.PlayingGame) {
return;
}

navigate(nextState);

Gamespace.addElements();
}
24 changes: 0 additions & 24 deletions kiosk/src/Transforms/launchGame.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { stateAndDispatch } from "../State";
import { KioskState } from "../Types";
import * as Actions from "../State/Actions";
import configData from "../config.json";
import { navigate } from "./navigate";
import * as Gamespace from "../Services/Gamespace";

export function launchGame(
gameId: string,
Expand All @@ -18,26 +16,4 @@ export function launchGame(
}
if (preventReturningToMenu) dispatch(Actions.setLockedGame(gameId));
navigate(KioskState.PlayingGame);

Gamespace.removeElements();

const playUrlBase = `${configData.PlayUrlRoot}?id=${gameId}&hideSimButtons=1&noFooter=1&single=1&fullscreen=1&autofocus=1`;
let playQueryParam = state.builtGamesCache[gameId]
? "&server=1"
: "&sendBuilt=1";

function createIFrame(src: string) {
const iframe: HTMLIFrameElement = document.createElement("iframe");
iframe.className = "sim-embed";
iframe.frameBorder = "0";
iframe.setAttribute(
"sandbox",
"allow-popups allow-forms allow-scripts allow-same-origin"
);
iframe.src = src;
return iframe;
}
const playerIFrame = createIFrame(playUrlBase + playQueryParam);
Gamespace.append(playerIFrame);
playerIFrame.focus();
}

0 comments on commit 5b4bd1c

Please sign in to comment.