Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chat ui first stage done #61

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/src/components/Buyer/signup.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ select>option{
text-decoration: underline;
display: flex;
gap: 10px;
padding-left: 60px;
padding-left: 30px;

}
.google>button>span{
Expand Down
107 changes: 98 additions & 9 deletions client/src/components/Negotiate/Chat.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import './chat.css';
import styles from './chat.module.css';
import io from 'socket.io-client'
import { useState, useRef, useEffect, useContext } from 'react';
import { addDoc, collection, doc, getDoc } from 'firebase/firestore';
import { db } from '../../../firebase';
import { AuthContext } from '../context/Authcontext';
import { useNavigate } from 'react-router-dom';
import { LuUserCircle2 } from "react-icons/lu";
import { IoArrowBackOutline } from "react-icons/io5";
import { MdCall } from "react-icons/md";
import { IoVideocam } from "react-icons/io5";
import { IoMdMore } from "react-icons/io";
import { FaPlus } from "react-icons/fa6";


const SERVER_PORT = import.meta.env.VITE_SERVER_PORT;
Expand All @@ -16,6 +23,9 @@
const [prevRoomID, setPrevRoomID] = useState(null);
const [userType, setUserType] = useState('buyers');
const [contacts, setContacts] = useState(null);
const [message,setmessage]=useState();
const navigate = useNavigate();
const [currperson,setperson]=useState();

useEffect(()=>{
if(!currentUser){
Expand All @@ -35,7 +45,7 @@
console.log("disconnected");
newSocket.disconnect();
};
},[currentUser])

Check warning on line 48 in client/src/components/Negotiate/Chat.jsx

View workflow job for this annotation

GitHub Actions / Lint Client Code

React Hook useEffect has a missing dependency: 'userType'. Either include it or remove the dependency array

useEffect(()=>{
if(contacts!=null){
Expand Down Expand Up @@ -78,7 +88,7 @@
switchRooms(socket, prevRoomID, currentRoomID);
loadMessage(currentRoomID);
}
}, [currentRoomID])

Check warning on line 91 in client/src/components/Negotiate/Chat.jsx

View workflow job for this annotation

GitHub Actions / Lint Client Code

React Hook useEffect has missing dependencies: 'prevRoomID' and 'socket'. Either include them or remove the dependency array


const handleClick = async ()=>{
Expand All @@ -86,11 +96,90 @@
await socket.emit("send-message", {message : `message from ${socket.id}`, room:currentRoomID});

//upload message to database
uploadMessage(currentRoomID);
uploadMessage(currentRoomID,message,currentUser.uid);
}
const handleChange = (event) => {
setmessage(event.target.value);
};
return (
<>
<button onClick={handleClick}>Send message</button>
<div className={styles.chitchat}>
<div className={styles.chatui}>
<div className={styles.cntlist}>
<div className={styles.profileinfo}>
<a onClick={()=>navigate()}><IoArrowBackOutline /></a>
<h1>Chats</h1>
</div>
<div className={styles.list}>
{/* <div className={styles.cnt1}>
<LuUserCircle2 />
<span>lavi</span>
</div>
<div className={styles.cnt1}>
<LuUserCircle2 />
<span>supreeth</span>
</div>
<div className={styles.cnt1}>
<LuUserCircle2 />
<span>dilip</span>
</div>
<div className={styles.cnt1}>
<LuUserCircle2 />
<span>isha</span>
</div>
<div className={styles.cnt1}>
<LuUserCircle2 />
<span>samyak</span>
</div> */}
{Object.keys(contacts).map((key) => {
const contact = contacts[key];
return (
<button
key={key}
onClick={() => {
loadMessage(contact.roomID)
setperson(`${contact.farmer_name}`)}}
style={{ marginBottom: '10px', cursor: 'pointer',textAlign:'center' }}
className={styles.cnt1}
>
<LuUserCircle2 />
<span>{contact.farmer_name}</span>
</button>
);
})}
</div>
</div>
<div className={styles.chat}>
<div className={styles.clientpfp}>
<span style={{display:'flex',gap:'15px'}}>
<span style={{position:'relative',top:'1vh'}}><LuUserCircle2 /></span>
{currperson}
</span>
<div className={styles.icons}>
<MdCall />
<IoVideocam />
<IoMdMore />
</div>
</div>
<div className={styles.display}>
<div className={styles.mess}>
{/* <span>message 1</span> */}
</div>
<div className={styles.mess}>
{/* <span>message 2</span> */}
</div>
</div>
<div className={styles.send}>
<textarea
name="negotiate"
id="chat"
placeholder="Send a message"
onChange={handleChange}
/>
<button onClick={handleClick}>Send</button>
</div>
</div>
</div>
{/*
<button onClick={()=>{
if(currentRoomID<3){
setPrevRoomID(currentRoomID);
Expand All @@ -100,8 +189,8 @@
setPrevRoomID(currentRoomID);
setRoomID(1);
}
}}>Switch Room</button>
</>
}}>Switch Room</button> */}
</div>
);
}

Expand All @@ -110,13 +199,13 @@
await socket.emit('join-room', currentRoomID);
}

const uploadMessage = async (currentRoomID)=>{
const uploadMessage = async (currentRoomID,mess,userId)=>{
try {
await addDoc(collection(db, 'chats', `${currentRoomID}`, 'messages'), {
message: 'test text',
message: `${mess}`,
timeStamp: new Date(),
// user: currentUser.uid,
user: 'asdjka'
user:`${userId}`
}).then(console.log("message sent"));
} catch (error) {
console.error("Error uploading message:", error);
Expand Down
25 changes: 0 additions & 25 deletions client/src/components/Negotiate/chat.css

This file was deleted.

119 changes: 119 additions & 0 deletions client/src/components/Negotiate/chat.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
*{
margin: 0;
padding: 0;
}
.chatui{
width: 100vw;
height: 100vh;
display: flex;
}
.cntlist{
width: 25vw;
height: 100vh;
}
.profileinfo{
padding: 13px;
background-color:white;
height: 7vh;
text-align: center;
font-size: 22px;
display: flex;
gap: 5vw;
border-right:1px solid rgba(128, 128, 128, 0.267);
/* border-radius: 5px; */
}
.profileinfo a{
cursor: pointer;
}
.profileinfo>h1{
position: relative;
bottom: 0.7vh;
right: 4vw;
}
.list{
/* border-radius: 10px; */
display: flex;
flex-direction: column;
height: 93vh;
border: 1px solid rgba(128, 128, 128, 0.267);
background-color: white;
overflow-y: auto;
}
.list>button>span{
position: relative;
bottom: 1vh;
}
.cnt1{
height: 9vh;
font-size: 25px;
padding: 20px;
text-align: center;
display: flex;
gap: 20px;
position: relative;
}
.cnt1>span{
position: relative;
bottom: 6px;
}
.cnt1:focus{
background-color:rgba(0, 0, 0, 0.034);
}
.chat{
display: flex;
flex-direction: column;
}
.clientpfp{
height:7.4vh;
width: 76vw;
text-align: center;
padding: 8px;
background-color: whitesmoke;
font-size: 25px;
display: flex;
justify-content: space-between;
/* border-radius:5px; */
}
.icons{
display: flex;
gap: 20px;
padding: 10px;
}
.display{
display: flex;
flex-direction: column;
padding: 40px;
font-size: 20px;
background-color: rgb(228, 226, 226);
height: 85vh;
z-index: -1;
text-align: center;
overflow-y: scroll;
}
.send{
display: flex;
justify-content: center;
padding: 20px;
background-color: whitesmoke;
gap: 15px;
padding-left: 3vw;
}
.send>textarea{
padding: 4px;
width: 55vw;
height: 6vh;
color: black;
font-size: 18px;
outline: none;
background-color: white;
text-align: center;
overflow-y: auto;
border-radius: 10px;
}
.send>button{
/* border-radius:10px; */
background-color:greenyellow;
width: 10vw;
text-align: center;
border-radius: 10px;
}
Loading