import { doesExist } from '@apextoaster/js-utils'; import { Alert, Button, Card, CardContent, Stack, TextField, Typography } from '@mui/material'; import React, { useState } from 'react'; import { useStore } from 'zustand'; import { store, StoreState } from './store'; export interface PlayerPanelProps { sendInput: (input: string) => void; } export function playerStateSelector(s: StoreState) { return { character: s.character, activeTurn: s.activeTurn, }; } export function PlayerPanel(props: PlayerPanelProps) { const state = useStore(store, playerStateSelector); const { character, activeTurn } = state; const { sendInput } = props; const [input, setInput] = useState(''); if (doesExist(character)) { return {activeTurn && It's your turn!} Playing as: {character.name} {character.backstory} setInput(event.target.value)} onKeyDown={(event) => { if (event.key === 'Enter') { sendInput(input); setInput(''); } }} /> ; } return No player character ; }