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);
|
|
|
|
const logout = () => {
|
|
|
|
setUserData({
|
|
|
|
token: undefined,
|
|
|
|
user: undefined,
|
|
|
|
});
|
|
|
|
localStorage.setItem("auth-token", "");
|
|
|
|
};
|
2020-12-09 08:58:29 -08:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
window.addEventListener("scroll", () => {
|
|
|
|
var header = document.getElementById("navheader");
|
2020-12-14 07:09:59 -08:00
|
|
|
header.classList.toggle("sticky", window.scrollY > 1);
|
2020-12-09 08:58:29 -08:00
|
|
|
});
|
|
|
|
});
|
2020-11-30 08:56:17 -08:00
|
|
|
return (
|
2020-12-06 08:59:40 -08:00
|
|
|
<div className="navbar">
|
2020-12-09 08:58:29 -08:00
|
|
|
<header id="navheader">
|
2020-11-30 08:56:17 -08:00
|
|
|
<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-21 08:27:28 -08:00
|
|
|
<React.Fragment>
|
2020-12-07 09:49:14 -08:00
|
|
|
<li><Link onClick={logout}>{userData.user.username}</Link></li>
|
2020-12-21 08:27:28 -08:00
|
|
|
<li class="nr_li dd_main">
|
|
|
|
<img src="https://i.imgur.com/2QKIaJ5.png" alt="profile_img" />
|
|
|
|
|
|
|
|
<div class="dd_menu">
|
|
|
|
<div class="dd_left">
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
<li><i class="fas fa-cog"></i></li>
|
|
|
|
<li><i class="fas fa-sign-out-alt"></i></li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div class="dd_right">
|
|
|
|
<ul>
|
|
|
|
<li>Settings</li>
|
|
|
|
<li>Logout</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
<li class="nr_li">
|
|
|
|
<i class="fas fa-envelope-open-text"></i>
|
|
|
|
</li>
|
|
|
|
</React.Fragment>
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|