Skip to content

Instantly share code, notes, and snippets.

@hieptl
Created August 21, 2021 08:39
Show Gist options
  • Save hieptl/1bb9938555f83d9c9ac930d8b5a44858 to your computer and use it in GitHub Desktop.
Save hieptl/1bb9938555f83d9c9ac930d8b5a44858 to your computer and use it in GitHub Desktop.
Chat - Uber Clone
// import useContext.
import { useContext } from 'react';
// import Context.
import Context from '../Context';
// import cometchat ui.
import { CometChatMessages } from '../cometchat-pro-react-ui-kit/CometChatWorkspace/src';
function Chat() {
const { user, currentRide } = useContext(Context);
const findUser = () => {
if (user && currentRide) {
if (user.role === 'user' && currentRide.driver && currentRide.driver.id) {
return currentRide.driver.id;
} else if (user.role === 'driver' && currentRide.requestor && currentRide.requestor.id) {
return currentRide.requestor.id;
}
}
}
return (
<div style={{width: '100vw', height:'100vh' }}>
<CometChatMessages chatWithUser={findUser()} />
</div>
);
}
export default Chat;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment