Last active
November 22, 2021 16:31
-
-
Save hieptl/3fb3990cdd615b41e05b0535ac6e1947 to your computer and use it in GitHub Desktop.
header.js - Instagram Clone React Node
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 { useContext } from 'react'; | |
import { useHistory } from 'react-router-dom'; | |
import withModal from '../common/Modal'; | |
import Create from '../create/Create'; | |
import Context from '../../context'; | |
import logo from '../../logo.png'; | |
const Header = (props) => { | |
const { toggleModal } = props; | |
const { user, setUser, cometChat } = useContext(Context); | |
const history = useHistory(); | |
const logout = async () => { | |
const isLogout = window.confirm('Do you want to log out ?'); | |
if (isLogout) { | |
await cometChat.logout(); | |
localStorage.removeItem('auth'); | |
setUser(null); | |
history.push('/login'); | |
} | |
}; | |
const goCreatePost = () => { | |
toggleModal(true); | |
}; | |
const goHome = () => { | |
history.push('/'); | |
}; | |
const goProfile = () => { | |
history.push(`/profile/${user.id}`) | |
}; | |
const goNotification = () => { | |
history.push('/notifications'); | |
}; | |
const goChat = () => { | |
history.push('/chat'); | |
}; | |
return ( | |
<div className="header"> | |
<div className="header__left"> | |
<img onClick={goHome} src={logo} alt="Instagram Clone" /> | |
</div> | |
<div className="header__right"> | |
<span onClick={goHome}> | |
<svg aria-label="Home" className="_8-yf5 " color="#262626" fill="#262626" height="22" role="img" viewBox="0 0 48 48" width="22"><path d="M45.3 48H30c-.8 0-1.5-.7-1.5-1.5V34.2c0-2.6-2-4.6-4.6-4.6s-4.6 2-4.6 4.6v12.3c0 .8-.7 1.5-1.5 1.5H2.5c-.8 0-1.5-.7-1.5-1.5V23c0-.4.2-.8.4-1.1L22.9.4c.6-.6 1.5-.6 2.1 0l21.5 21.5c.4.4.6 1.1.3 1.6 0 .1-.1.1-.1.2v22.8c.1.8-.6 1.5-1.4 1.5zm-13.8-3h12.3V23.4L24 3.6l-20 20V45h12.3V34.2c0-4.3 3.3-7.6 7.6-7.6s7.6 3.3 7.6 7.6V45z"></path></svg> | |
</span> | |
<span onClick={goCreatePost}> | |
<svg aria-label="New Post" className="_8-yf5 " color="#262626" fill="#262626" height="22" role="img" viewBox="0 0 48 48" width="22"><path d="M31.8 48H16.2c-6.6 0-9.6-1.6-12.1-4C1.6 41.4 0 38.4 0 31.8V16.2C0 9.6 1.6 6.6 4 4.1 6.6 1.6 9.6 0 16.2 0h15.6c6.6 0 9.6 1.6 12.1 4C46.4 6.6 48 9.6 48 16.2v15.6c0 6.6-1.6 9.6-4 12.1-2.6 2.5-5.6 4.1-12.2 4.1zM16.2 3C10 3 7.8 4.6 6.1 6.2 4.6 7.8 3 10 3 16.2v15.6c0 6.2 1.6 8.4 3.2 10.1 1.6 1.6 3.8 3.1 10 3.1h15.6c6.2 0 8.4-1.6 10.1-3.2 1.6-1.6 3.1-3.8 3.1-10V16.2c0-6.2-1.6-8.4-3.2-10.1C40.2 4.6 38 3 31.8 3H16.2z"></path><path d="M36.3 25.5H11.7c-.8 0-1.5-.7-1.5-1.5s.7-1.5 1.5-1.5h24.6c.8 0 1.5.7 1.5 1.5s-.7 1.5-1.5 1.5z"></path><path d="M24 37.8c-.8 0-1.5-.7-1.5-1.5V11.7c0-.8.7-1.5 1.5-1.5s1.5.7 1.5 1.5v24.6c0 .8-.7 1.5-1.5 1.5z"></path></svg> | |
</span> | |
<span onClick={goChat}> | |
<svg xmlns="http://www.w3.org/2000/svg" style={{ width: '1.75rem', height: '1.75rem' }} className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z" /> | |
</svg> | |
</span> | |
<span onClick={goNotification}> | |
<svg aria-label="Activity Feed" className="_8-yf5 " color="#262626" fill="#262626" height="22" role="img" viewBox="0 0 48 48" width="22"><path d="M34.6 6.1c5.7 0 10.4 5.2 10.4 11.5 0 6.8-5.9 11-11.5 16S25 41.3 24 41.9c-1.1-.7-4.7-4-9.5-8.3-5.7-5-11.5-9.2-11.5-16C3 11.3 7.7 6.1 13.4 6.1c4.2 0 6.5 2 8.1 4.3 1.9 2.6 2.2 3.9 2.5 3.9.3 0 .6-1.3 2.5-3.9 1.6-2.3 3.9-4.3 8.1-4.3m0-3c-4.5 0-7.9 1.8-10.6 5.6-2.7-3.7-6.1-5.5-10.6-5.5C6 3.1 0 9.6 0 17.6c0 7.3 5.4 12 10.6 16.5.6.5 1.3 1.1 1.9 1.7l2.3 2c4.4 3.9 6.6 5.9 7.6 6.5.5.3 1.1.5 1.6.5.6 0 1.1-.2 1.6-.5 1-.6 2.8-2.2 7.8-6.8l2-1.8c.7-.6 1.3-1.2 2-1.7C42.7 29.6 48 25 48 17.6c0-8-6-14.5-13.4-14.5z"></path></svg> | |
</span> | |
<span className="header__user-avatar"> | |
<img onClick={goProfile} src={`http://localhost:8080${user?.user_avatar}`} alt="user-avatar" /> | |
</span> | |
<span onClick={logout}> | |
<svg aria-label="Direct" className="_8-yf5 " color="#262626" fill="#262626" height="22" role="img" viewBox="0 0 48 48" width="22"><path d="M47.8 3.8c-.3-.5-.8-.8-1.3-.8h-45C.9 3.1.3 3.5.1 4S0 5.2.4 5.7l15.9 15.6 5.5 22.6c.1.6.6 1 1.2 1.1h.2c.5 0 1-.3 1.3-.7l23.2-39c.4-.4.4-1 .1-1.5zM5.2 6.1h35.5L18 18.7 5.2 6.1zm18.7 33.6l-4.4-18.4L42.4 8.6 23.9 39.7z"></path></svg> | |
</span> | |
</div> | |
</div> | |
); | |
} | |
export default withModal(Create)(Header); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment