From afd7045442dfed908e8b7d8a3c18104a1a0b7bc3 Mon Sep 17 00:00:00 2001 From: Aryan Kothari Date: Tue, 26 Dec 2023 05:43:08 +0000 Subject: [PATCH] Convert header to client component, fetch seasonList from backend --- frontend/app/components/header/header.tsx | 56 +++++++++++++++++++---- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/frontend/app/components/header/header.tsx b/frontend/app/components/header/header.tsx index 64cde6b7..201d94eb 100644 --- a/frontend/app/components/header/header.tsx +++ b/frontend/app/components/header/header.tsx @@ -1,28 +1,64 @@ +"use client"; +import {useEffect, useState} from "react"; import styles from "./header.module.scss" +import {fetchSeasonList} from "@/app/utils/clientSideFetch"; +import {useRouter} from "next/router"; - -export type NavLinks = { +type NavLinks = { label: string; - path: string; + path: string } -export type HeaderProps = { - nav_links: NavLinks[]; -} +const Header = () => { + const [navLinks, setNavLinks] = useState([]) + const router = useRouter(); + useEffect(() => { + fetchSeasonList().then(seasonList => { + setNavLinks(seasonList.reverse().map(season => { + const seasonNumber = season.split("_")[0] + return {label: `Season ${seasonNumber}`, path: `/season/${seasonNumber}`} + })) + if (router.pathname === "/" && typeof window !== undefined) { + const element = document.getElementById("curseason") + if (element) { + element.innerText = `Season ${seasonList[0].split("_")[0]}` + } + } + + if (typeof window !== undefined){ + const element = document.getElementById('navbar') + if (element){ + element.addEventListener('wheel', function(e) { + // @ts-ignore + if (e.deltaY != 0) { + // @ts-ignore + this.scrollLeft += (e.deltaY * 1.5); + e.preventDefault(); + } + }, false); + } + + } + + }) + + }, []); + -const Header = ({nav_links}: HeaderProps) => { return (

Top 500 Aggregator

-
+