This commit is contained in:
2023-04-22 13:57:18 +02:00
parent a1d7630026
commit f2d0d2faf8

View File

@@ -41,6 +41,7 @@ const Room = () => {
Players: [] Players: []
}); });
const [chatMessages, setChatMessages] = React.useState<ChatMessage[]>([]); const [chatMessages, setChatMessages] = React.useState<ChatMessage[]>([]);
const [chatInput, setChatInput] = React.useState<string>('');
const websocket = useWebSocket(WS_URL, { const websocket = useWebSocket(WS_URL, {
onOpen: () => { onOpen: () => {
@@ -87,10 +88,10 @@ const Room = () => {
}); });
} }
const handleChat = (Message: string) => { const handleChat = (message: string) => {
handleSend({ handleSend({
Type: "CHAT", Type: "CHAT",
Payload: { Message } Payload: message
}); });
} }
@@ -99,6 +100,13 @@ const Room = () => {
<h1>Room {roomId}</h1> <h1>Room {roomId}</h1>
<GHButton onClick={handleLeaveRoom}>Leave Room</GHButton> <GHButton onClick={handleLeaveRoom}>Leave Room</GHButton>
<Game gameState={gameState} handleCardSend={handleCardSend} handleDraw={handleDraw}/> <Game gameState={gameState} handleCardSend={handleCardSend} handleDraw={handleDraw}/>
<input type="text" placeholder={"Chat"} value={chatInput} onChange={(e) => setChatInput(e.target.value)} />
<button onClick={() => handleChat(chatInput)}>Send</button>
<ul>
{chatMessages.map((message, index) => (
<li key={index}>{message.PlayerName}: {message.Message}</li>
))}
</ul>
</div> </div>
) )
} }