2020-12-07 09:49:14 -08:00
|
|
|
import React, { useContext } from 'react';
|
|
|
|
import { Link } from "react-router-dom";
|
2020-11-21 09:27:17 -08:00
|
|
|
import '../navbar.css';
|
2020-11-30 08:56:17 -08:00
|
|
|
import UserContext from "../context/UserContext";
|
2020-11-20 09:26:49 -08:00
|
|
|
|
2020-11-29 09:05:56 -08:00
|
|
|
export default function NavBar() {
|
2020-11-30 08:56:17 -08:00
|
|
|
const { userData, setUserData } = useContext(UserContext);
|
2020-12-07 09:49:14 -08:00
|
|
|
|
2020-11-30 08:56:17 -08:00
|
|
|
|
|
|
|
|
|
|
|
const logout = () => {
|
|
|
|
setUserData({
|
|
|
|
token: undefined,
|
|
|
|
user: undefined,
|
|
|
|
});
|
|
|
|
localStorage.setItem("auth-token", "");
|
|
|
|
};
|
|
|
|
window.addEventListener("scroll", () => {
|
|
|
|
var header = document.querySelector("header");
|
|
|
|
header.classList.toggle("sticky", window.scrollY > 0);
|
|
|
|
|
|
|
|
})
|
2020-12-06 08:59:40 -08:00
|
|
|
console.log(userData);
|
2020-11-30 08:56:17 -08:00
|
|
|
return (
|
2020-12-06 08:59:40 -08:00
|
|
|
<div className="navbar">
|
2020-11-30 08:56:17 -08:00
|
|
|
<header>
|
|
|
|
<input type="checkbox" id="check" />
|
2020-12-06 08:59:40 -08:00
|
|
|
<label htmlFor="check" className="checkbtn">
|
|
|
|
<i className="fas fa-bars" id="btn"></i>
|
2020-11-30 08:56:17 -08:00
|
|
|
</label>
|
|
|
|
|
|
|
|
|
2020-12-07 09:49:14 -08:00
|
|
|
<a href="/" className="logo">locaft</a>
|
2020-11-30 08:56:17 -08:00
|
|
|
<ul>
|
2020-12-07 09:49:14 -08:00
|
|
|
<li><a href="/">Home</a></li>
|
|
|
|
<li><a href="/#about-us">About</a></li>
|
|
|
|
<li><a href="/#features">Services</a></li>
|
|
|
|
<li><a href="/#footer">Contact us</a></li>
|
2020-11-30 08:56:17 -08:00
|
|
|
{userData.user ? (
|
2020-12-07 09:49:14 -08:00
|
|
|
<li><Link onClick={logout}>{userData.user.username}</Link></li>
|
2020-11-30 08:56:17 -08:00
|
|
|
) : (
|
2020-12-04 08:38:55 -08:00
|
|
|
<React.Fragment>
|
2020-12-07 09:49:14 -08:00
|
|
|
<li><Link to="/user/register">Register</Link></li>
|
|
|
|
<li><Link to="/user/login">login</Link></li>
|
2020-12-04 08:38:55 -08:00
|
|
|
</React.Fragment>
|
2020-11-30 08:56:17 -08:00
|
|
|
)}
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
</header>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
2020-11-29 09:05:56 -08:00
|
|
|
|