From 0a1323da8ad29dcd1030d93bbbff6d776fa8aabb Mon Sep 17 00:00:00 2001 From: Hansi Xu Date: Sun, 6 Mar 2022 18:15:21 -0500 Subject: [PATCH] Finally fixed input --- sports-matcher/src/ChatWindow.js | 86 ++++++++++++++++++++++---------- sports-matcher/src/Contact.js | 12 ++++- sports-matcher/src/chats.css | 22 +++++++- 3 files changed, 92 insertions(+), 28 deletions(-) diff --git a/sports-matcher/src/ChatWindow.js b/sports-matcher/src/ChatWindow.js index 2db5275..036ad55 100644 --- a/sports-matcher/src/ChatWindow.js +++ b/sports-matcher/src/ChatWindow.js @@ -4,6 +4,7 @@ import React from 'react'; import './chats.css' import Chat from './Chat' import Contact from './Contact' +import { useState } from "react"; class ChatWindow extends React.Component { render() { @@ -11,15 +12,14 @@ class ChatWindow extends React.Component {
+
) } - test() { - alert("test") - } } class UserList extends React.Component { + render() { return (
@@ -35,26 +35,10 @@ class MessageList extends React.Component { render() { return (
-
-
- Got time for tennis this week, Raiden? -
-
-
-
- Foolish question. If I do not even have free time, How am I to pursue eternity and fulfill my promise to the people of Inazuma? -
-
-
-
- Aiight, see you at 4 -
-
-
-
- As you wish. -
-
+ + + +
) } @@ -69,9 +53,61 @@ class MessageList extends React.Component { // ) // } // } -class ChatInput extends React.Component { +const ChatInput = () => { + const [message, setMessage] = useState( '' ); + + // const onKeyPress = (e) => { + // // if(e.key === 'Enter'){ + // // e.preventDefault(); // Ensure it is only this code that runs + // // setMessage("") + // // } + // } + + const onKeyDown = (e) => { + const keyCode = e.which || e.keyCode; + + // 13 represents the Enter key + if (keyCode === 13 && !e.shiftKey) { + e.preventDefault(); + setMessage("") + } + } + + return ( + // onKeyPress={(e) => onKeyPress(e)} +
+