File size: 12,371 Bytes
f5071ca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
import React, { useState, useEffect, useContext } from "react";
import { Transition } from "@headlessui/react";
import { Fade } from "react-reveal";
import { Link, useNavigate } from "react-router-dom";
import { getAuth, signOut } from "firebase/auth";
import { AuthContext } from "../../Context/UserContext";
function Navbar(props) {
const { User } = useContext(AuthContext);
const [profilePic, setProfilePic] = useState("");
const navigate = useNavigate();
useEffect(() => {
if (User != null) {
setProfilePic(User.photoURL);
}
window.addEventListener("scroll", transitionNavBar);
console.log("Navbar", User);
return () => {
window.removeEventListener("scroll", transitionNavBar);
};
}, []);
const [isOpen, setIsOpen] = useState(false);
const [show, handleShow] = useState(false);
const transitionNavBar = () => {
if (window.scrollY > 80) {
handleShow(true);
} else {
handleShow(false);
}
};
const NavBlack = () => {
handleShow(true);
};
const NavTransparent = () => {
handleShow(false);
};
const SignOut = () => {
const auth = getAuth();
signOut(auth)
.then(() => {
navigate("/");
})
.catch((error) => {
alert(error.message);
});
};
return (
<Fade>
<header
className={
props.playPage
? "fixed top-0 z-10 w-full backdrop-blur-sm"
: "fixed top-0 z-10 w-full"
}
>
<nav
className={`transition duration-500 ease-in-out ${
show && "transition duration-500 ease-in-out bg-black "
} `}
>
<div className="px-4 mx-auto max-w-8xl sm:px-6 lg:px-8">
<div className="flex items-center justify-between h-16">
<div className="flex items-center">
<div className="flex-shrink-0">
<img
className="h-6 cursor-pointer w-18"
src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/08/Netflix_2015_logo.svg/1920px-Netflix_2015_logo.svg.png"
alt="NETFLIX"
/>
</div>
<div className="hidden md:block">
<div className="flex items-center ml-10 space-x-4">
<Link
to={"/"}
className="py-2 font-medium text-white transition ease-in-out delay-150 rounded-md cursor-pointer hover:text-red-800 lg:px-3 text-m"
>
Home
</Link>
<Link
to={"/series"}
className="py-2 font-medium text-white transition ease-in-out delay-150 rounded-md cursor-pointer hover:text-red-800 lg:px-3 text-m"
>
Series
</Link>
<Link
to={"/history"}
className="py-2 font-medium text-white transition ease-in-out delay-150 rounded-md cursor-pointer hover:text-red-800 lg:px-3 text-m"
>
History
</Link>
<Link
to={"/liked"}
className="py-2 font-medium text-white transition ease-in-out delay-150 rounded-md cursor-pointer hover:text-red-800 lg:px-3 text-m"
>
Liked
</Link>
<Link
to={"/mylist"}
className="py-2 font-medium text-white transition ease-in-out delay-150 rounded-md cursor-pointer hover:text-red-800 lg:px-3 text-m"
>
My List
</Link>
</div>
</div>
</div>
<div className="ml-auto">
<div className="flex">
{/* Search Icon */}
<Link to={"/search"}>
<svg
xmlns="http://www.w3.org/2000/svg"
className="items-center w-10 h-10 pr-4 mt-auto mb-auto text-white hover:text-red-800 cursor-pointer"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={2}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
/>
</svg>
</Link>
{User ? (
<a className="items-center hidden pr-4 mt-auto mb-auto text-base font-medium text-white transition ease-in-out delay-150 cursor-pointer hover:text-red-800 md:flex">
{User.displayName}
</a>
) : null}
{/* Notification icon */}
<svg
xmlns="http://www.w3.org/2000/svg"
className="items-center hidden w-10 h-10 pr-4 mt-auto mb-auto text-white cursor-pointer md:flex"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={2}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"
/>
</svg>
<div className="group inline-block relative transition ease-in-out delay-300">
<Link to={"/profile"}>
<img
className="h-10 w-10 rounded-full cursor-pointer"
src={
profilePic
? `${User.photoURL}`
: `https://www.citypng.com/public/uploads/preview/profile-user-round-red-icon-symbol-download-png-11639594337tco5j3n0ix.png`
}
alt="NETFLIX"
/>
</Link>
<ul class="absolute hidden text-white pt-1 -ml-32 group-hover:block transition ease-in-out delay-150">
<li>
<Link
to={"/profile"}
className="cursor-pointer rounded-t bg-stone-900 font-bold hover:border-l-4 hover:bg-gradient-to-r from-[#ff000056] border-red-800 py-2 px-4 block whitespace-no-wrap transition ease-in-out delay-150"
>
Profile
</Link>
</li>
<li>
<Link
to={"/signin"}
className="cursor-pointer bg-stone-900 font-semibold hover:border-l-4 hover:bg-gradient-to-r from-[#ff000056] border-red-800 py-2 px-4 block whitespace-no-wrap transition ease-in-out delay-150"
>
Add another User
</Link>
</li>
<li>
<a
onClick={SignOut}
className="cursor-pointer rounded-b bg-stone-900 font-bold hover:border-l-4 hover:bg-gradient-to-r from-[#ff000056] border-red-800 py-2 px-4 block whitespace-no-wrap transition ease-in-out delay-150"
>
Sign Out
</a>
</li>
</ul>
</div>
</div>
</div>
<div className="flex pl-4 -mr-2 md:hidden">
<button
onClick={() => setIsOpen(!isOpen)}
type="button"
className="inline-flex items-center justify-center p-2 text-gray-400 bg-gray-900 rounded-md hover:text-white hover:bg-gray-800 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-800 focus:ring-white"
aria-controls="mobile-menu"
aria-expanded="false"
>
<span className="sr-only">Open main menu</span>
{!isOpen ? (
<svg
className="block w-6 h-6"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
aria-hidden="true"
onClick={NavBlack}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M4 6h16M4 12h16M4 18h16"
/>
</svg>
) : (
<svg
className="block w-6 h-6"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
aria-hidden="true"
onClick={NavTransparent}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M6 18L18 6M6 6l12 12"
/>
</svg>
)}
</button>
</div>
</div>
</div>
<Transition
show={isOpen}
enter="transition ease-out duration-100 transform"
enterFrom="opacity-0 scale-95"
enterTo="opacity-100 scale-100"
leave="transition ease-in duration-75 transform"
leaveFrom="opacity-100 scale-100"
leaveTo="opacity-0 scale-95"
>
{(ref) => (
<div className="md:hidden" id="mobile-menu">
<div ref={ref} className="px-2 pt-2 pb-3 space-y-1 sm:px-3">
<Link to={"/"}>
<a className="block px-3 py-2 text-base font-medium text-white rounded-md hover:bg-red-800">
Home
</a>
</Link>
<Link to={"/series"}>
<a className="block px-3 py-2 text-base font-medium text-gray-300 rounded-md hover:bg-red-800 hover:text-white">
TV-Series
</a>
</Link>
<Link to={"/history"}>
<a className="block px-3 py-2 text-base font-medium text-gray-300 rounded-md hover:bg-red-800 hover:text-white">
History
</a>
</Link>
<Link to={"/liked"}>
<a className="block px-3 py-2 text-base font-medium text-gray-300 rounded-md hover:bg-red-800 hover:text-white">
Liked
</a>
</Link>
<Link to={"/mylist"}>
<a className="block px-3 py-2 text-base font-medium text-gray-300 rounded-md hover:bg-red-800 hover:text-white">
My-List
</a>
</Link>
<Link to={"/signin"}>
<a className="block px-3 py-2 text-base font-medium text-gray-300 rounded-md hover:bg-red-800 hover:text-white">
Add another user
</a>
</Link>
<a
onClick={SignOut}
className="block px-3 py-2 text-base font-medium text-gray-300 rounded-md hover:bg-red-800 hover:text-white"
>
Sign Out
</a>
</div>
</div>
)}
</Transition>
</nav>
</header>
</Fade>
);
}
export default Navbar;
|