Last active
November 22, 2021 12:02
-
-
Save hieptl/6fd2a9fc417b729f9ba95a57d2d01bbc to your computer and use it in GitHub Desktop.
Main.js - Discord Clone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useContext } from 'react'; | |
import { CometChatMessages } from '../../cometchat-pro-react-ui-kit/CometChatWorkspace/src'; | |
import Header from './Header'; | |
import Pendings from './Pendings'; | |
import Add from './Add'; | |
import RightSidebar from './RightSidebar'; | |
import Context from '../../context'; | |
const Main = () => { | |
const [selectedOption, setSelectedOption] = useState(1); | |
const { selectedFriend, setSelectedFriend } = useContext(Context); | |
const onItemSelected = (index) => { | |
setSelectedOption(() => index); | |
setSelectedFriend(null); | |
} | |
const renderMain = () => { | |
if (selectedFriend) { | |
return <CometChatMessages chatWithUser={selectedFriend.uid} />; | |
} | |
if (selectedOption === 1) { | |
return <Pendings />; | |
} | |
if (selectedOption === 3) { | |
return <Add />; | |
} | |
}; | |
return ( | |
<div className="friends__main"> | |
<Header onItemSelected={onItemSelected} selectedOption={selectedOption} /> | |
<div className="friends__container"> | |
<div className="friends__container-body"> | |
{renderMain()} | |
</div> | |
<RightSidebar /> | |
</div> | |
</div> | |
); | |
}; | |
export default Main; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment