1- "use client"
1+ "use client" ;
22
33import { useState , useEffect } from "react" ;
44import Sidebar from "@/app/components/random_chat_components/Sidebar" ;
5+ import CategoriesAndGenderDetailsPopup from "@/app/components/random_chat_components/CategoriesAndGenderDetailsPopup" ;
56
67const RandomChat = ( ) => {
78 const [ inputMessage , setInputMessage ] = useState < string > ( "" ) ;
@@ -25,13 +26,15 @@ const RandomChat = () => {
2526 return ( ) => {
2627 newSocket . close ( ) ;
2728 } ;
29+ // eslint-disable-next-line
2830 } , [ ] ) ; // Only runs once when the component mounts
2931
3032 function sendMessage ( event : React . KeyboardEvent < HTMLInputElement > ) {
3133 if (
3234 event . key === "Enter" &&
3335 socket &&
34- socket . readyState === WebSocket . OPEN
36+ socket . readyState === WebSocket . OPEN &&
37+ inputMessage . length >= 1
3538 ) {
3639 // Send the message
3740 socket . send ( JSON . stringify ( { content : inputMessage } ) ) ;
@@ -48,23 +51,30 @@ const RandomChat = () => {
4851 return (
4952 < div className = "flex w-full h-full" >
5053 < 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 /> }
5256 < div className = "bg-blue text-white p-2" >
5357 { 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 >
5564 ) ) }
5665 </ 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 >
6878 </ div >
6979 </ div >
7080 </ div >
0 commit comments