1
- "use client"
1
+ "use client" ;
2
2
3
3
import { useState , useEffect } from "react" ;
4
4
import Sidebar from "@/app/components/random_chat_components/Sidebar" ;
5
+ import CategoriesAndGenderDetailsPopup from "@/app/components/random_chat_components/CategoriesAndGenderDetailsPopup" ;
5
6
6
7
const RandomChat = ( ) => {
7
8
const [ inputMessage , setInputMessage ] = useState < string > ( "" ) ;
@@ -25,13 +26,15 @@ const RandomChat = () => {
25
26
return ( ) => {
26
27
newSocket . close ( ) ;
27
28
} ;
29
+ // eslint-disable-next-line
28
30
} , [ ] ) ; // Only runs once when the component mounts
29
31
30
32
function sendMessage ( event : React . KeyboardEvent < HTMLInputElement > ) {
31
33
if (
32
34
event . key === "Enter" &&
33
35
socket &&
34
- socket . readyState === WebSocket . OPEN
36
+ socket . readyState === WebSocket . OPEN &&
37
+ inputMessage . length >= 1
35
38
) {
36
39
// Send the message
37
40
socket . send ( JSON . stringify ( { content : inputMessage } ) ) ;
@@ -48,23 +51,30 @@ const RandomChat = () => {
48
51
return (
49
52
< div className = "flex w-full h-full" >
50
53
< Sidebar />
51
- < div className = "flex h-[100vh] w-full ml-[25%] bg-[#393E46]" >
54
+ < div className = "flex flex-col justify-between h-[100vh] w-full ml-[25%] bg-[#393E46]" >
55
+ { chatMessages . length <= 0 && < CategoriesAndGenderDetailsPopup /> }
52
56
< div className = "bg-blue text-white p-2" >
53
57
{ chatMessages . map ( ( message , index ) => (
54
- < div key = { index } > { message } </ div >
58
+ < div
59
+ key = { index }
60
+ className = "bg-white rounded-l-full rounded-r-full px-3 py-1 text-black max-w-fit mb-3"
61
+ >
62
+ { message }
63
+ </ div >
55
64
) ) }
56
65
</ div >
57
-
58
- < div className = "w-[90%] self-end mx-auto mb-5" >
59
- < input
60
- type = "text"
61
- id = "default-input"
62
- className = "text-gray-50 text-sm rounded-lg block p-2.5 w-full bg-gray-500 outline-none"
63
- placeholder = "Enter text here..."
64
- value = { inputMessage }
65
- onChange = { handleMessageChange }
66
- onKeyDown = { sendMessage }
67
- />
66
+ < div className = "w-full" >
67
+ < div className = "w-[95%] mx-auto mb-4" >
68
+ < input
69
+ type = "text"
70
+ id = "default-input"
71
+ className = "text-gray-50 text-sm rounded-lg block p-2.5 w-full bg-gray-500 outline-none"
72
+ placeholder = "Enter text here..."
73
+ value = { inputMessage }
74
+ onChange = { handleMessageChange }
75
+ onKeyDown = { sendMessage }
76
+ />
77
+ </ div >
68
78
</ div >
69
79
</ div >
70
80
</ div >
0 commit comments