From dc00a78b57a7436f9b48f07594e34e2cdb076761 Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Sat, 4 May 2024 17:18:25 -0500 Subject: [PATCH] improve web client --- client/src/app.tsx | 144 ++++++++++++++++++++++++++++++------------ client/src/format.ts | 2 +- client/src/index.html | 3 +- 3 files changed, 106 insertions(+), 43 deletions(-) diff --git a/client/src/app.tsx b/client/src/app.tsx index 001216b..1cd0317 100644 --- a/client/src/app.tsx +++ b/client/src/app.tsx @@ -1,8 +1,7 @@ -/* eslint-disable no-restricted-syntax */ /* eslint-disable @typescript-eslint/no-explicit-any */ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useRef, MutableRefObject, Fragment } from 'react'; import useWebSocketModule, { ReadyState } from 'react-use-websocket'; -import { Maybe, Optional, doesExist } from '@apextoaster/js-utils'; +import { Maybe, doesExist } from '@apextoaster/js-utils'; import List from '@mui/material/List'; import ListItem from '@mui/material/ListItem'; import Divider from '@mui/material/Divider'; @@ -16,7 +15,7 @@ import Alert from '@mui/material/Alert'; import Switch from '@mui/material/Switch'; import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView'; import { TreeItem } from '@mui/x-tree-view/TreeItem'; -import { CssBaseline, PaletteMode, ThemeProvider, createTheme } from '@mui/material'; +import { Button, CssBaseline, Dialog, DialogContent, DialogTitle, PaletteMode, ThemeProvider, createTheme } from '@mui/material'; import { formatters } from './format.js'; @@ -74,7 +73,7 @@ export function WorldItem(props: EventItemProps) { return - + }) { - const { world } = props; +export type SetDetails = (entity: Maybe) => void; - return +export function ItemItem(props: { item: Item; setDetails: SetDetails }) { + const { item, setDetails } = props; + + return + setDetails(item)} /> + ; +} + +export function ActorItem(props: { actor: Actor; setDetails: SetDetails }) { + const { actor, setDetails } = props; + + return + setDetails(actor)} /> + + {actor.items.map((item) => )} + + ; +} + +export function RoomItem(props: { room: Room; setDetails: SetDetails }) { + const { room, setDetails } = props; + + return + setDetails(room)} /> + + {room.actors.map((actor) => )} + + + {room.items.map((item) => )} + + ; +} + +export function WorldPanel(props: { world: Maybe; setDetails: SetDetails }) { + const { world, setDetails } = props; + + // eslint-disable-next-line no-restricted-syntax + if (!doesExist(world)) { + return + No world data available + ; + } + + return - World: {world?.name} + World: {world.name} - Theme: {world?.theme} + Theme: {world.theme} - {world?.rooms.map((room) => - {room.actors.map((actor) => - {actor.items.map((item) => - )} - - )} - {room.items.map((item) => - )} - - )} + {world.rooms.map((room) => )} ; } +export function EntityDetails(props: { entity: Maybe; close: () => void }) { + // eslint-disable-next-line no-restricted-syntax + if (!doesExist(props.entity)) { + return ; + } + + return + {props.entity.name} + + + {props.entity.description} + + + + ; +} + +export function DetailDialog(props: { setDetails: SetDetails; details: Maybe }) { + const { details, setDetails } = props; + + return setDetails(undefined)} + > + setDetails(undefined)} /> + ; +} + export function App(props: AppProps) { + const [ detailEntity, setDetailEntity ] = useState>(undefined); const [ world, setWorld ] = useState>(undefined); const [ themeMode, setThemeMode ] = useState('light'); const [ history, setHistory ] = useState>([]); @@ -220,26 +281,29 @@ export function App(props: AppProps) { return - - - - - - - - Status: {connectionStatus} - - setThemeMode(themeMode === 'dark' ? 'light' : 'dark')} - inputProps={{ 'aria-label': 'controlled' }} - sx={{ marginLeft: 'auto' }} - /> - - - - {interleave(items)} - + + + + + + + Status: {connectionStatus} + + setThemeMode(themeMode === 'dark' ? 'light' : 'dark')} + inputProps={{ 'aria-label': 'controlled' }} + sx={{ marginLeft: 'auto' }} + /> + + + + + + + {interleave(items)} + + diff --git a/client/src/format.ts b/client/src/format.ts index 53502fb..9c5579f 100644 --- a/client/src/format.ts +++ b/client/src/format.ts @@ -26,7 +26,7 @@ export function formatWorld(data: any) { } export const formatters: Record = { - input: formatInput, + action: formatInput, result: formatResult, world: formatWorld, }; diff --git a/client/src/index.html b/client/src/index.html index 125998f..373a56a 100644 --- a/client/src/index.html +++ b/client/src/index.html @@ -4,8 +4,7 @@ Text World -
-
    +