Spaces:
Runtime error
Runtime error
Julian Bilcke commited on
Commit ·
0be4978
1
Parent(s): 4251a28
add toggle for the debug mode
Browse files- package-lock.json +54 -0
- package.json +2 -0
- src/app/main.tsx +34 -8
- src/components/ui/label.tsx +26 -0
- src/components/ui/switch.tsx +29 -0
package-lock.json
CHANGED
|
@@ -18,11 +18,13 @@
|
|
| 18 |
"@radix-ui/react-dialog": "^1.0.4",
|
| 19 |
"@radix-ui/react-dropdown-menu": "^2.0.5",
|
| 20 |
"@radix-ui/react-icons": "^1.3.0",
|
|
|
|
| 21 |
"@radix-ui/react-menubar": "^1.0.3",
|
| 22 |
"@radix-ui/react-popover": "^1.0.6",
|
| 23 |
"@radix-ui/react-select": "^1.2.2",
|
| 24 |
"@radix-ui/react-separator": "^1.0.3",
|
| 25 |
"@radix-ui/react-slot": "^1.0.2",
|
|
|
|
| 26 |
"@silevis/reactgrid": "^4.0.5",
|
| 27 |
"@tanstack/react-query": "^4.30.0",
|
| 28 |
"@tanstack/react-table": "^8.9.3",
|
|
@@ -1048,6 +1050,29 @@
|
|
| 1048 |
}
|
| 1049 |
}
|
| 1050 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1051 |
"node_modules/@radix-ui/react-menu": {
|
| 1052 |
"version": "2.0.5",
|
| 1053 |
"resolved": "https://registry.npmjs.org/@radix-ui/react-menu/-/react-menu-2.0.5.tgz",
|
|
@@ -1374,6 +1399,35 @@
|
|
| 1374 |
}
|
| 1375 |
}
|
| 1376 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1377 |
"node_modules/@radix-ui/react-use-callback-ref": {
|
| 1378 |
"version": "1.0.1",
|
| 1379 |
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-callback-ref/-/react-use-callback-ref-1.0.1.tgz",
|
|
|
|
| 18 |
"@radix-ui/react-dialog": "^1.0.4",
|
| 19 |
"@radix-ui/react-dropdown-menu": "^2.0.5",
|
| 20 |
"@radix-ui/react-icons": "^1.3.0",
|
| 21 |
+
"@radix-ui/react-label": "^2.0.2",
|
| 22 |
"@radix-ui/react-menubar": "^1.0.3",
|
| 23 |
"@radix-ui/react-popover": "^1.0.6",
|
| 24 |
"@radix-ui/react-select": "^1.2.2",
|
| 25 |
"@radix-ui/react-separator": "^1.0.3",
|
| 26 |
"@radix-ui/react-slot": "^1.0.2",
|
| 27 |
+
"@radix-ui/react-switch": "^1.0.3",
|
| 28 |
"@silevis/reactgrid": "^4.0.5",
|
| 29 |
"@tanstack/react-query": "^4.30.0",
|
| 30 |
"@tanstack/react-table": "^8.9.3",
|
|
|
|
| 1050 |
}
|
| 1051 |
}
|
| 1052 |
},
|
| 1053 |
+
"node_modules/@radix-ui/react-label": {
|
| 1054 |
+
"version": "2.0.2",
|
| 1055 |
+
"resolved": "https://registry.npmjs.org/@radix-ui/react-label/-/react-label-2.0.2.tgz",
|
| 1056 |
+
"integrity": "sha512-N5ehvlM7qoTLx7nWPodsPYPgMzA5WM8zZChQg8nyFJKnDO5WHdba1vv5/H6IO5LtJMfD2Q3wh1qHFGNtK0w3bQ==",
|
| 1057 |
+
"dependencies": {
|
| 1058 |
+
"@babel/runtime": "^7.13.10",
|
| 1059 |
+
"@radix-ui/react-primitive": "1.0.3"
|
| 1060 |
+
},
|
| 1061 |
+
"peerDependencies": {
|
| 1062 |
+
"@types/react": "*",
|
| 1063 |
+
"@types/react-dom": "*",
|
| 1064 |
+
"react": "^16.8 || ^17.0 || ^18.0",
|
| 1065 |
+
"react-dom": "^16.8 || ^17.0 || ^18.0"
|
| 1066 |
+
},
|
| 1067 |
+
"peerDependenciesMeta": {
|
| 1068 |
+
"@types/react": {
|
| 1069 |
+
"optional": true
|
| 1070 |
+
},
|
| 1071 |
+
"@types/react-dom": {
|
| 1072 |
+
"optional": true
|
| 1073 |
+
}
|
| 1074 |
+
}
|
| 1075 |
+
},
|
| 1076 |
"node_modules/@radix-ui/react-menu": {
|
| 1077 |
"version": "2.0.5",
|
| 1078 |
"resolved": "https://registry.npmjs.org/@radix-ui/react-menu/-/react-menu-2.0.5.tgz",
|
|
|
|
| 1399 |
}
|
| 1400 |
}
|
| 1401 |
},
|
| 1402 |
+
"node_modules/@radix-ui/react-switch": {
|
| 1403 |
+
"version": "1.0.3",
|
| 1404 |
+
"resolved": "https://registry.npmjs.org/@radix-ui/react-switch/-/react-switch-1.0.3.tgz",
|
| 1405 |
+
"integrity": "sha512-mxm87F88HyHztsI7N+ZUmEoARGkC22YVW5CaC+Byc+HRpuvCrOBPTAnXgf+tZ/7i0Sg/eOePGdMhUKhPaQEqow==",
|
| 1406 |
+
"dependencies": {
|
| 1407 |
+
"@babel/runtime": "^7.13.10",
|
| 1408 |
+
"@radix-ui/primitive": "1.0.1",
|
| 1409 |
+
"@radix-ui/react-compose-refs": "1.0.1",
|
| 1410 |
+
"@radix-ui/react-context": "1.0.1",
|
| 1411 |
+
"@radix-ui/react-primitive": "1.0.3",
|
| 1412 |
+
"@radix-ui/react-use-controllable-state": "1.0.1",
|
| 1413 |
+
"@radix-ui/react-use-previous": "1.0.1",
|
| 1414 |
+
"@radix-ui/react-use-size": "1.0.1"
|
| 1415 |
+
},
|
| 1416 |
+
"peerDependencies": {
|
| 1417 |
+
"@types/react": "*",
|
| 1418 |
+
"@types/react-dom": "*",
|
| 1419 |
+
"react": "^16.8 || ^17.0 || ^18.0",
|
| 1420 |
+
"react-dom": "^16.8 || ^17.0 || ^18.0"
|
| 1421 |
+
},
|
| 1422 |
+
"peerDependenciesMeta": {
|
| 1423 |
+
"@types/react": {
|
| 1424 |
+
"optional": true
|
| 1425 |
+
},
|
| 1426 |
+
"@types/react-dom": {
|
| 1427 |
+
"optional": true
|
| 1428 |
+
}
|
| 1429 |
+
}
|
| 1430 |
+
},
|
| 1431 |
"node_modules/@radix-ui/react-use-callback-ref": {
|
| 1432 |
"version": "1.0.1",
|
| 1433 |
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-callback-ref/-/react-use-callback-ref-1.0.1.tgz",
|
package.json
CHANGED
|
@@ -19,11 +19,13 @@
|
|
| 19 |
"@radix-ui/react-dialog": "^1.0.4",
|
| 20 |
"@radix-ui/react-dropdown-menu": "^2.0.5",
|
| 21 |
"@radix-ui/react-icons": "^1.3.0",
|
|
|
|
| 22 |
"@radix-ui/react-menubar": "^1.0.3",
|
| 23 |
"@radix-ui/react-popover": "^1.0.6",
|
| 24 |
"@radix-ui/react-select": "^1.2.2",
|
| 25 |
"@radix-ui/react-separator": "^1.0.3",
|
| 26 |
"@radix-ui/react-slot": "^1.0.2",
|
|
|
|
| 27 |
"@silevis/reactgrid": "^4.0.5",
|
| 28 |
"@tanstack/react-query": "^4.30.0",
|
| 29 |
"@tanstack/react-table": "^8.9.3",
|
|
|
|
| 19 |
"@radix-ui/react-dialog": "^1.0.4",
|
| 20 |
"@radix-ui/react-dropdown-menu": "^2.0.5",
|
| 21 |
"@radix-ui/react-icons": "^1.3.0",
|
| 22 |
+
"@radix-ui/react-label": "^2.0.2",
|
| 23 |
"@radix-ui/react-menubar": "^1.0.3",
|
| 24 |
"@radix-ui/react-popover": "^1.0.6",
|
| 25 |
"@radix-ui/react-select": "^1.2.2",
|
| 26 |
"@radix-ui/react-separator": "^1.0.3",
|
| 27 |
"@radix-ui/react-slot": "^1.0.2",
|
| 28 |
+
"@radix-ui/react-switch": "^1.0.3",
|
| 29 |
"@silevis/reactgrid": "^4.0.5",
|
| 30 |
"@tanstack/react-query": "^4.30.0",
|
| 31 |
"@tanstack/react-table": "^8.9.3",
|
src/app/main.tsx
CHANGED
|
@@ -13,9 +13,10 @@ import {
|
|
| 13 |
SelectTrigger,
|
| 14 |
SelectValue,
|
| 15 |
} from "@/components/ui/select"
|
|
|
|
|
|
|
| 16 |
|
| 17 |
import { newRender, getRender } from "./render"
|
| 18 |
-
|
| 19 |
import { RenderedScene } from "./types"
|
| 20 |
import { Game, GameType } from "./games/types"
|
| 21 |
import { defaultGame, games, getGame } from "./games"
|
|
@@ -47,7 +48,8 @@ export default function Main() {
|
|
| 47 |
const requestedEngine = (searchParams.get('engine') as EngineType) || defaultEngine
|
| 48 |
const [engine, setEngine] = useState<Engine>(getEngine(requestedEngine))
|
| 49 |
|
| 50 |
-
const
|
|
|
|
| 51 |
|
| 52 |
const [situation, setSituation] = useState("")
|
| 53 |
|
|
@@ -190,6 +192,22 @@ export default function Main() {
|
|
| 190 |
|
| 191 |
const clickables = Array.from(new Set(rendered.segments.map(s => s.label)).values())
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
const handleSelectGame = (newGameType: GameType) => {
|
| 194 |
gameRef.current = newGameType
|
| 195 |
setGame(getGame(newGameType))
|
|
@@ -233,11 +251,11 @@ export default function Main() {
|
|
| 233 |
router.replace(`${pathname}${query}`, { })
|
| 234 |
|
| 235 |
// workaround.. but it is strange that router.replace doesn't work..
|
| 236 |
-
|
| 237 |
-
|
| 238 |
|
| 239 |
// actually we don't handle partial reload very well, so let's reload the whole page
|
| 240 |
-
window.location = `${window.location.protocol + "//" + window.location.host + window.location.pathname + '?' + search.toString()}` as any
|
| 241 |
}
|
| 242 |
|
| 243 |
// determine when to show the spinner
|
|
@@ -249,7 +267,7 @@ export default function Main() {
|
|
| 249 |
>
|
| 250 |
<div className="flex flex-row w-full justify-between items-center px-2 py-2 border-b-1 border-gray-50 dark:border-gray-50 bg-gray-800 dark:bg-gray-800">
|
| 251 |
<div className="flex flex-row items-center space-x-3 font-mono">
|
| 252 |
-
<
|
| 253 |
<Select
|
| 254 |
defaultValue={gameRef.current}
|
| 255 |
onValueChange={(value) => { handleSelectGame(value as GameType) }}>
|
|
@@ -258,13 +276,21 @@ export default function Main() {
|
|
| 258 |
</SelectTrigger>
|
| 259 |
<SelectContent>
|
| 260 |
{Object.entries(games).map(([key, game]) =>
|
| 261 |
-
|
| 262 |
)}
|
| 263 |
</SelectContent>
|
| 264 |
</Select>
|
| 265 |
</div>
|
| 266 |
<div className="flex flex-row items-center space-x-3 font-mono">
|
| 267 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
<Select
|
| 269 |
defaultValue={engine.type}
|
| 270 |
onValueChange={(value) => { handleSelectEngine(value as EngineType) }}>
|
|
|
|
| 13 |
SelectTrigger,
|
| 14 |
SelectValue,
|
| 15 |
} from "@/components/ui/select"
|
| 16 |
+
import { Switch } from "@/components/ui/switch"
|
| 17 |
+
import { Label } from "@/components/ui/label"
|
| 18 |
|
| 19 |
import { newRender, getRender } from "./render"
|
|
|
|
| 20 |
import { RenderedScene } from "./types"
|
| 21 |
import { Game, GameType } from "./games/types"
|
| 22 |
import { defaultGame, games, getGame } from "./games"
|
|
|
|
| 48 |
const requestedEngine = (searchParams.get('engine') as EngineType) || defaultEngine
|
| 49 |
const [engine, setEngine] = useState<Engine>(getEngine(requestedEngine))
|
| 50 |
|
| 51 |
+
const requestedDebug = (searchParams.get('debug') === "true")
|
| 52 |
+
const [debug, setDebug] = useState<boolean>(requestedDebug)
|
| 53 |
|
| 54 |
const [situation, setSituation] = useState("")
|
| 55 |
|
|
|
|
| 192 |
|
| 193 |
const clickables = Array.from(new Set(rendered.segments.map(s => s.label)).values())
|
| 194 |
|
| 195 |
+
const handleToggleDebug = (isToggledOn: boolean) => {
|
| 196 |
+
const current = new URLSearchParams(Array.from(searchParams.entries()))
|
| 197 |
+
current.set("debug", `${isToggledOn}`)
|
| 198 |
+
const search = current.toString()
|
| 199 |
+
const query = search ? `?${search}` : ""
|
| 200 |
+
|
| 201 |
+
// for some reason, this doesn't work?!
|
| 202 |
+
router.replace(`${pathname}${query}`, { })
|
| 203 |
+
|
| 204 |
+
// workaround.. but it is strange that router.replace doesn't work..
|
| 205 |
+
let newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?' + search.toString()
|
| 206 |
+
window.history.pushState({path: newurl}, '', newurl)
|
| 207 |
+
|
| 208 |
+
setDebug(isToggledOn)
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
const handleSelectGame = (newGameType: GameType) => {
|
| 212 |
gameRef.current = newGameType
|
| 213 |
setGame(getGame(newGameType))
|
|
|
|
| 251 |
router.replace(`${pathname}${query}`, { })
|
| 252 |
|
| 253 |
// workaround.. but it is strange that router.replace doesn't work..
|
| 254 |
+
let newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?' + search.toString()
|
| 255 |
+
window.history.pushState({path: newurl}, '', newurl)
|
| 256 |
|
| 257 |
// actually we don't handle partial reload very well, so let's reload the whole page
|
| 258 |
+
// window.location = `${window.location.protocol + "//" + window.location.host + window.location.pathname + '?' + search.toString()}` as any
|
| 259 |
}
|
| 260 |
|
| 261 |
// determine when to show the spinner
|
|
|
|
| 267 |
>
|
| 268 |
<div className="flex flex-row w-full justify-between items-center px-2 py-2 border-b-1 border-gray-50 dark:border-gray-50 bg-gray-800 dark:bg-gray-800">
|
| 269 |
<div className="flex flex-row items-center space-x-3 font-mono">
|
| 270 |
+
<Label className="flex text-sm">Select a story:</Label>
|
| 271 |
<Select
|
| 272 |
defaultValue={gameRef.current}
|
| 273 |
onValueChange={(value) => { handleSelectGame(value as GameType) }}>
|
|
|
|
| 276 |
</SelectTrigger>
|
| 277 |
<SelectContent>
|
| 278 |
{Object.entries(games).map(([key, game]) =>
|
| 279 |
+
<SelectItem key={key} value={key}>{game.title}</SelectItem>
|
| 280 |
)}
|
| 281 |
</SelectContent>
|
| 282 |
</Select>
|
| 283 |
</div>
|
| 284 |
<div className="flex flex-row items-center space-x-3 font-mono">
|
| 285 |
+
<Switch
|
| 286 |
+
checked={debug}
|
| 287 |
+
onCheckedChange={handleToggleDebug}
|
| 288 |
+
disabled={isLoading}
|
| 289 |
+
/>
|
| 290 |
+
<Label>Debug</Label>
|
| 291 |
+
</div>
|
| 292 |
+
<div className="flex flex-row items-center space-x-3 font-mono">
|
| 293 |
+
<Label className="flex text-sm">Rendering engine:</Label>
|
| 294 |
<Select
|
| 295 |
defaultValue={engine.type}
|
| 296 |
onValueChange={(value) => { handleSelectEngine(value as EngineType) }}>
|
src/components/ui/label.tsx
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client"
|
| 2 |
+
|
| 3 |
+
import * as React from "react"
|
| 4 |
+
import * as LabelPrimitive from "@radix-ui/react-label"
|
| 5 |
+
import { cva, type VariantProps } from "class-variance-authority"
|
| 6 |
+
|
| 7 |
+
import { cn } from "@/lib/utils"
|
| 8 |
+
|
| 9 |
+
const labelVariants = cva(
|
| 10 |
+
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
const Label = React.forwardRef<
|
| 14 |
+
React.ElementRef<typeof LabelPrimitive.Root>,
|
| 15 |
+
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
|
| 16 |
+
VariantProps<typeof labelVariants>
|
| 17 |
+
>(({ className, ...props }, ref) => (
|
| 18 |
+
<LabelPrimitive.Root
|
| 19 |
+
ref={ref}
|
| 20 |
+
className={cn(labelVariants(), className)}
|
| 21 |
+
{...props}
|
| 22 |
+
/>
|
| 23 |
+
))
|
| 24 |
+
Label.displayName = LabelPrimitive.Root.displayName
|
| 25 |
+
|
| 26 |
+
export { Label }
|
src/components/ui/switch.tsx
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client"
|
| 2 |
+
|
| 3 |
+
import * as React from "react"
|
| 4 |
+
import * as SwitchPrimitives from "@radix-ui/react-switch"
|
| 5 |
+
|
| 6 |
+
import { cn } from "@/lib/utils"
|
| 7 |
+
|
| 8 |
+
const Switch = React.forwardRef<
|
| 9 |
+
React.ElementRef<typeof SwitchPrimitives.Root>,
|
| 10 |
+
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
|
| 11 |
+
>(({ className, ...props }, ref) => (
|
| 12 |
+
<SwitchPrimitives.Root
|
| 13 |
+
className={cn(
|
| 14 |
+
"peer inline-flex h-[24px] w-[44px] shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-400 focus-visible:ring-offset-2 focus-visible:ring-offset-white disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-zinc-900 data-[state=unchecked]:bg-zinc-200 dark:focus-visible:ring-zinc-800 dark:focus-visible:ring-offset-zinc-950 dark:data-[state=checked]:bg-zinc-50 dark:data-[state=unchecked]:bg-zinc-800",
|
| 15 |
+
className
|
| 16 |
+
)}
|
| 17 |
+
{...props}
|
| 18 |
+
ref={ref}
|
| 19 |
+
>
|
| 20 |
+
<SwitchPrimitives.Thumb
|
| 21 |
+
className={cn(
|
| 22 |
+
"pointer-events-none block h-5 w-5 rounded-full bg-white shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0 dark:bg-zinc-950"
|
| 23 |
+
)}
|
| 24 |
+
/>
|
| 25 |
+
</SwitchPrimitives.Root>
|
| 26 |
+
))
|
| 27 |
+
Switch.displayName = SwitchPrimitives.Root.displayName
|
| 28 |
+
|
| 29 |
+
export { Switch }
|