Slightly better chat (send with enter)
All checks were successful
Build Mau & Deploy Mau / build (push) Successful in 1m26s
Build Mau & Deploy Mau / deploy (push) Successful in 7m9s

This commit is contained in:
DTieman
2024-04-19 23:28:29 +02:00
parent 5f8c6994aa
commit e78d0d46f7
2 changed files with 14 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
import useWebSocket from "react-use-websocket";
import React from "react";
import React, {FormEvent} from "react";
import {useNavigate, useParams} from "react-router";
import {GHButton} from "../components/Button";
import useTitle from "../../utils/hooks/TitleHook";
@@ -91,11 +91,13 @@ const Room = () => {
});
}
const handleChat = (message: string) => {
const handleChat = (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
handleSend({
Type: "CHAT",
Payload: message
Payload: chatInput
});
setChatInput('');
}
return (
@@ -103,8 +105,10 @@ const Room = () => {
<h1>Room {roomId}</h1>
<GHButton onClick={handleLeaveRoom}>Leave Room</GHButton>
<Game gameState={gameState} handleCardSend={handleCardSend} handleDraw={handleDraw} handleChoice={handleChoice}/>
<input type="text" placeholder={"Chat"} value={chatInput} onChange={(e) => setChatInput(e.target.value)} />
<button onClick={() => handleChat(chatInput)}>Send</button>
<form onSubmit={handleChat}>
<input type="text" placeholder={"Chat"} value={chatInput} onChange={(e) => setChatInput(e.target.value)} />
<GHButton type={"submit"}>Send</GHButton>
</form>
<ul>
{chatMessages.map((message, index) => (
<li key={index}>{message.PlayerName}: {message.Message}</li>