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 loading contacts fix #80

Merged
merged 1 commit into from
Sep 15, 2024
Merged
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
18 changes: 13 additions & 5 deletions client/src/components/Negotiate/Chat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

const chatDisplayRef = useRef(null); // Ref to chat display container
const bottomRef = useRef(null); // Ref to the last message to scroll into view
// console.log(userType);

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

Check warning on line 69 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 @@ -103,7 +104,7 @@
socket.off('left-room');
}
};
}, [socket, messages]);

Check warning on line 107 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: 'lang'. Either include it or remove the dependency array

useEffect(() => {
//switch rooms/contacts
Expand All @@ -113,7 +114,7 @@
setMessages(result);
});
}
}, [currentRoomID]);

Check warning on line 117 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

useEffect(() => {
// console.log("messages array updated");
Expand Down Expand Up @@ -188,7 +189,7 @@
// loadMessage(contact.roomID)
setPrevRoomID(currentRoomID);
setRoomID(contact.roomID);
setperson(`${contact.farmer_name}`);
setperson(`${contact.name}`);
}}
style={{
marginBottom: '10px',
Expand All @@ -198,7 +199,7 @@
className={styles.cnt1}
>
<LuUserCircle2 />
<span>{contact.farmer_name}</span>
<span>{contact.name}</span>
</button>
);
})}
Expand All @@ -219,9 +220,13 @@
<button
className={styles.mkc}
onClick={() => {
navigate('/buyer')
if (userType == 'farmer') {
navigate('/farmerdashboard');
} else {
navigate('/buyer');
}
}}
style={{ display: currperson==='farmer' ? 'none' : 'flex' }}
style={{ display: !currperson ? 'none' : 'flex' }}
>
Make Contract
</button>
Expand Down Expand Up @@ -312,9 +317,12 @@
};

const loadContacts = async (currentUserID, userType) => {
const u_type = (userType=='buyers')?('buyers'):('farmers');
try {
const userDocRef = doc(db, userType, currentUserID);
const userDocRef = doc(db, u_type, currentUserID);
console.log("ref : ", userDocRef);
const userDoc = await getDoc(userDocRef);
console.log(userDoc.data());
if (userDoc.exists()) {
const userData = userDoc.data();
return userData.Contacts || {};
Expand Down
Loading