Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hydration error in Header.js #674

Merged
merged 6 commits into from
Oct 8, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 30 additions & 33 deletions Website/app/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,36 @@ import Image from "next/image";
import { useState } from "react";
import Link from "next/link";
import { useCallback, useEffect } from "react";
import { useRouter } from 'next/router';
Fixed Show fixed Hide fixed
drippypop marked this conversation as resolved.
Show resolved Hide resolved

function NavLink({ to, children, cn }) {
function handleNavLinkClick(to, setOpen) {
const router = useRouter();
if (window.location.pathname === to) {
setOpen(false);
} else {
router.push(to);
Fixed Show fixed Hide fixed
}
}
drippypop marked this conversation as resolved.
Show resolved Hide resolved

function NavLink({ to, children, cn, setOpen }) {
return (
<Link
scroll={false}
href={to}
<button
onClick={() => handleNavLinkClick(to, setOpen)}
className={`text-gray-900 hover:text-black ${cn}`}
>
{children}
</Link>
</button>
drippypop marked this conversation as resolved.
Show resolved Hide resolved
);
}

function MobileNav({ open }) {
function MobileNav({ open, setOpen }) {
return (
<div
className={`fixed z-10 top-0 left-0 h-screen w-screen bg-top transform ${
!open && "-translate-x-full"
} transition-transform duration-300 ease-in-out filter drop-shadow-md`}
>
<div className="flex items-start justify-center filter bg-top h-30 m-4 z-50">
{/* Logo container */}
<Link className="text-xl font-semibold z-50" href="/">
<Image
src="Drifty1024Thinner1Px.png"
Expand All @@ -36,28 +44,29 @@ function MobileNav({ open }) {
</Link>
</div>

{/* Mobile Nav */}
<div className="flex flex-col pt-12 justify-items-center items-center z-50">
<NavLink
to="/about"
cn="text-2xl font-bold my-6 text-white hover:text-blue-700 hover:transition hover:ease-in-out delay-75 hover:-translate-y-1 hover:scale-110 duration-300 z-50"
setOpen={setOpen}
>
<button>About</button>
About
</NavLink>
<NavLink
to="/download"
cn="text-2xl font-bold my-6 text-white hover:text-blue-700 hover:transition hover:ease-in-out delay-75 hover:-translate-y-1 hover:scale-110 duration-300 z-50"
setOpen={setOpen}
>
<button>Download</button>
Download
</NavLink>
<NavLink
to="/contact"
cn="text-2xl font-bold my-6 text-white hover:text-blue-700 hover:transition hover:ease-in-out delay-75 hover:-translate-y-1 hover:scale-110 duration-300 z-50"
setOpen={setOpen}
>
<button>Contact</button>
Contact
</NavLink>

{/* Social Icons */}
<div className="flex justify-center items-center pt-10 z-50">
<a href="https://discord.gg/DeT4jXPfkG" target="_blank">
<i
Expand Down Expand Up @@ -95,9 +104,7 @@ export default function Header({ props }) {
}, [props, open]);

useEffect(() => {
// add event listener to window
window.addEventListener("scroll", onScroll, { passive: true });
// remove event listener on unmount to prevent memory leaks
return () => {
window.removeEventListener("scroll", onScroll);
};
Expand Down Expand Up @@ -128,7 +135,6 @@ export default function Header({ props }) {
}}
role={"button"}
>
{/* hamburger button */}
<span
className={`h-1 w-full bg-white rounded-lg transform transition duration-300 ease-in-out ${
open ? "rotate-45 translate-y-3.5" : ""
Expand All @@ -146,27 +152,18 @@ export default function Header({ props }) {
/>
</div>

{/* NAVBAR BUTTONS */}
<div className="hidden md:flex mr-20 ">
<NavLink to="/#" cn="mx-4 flex">
<button className="text-white hover:transition text-xl hover:scale-105 duration-300 font-extrabold">
HOME
</button>
<NavLink to="/#" cn="mx-4 flex" setOpen={setOpen}>
HOME
</NavLink>
<NavLink to="/about" cn="mx-4 flex">
<button className="text-white hover:transition text-xl hover:scale-105 duration-300 font-extrabold">
ABOUT
</button>
<NavLink to="/about" cn="mx-4 flex" setOpen={setOpen}>
ABOUT
</NavLink>
<NavLink to="/download" cn="mx-4 flex">
<button className="text-white hover:transition text-xl hover:scale-105 duration-300 font-extrabold">
DOWNLOAD
</button>
<NavLink to="/download" cn="mx-4 flex" setOpen={setOpen}>
DOWNLOAD
</NavLink>
<NavLink to="/contact" cn="mx-4 flex">
<button className="text-white hover:transition text-xl hover:scale-105 duration-300 font-extrabold">
CONTACT
</button>
<NavLink to="/contact" cn="mx-4 flex" setOpen={setOpen}>
CONTACT
</NavLink>
<a href="https://discord.gg/DeT4jXPfkG" target="_blank">
<i
Expand All @@ -187,4 +184,4 @@ export default function Header({ props }) {
</nav>
</header>
);
}
}