2021-03-17 18:44:15 -07:00
|
|
|
import React, {useContext,useEffect } from 'react';
|
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
import UserContext from "../context/UserContext";
|
|
|
|
import styled,{ css } from 'styled-components';
|
|
|
|
|
|
|
|
const Header = styled.header`
|
|
|
|
|
|
|
|
@import url('https://fonts.googleapis.com/css?family=Montserrat|Ubuntu');
|
|
|
|
background: #66bfbf;
|
|
|
|
position: fixed;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
width: 100%;
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: center;
|
|
|
|
transition: 0.6s;
|
|
|
|
padding: 10px 15px;
|
|
|
|
z-index: 100000;
|
|
|
|
font-family: Ubuntu;
|
|
|
|
|
|
|
|
${ props => props.sticky ? css`
|
|
|
|
${Header};
|
|
|
|
padding: 3px 45px;
|
2021-03-18 06:29:48 -07:00
|
|
|
min-height: 3vh;
|
2021-03-17 18:44:15 -07:00
|
|
|
opacity: 0.85;
|
|
|
|
display: fixed;
|
|
|
|
`:css``};
|
|
|
|
|
|
|
|
|
|
|
|
& .logo {
|
|
|
|
font-family: "Ubuntu";
|
|
|
|
font-size: 2rem;
|
|
|
|
font-weight: bold;
|
|
|
|
position: relative;
|
|
|
|
color: #fff;
|
|
|
|
text-decoration: none;
|
|
|
|
text-transform: lowercase;
|
|
|
|
transition: 0.6s;
|
|
|
|
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
const List = styled.ul`
|
|
|
|
|
|
|
|
position: relative;
|
|
|
|
display: flex;
|
2021-03-18 06:29:48 -07:00
|
|
|
flex-direction: row;
|
2021-03-17 18:44:15 -07:00
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
2021-03-18 06:29:48 -07:00
|
|
|
padding: 13px 50px;
|
|
|
|
flex-wrap: nowrap;
|
|
|
|
margin-bottom: 0px !important;
|
2021-03-17 18:44:15 -07:00
|
|
|
|
2021-03-18 06:29:48 -07:00
|
|
|
`;
|
|
|
|
const ListElement = styled.li`
|
|
|
|
color: #fff;
|
|
|
|
text-decoration: none;
|
2021-03-19 05:12:44 -07:00
|
|
|
text-transform: uppercase;
|
2021-03-18 06:29:48 -07:00
|
|
|
|
|
|
|
position:relative;
|
|
|
|
padding:3px 50px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Anchor = styled.a`
|
2021-03-17 18:44:15 -07:00
|
|
|
color: #fff;
|
2021-03-18 06:29:48 -07:00
|
|
|
text-transform: uppercase;
|
|
|
|
color: inherit;
|
2021-03-17 18:44:15 -07:00
|
|
|
letter-spacing: 2px;
|
2021-03-18 06:29:48 -07:00
|
|
|
font-size: 1.2em;
|
|
|
|
padding: 3px ;
|
2021-03-17 18:44:15 -07:00
|
|
|
transition: 0.6s;
|
2021-03-18 06:29:48 -07:00
|
|
|
white-space: nowrap;
|
2021-03-17 18:44:15 -07:00
|
|
|
|
2021-03-18 06:29:48 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
`;
|
|
|
|
const Linker = styled(Link)`
|
|
|
|
color:#fff;
|
|
|
|
text-transform: uppercase;
|
|
|
|
color: inherit;
|
|
|
|
letter-spacing: 2px;
|
|
|
|
font-size: 1.2em;
|
|
|
|
padding: 3px 0;
|
|
|
|
transition: 0.6s;
|
2021-03-17 18:44:15 -07:00
|
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
export default function NavBar() {
|
|
|
|
const { userData, setUserData } = useContext(UserContext);
|
|
|
|
|
|
|
|
const logout = () => {
|
|
|
|
setUserData({
|
|
|
|
token: undefined,
|
|
|
|
user: undefined,
|
|
|
|
});
|
|
|
|
localStorage.setItem("auth-token", "");
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const [scrolled,setScrolled]=React.useState(false);
|
|
|
|
const handleScroll=() => {
|
|
|
|
const offset=window.scrollY;
|
|
|
|
if(offset > 200 ){
|
|
|
|
setScrolled(true);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
setScrolled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
useEffect(() => {
|
|
|
|
window.addEventListener('scroll',handleScroll)
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="navbar">
|
|
|
|
<Header sticky = {scrolled} >
|
|
|
|
|
2021-03-18 06:29:48 -07:00
|
|
|
<Anchor href="/" className="logo">locaft</Anchor>
|
|
|
|
<List>
|
|
|
|
<ListElement><Anchor href="/">Home</Anchor></ListElement>
|
|
|
|
<ListElement><Anchor href="/#about-us">About</Anchor></ListElement>
|
2021-03-19 05:12:44 -07:00
|
|
|
<ListElement><Anchor href="/#services">Services</Anchor></ListElement>
|
2021-03-18 06:29:48 -07:00
|
|
|
<ListElement><Anchor href="/#footer">Contact us</Anchor></ListElement>
|
2021-03-17 18:44:15 -07:00
|
|
|
{userData.user ? (
|
|
|
|
<React.Fragment>
|
2021-03-21 10:28:11 -07:00
|
|
|
<ListElement><Linker onClick={logout}>{userData.user.username}</Linker></ListElement>
|
2021-03-17 18:44:15 -07:00
|
|
|
</React.Fragment>
|
|
|
|
|
|
|
|
) : (
|
|
|
|
<React.Fragment>
|
2021-03-18 06:29:48 -07:00
|
|
|
<ListElement><Linker to="/user/register">Register</Linker></ListElement>
|
|
|
|
<ListElement><Linker to="/user/login">login</Linker></ListElement>
|
2021-03-17 18:44:15 -07:00
|
|
|
</React.Fragment>
|
|
|
|
)}
|
2021-03-18 06:29:48 -07:00
|
|
|
</List>
|
2021-03-17 18:44:15 -07:00
|
|
|
|
|
|
|
</Header>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|