Slightly better chat (send with enter)
This commit is contained in:
@@ -1,13 +1,10 @@
|
|||||||
import React, {FunctionComponent} from "react";
|
import React, {ButtonHTMLAttributes, DetailedHTMLProps, FunctionComponent} from "react";
|
||||||
|
|
||||||
interface Props {
|
export const GHButton: FunctionComponent<DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>> = (props) => {
|
||||||
className?: string
|
|
||||||
onClick?: () => void
|
const {className, ...rest} = props;
|
||||||
children?: React.ReactNode
|
|
||||||
}
|
|
||||||
|
|
||||||
export const GHButton: FunctionComponent<Props> = ({className, onClick, children}) => {
|
|
||||||
return (
|
return (
|
||||||
<span className={`gh-button ${className}`} onClick={onClick}>{children}</span>
|
<button className={`gh-button ${className}`} {...rest}></button>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import useWebSocket from "react-use-websocket";
|
import useWebSocket from "react-use-websocket";
|
||||||
import React from "react";
|
import React, {FormEvent} from "react";
|
||||||
import {useNavigate, useParams} from "react-router";
|
import {useNavigate, useParams} from "react-router";
|
||||||
import {GHButton} from "../components/Button";
|
import {GHButton} from "../components/Button";
|
||||||
import useTitle from "../../utils/hooks/TitleHook";
|
import useTitle from "../../utils/hooks/TitleHook";
|
||||||
@@ -91,11 +91,13 @@ const Room = () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleChat = (message: string) => {
|
const handleChat = (e: FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
handleSend({
|
handleSend({
|
||||||
Type: "CHAT",
|
Type: "CHAT",
|
||||||
Payload: message
|
Payload: chatInput
|
||||||
});
|
});
|
||||||
|
setChatInput('');
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -103,8 +105,10 @@ 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} handleChoice={handleChoice}/>
|
<Game gameState={gameState} handleCardSend={handleCardSend} handleDraw={handleDraw} handleChoice={handleChoice}/>
|
||||||
<input type="text" placeholder={"Chat"} value={chatInput} onChange={(e) => setChatInput(e.target.value)} />
|
<form onSubmit={handleChat}>
|
||||||
<button onClick={() => handleChat(chatInput)}>Send</button>
|
<input type="text" placeholder={"Chat"} value={chatInput} onChange={(e) => setChatInput(e.target.value)} />
|
||||||
|
<GHButton type={"submit"}>Send</GHButton>
|
||||||
|
</form>
|
||||||
<ul>
|
<ul>
|
||||||
{chatMessages.map((message, index) => (
|
{chatMessages.map((message, index) => (
|
||||||
<li key={index}>{message.PlayerName}: {message.Message}</li>
|
<li key={index}>{message.PlayerName}: {message.Message}</li>
|
||||||
|
|||||||
Reference in New Issue
Block a user