1
- import { Box , TextField , Typography } from "@mui/material" ;
1
+ import { Box , styled , TextField , Typography } from "@mui/material" ;
2
2
import { useEffect , useRef , useState } from "react" ;
3
3
import { communicationSocket } from "../../utils/communicationSocket" ;
4
4
import { useMatch } from "../../contexts/MatchContext" ;
@@ -34,6 +34,13 @@ type ChatProps = {
34
34
isActive : boolean ;
35
35
} ;
36
36
37
+ const StyledTypography = styled ( Typography ) ( ( { theme } ) => ( {
38
+ padding : theme . spacing ( 1 , 2 ) ,
39
+ borderRadius : theme . spacing ( 2 ) ,
40
+ maxWidth : "80%" ,
41
+ whiteSpace : "pre-line" ,
42
+ } ) ) ;
43
+
37
44
const Chat : React . FC < ChatProps > = ( { isActive } ) => {
38
45
const [ messages , setMessages ] = useState < Message [ ] > ( [ ] ) ;
39
46
const [ inputValue , setInputValue ] = useState ( "" ) ;
@@ -143,16 +150,13 @@ const Chat: React.FC<ChatProps> = ({ isActive }) => {
143
150
marginTop : theme . spacing ( 1 ) ,
144
151
} ) }
145
152
>
146
- < Typography
153
+ < StyledTypography
147
154
sx = { ( theme ) => ( {
148
155
background : theme . palette . primary . main ,
149
- padding : theme . spacing ( 1 , 2 ) ,
150
- borderRadius : theme . spacing ( 2 ) ,
151
- maxWidth : "80%" ,
152
156
} ) }
153
157
>
154
158
{ msg . message }
155
- </ Typography >
159
+ </ StyledTypography >
156
160
</ Box >
157
161
) : (
158
162
< Box
@@ -163,16 +167,13 @@ const Chat: React.FC<ChatProps> = ({ isActive }) => {
163
167
marginTop : theme . spacing ( 1 ) ,
164
168
} ) }
165
169
>
166
- < Typography
170
+ < StyledTypography
167
171
sx = { ( theme ) => ( {
168
172
background : theme . palette . secondary . main ,
169
- padding : theme . spacing ( 1 , 2 ) ,
170
- borderRadius : theme . spacing ( 2 ) ,
171
- maxWidth : "80%" ,
172
173
} ) }
173
174
>
174
175
{ msg . message }
175
- </ Typography >
176
+ </ StyledTypography >
176
177
</ Box >
177
178
)
178
179
) }
@@ -186,7 +187,7 @@ const Chat: React.FC<ChatProps> = ({ isActive }) => {
186
187
onChange = { ( e ) => setInputValue ( e . target . value ) }
187
188
onKeyDown = { ( e ) => {
188
189
const trimmedValue = inputValue . trim ( ) ;
189
- if ( e . key === "Enter" && trimmedValue !== "" ) {
190
+ if ( e . key === "Enter" && ! e . shiftKey && trimmedValue !== "" ) {
190
191
e . preventDefault ( ) ;
191
192
communicationSocket . emit ( CommunicationEvents . SEND_TEXT_MESSAGE , {
192
193
roomId : getMatchId ( ) ,
0 commit comments