-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from UoaWDCC/129_make-branch-dynamic
129 make navbar dynamic
- Loading branch information
Showing
12 changed files
with
260 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
"use client"; | ||
|
||
import { getLargestImageUrl } from "@/util/image"; | ||
import { motion } from "framer-motion"; | ||
import Image from "next/image"; | ||
import Link from "next/link"; | ||
import { useState } from "react"; | ||
import Cross from "../svg/Cross"; | ||
import Hamburger from "../svg/Hamburger"; | ||
import UpArrow from "../svg/UpArrow"; | ||
import { HeaderData } from "./headerTypes"; | ||
interface SmallNavbarProps { | ||
data: HeaderData; | ||
} | ||
|
||
export default function SmallNavbar({ data }: SmallNavbarProps) { | ||
const [menuOpen, setMenuOpen] = useState(false); | ||
const [projectsOpen, setProjectsOpen] = useState(false); | ||
const [membersOpen, setMembersOpen] = useState(false); | ||
const logoSrc = getLargestImageUrl(data?.Logo); | ||
const links = data?.navigation; | ||
|
||
console.log(links); | ||
const toggleMenu = () => { | ||
setMenuOpen(!menuOpen); | ||
setProjectsOpen(false); | ||
setMembersOpen(false); | ||
}; | ||
|
||
const toggleProjects = () => { | ||
setProjectsOpen(!projectsOpen); | ||
}; | ||
|
||
const toggleMembers = () => { | ||
setMembersOpen(!membersOpen); | ||
}; | ||
|
||
return ( | ||
<header | ||
className={`text-white w-full p-4 sm:hidden ${menuOpen ? "relative" : "absolute"}`} | ||
> | ||
<div className="flex justify-between items-center w-full"> | ||
<div className="text-lg font-bold"> | ||
<Link href="/"> | ||
<Image | ||
src={logoSrc} | ||
alt="Younite Logo" | ||
className="h-20 w-auto" | ||
height={128} | ||
width={256} | ||
priority | ||
/> | ||
</Link> | ||
</div> | ||
<div className="md:hidden"> | ||
<button onClick={toggleMenu}> | ||
{menuOpen ? <Cross /> : <Hamburger />} | ||
</button> | ||
</div> | ||
</div> | ||
|
||
{menuOpen && ( | ||
<motion.div | ||
className="top-full relative left-0 w-full m-2 ml-0 mt-4 -mb-40" | ||
initial={{ opacity: 0 }} | ||
animate={{ opacity: 1 }} | ||
transition={{ type: "spring", bounce: 0, duration: 0.5 }} | ||
> | ||
<div className="flex flex-col justify-items-stretch ml-2"> | ||
<div> | ||
<button onClick={toggleMembers} className="mb-2"> | ||
MEMBERS | ||
{membersOpen ? ( | ||
<UpArrow className="origin-center rotate-0" /> | ||
) : ( | ||
<UpArrow className="origin-[50%_40%] rotate-[180deg]" /> | ||
)} | ||
</button> | ||
{membersOpen && ( | ||
<div className="flex flex-col"> | ||
{data.members.map( | ||
({ CommitteeYear }: { CommitteeYear: number }) => ( | ||
<Link | ||
onClick={toggleMenu} | ||
href={`/members/${CommitteeYear}`} | ||
key={CommitteeYear} | ||
className="mb-2 ml-4 min-w-16" | ||
> | ||
{CommitteeYear} | ||
</Link> | ||
), | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
|
||
<div> | ||
<button onClick={toggleProjects}> | ||
PROJECTS | ||
{projectsOpen ? ( | ||
<UpArrow className="origin-center rotate-0" /> | ||
) : ( | ||
<UpArrow className="origin-[50%_40%] rotate-[180deg]" /> | ||
)} | ||
</button> | ||
{projectsOpen && ( | ||
<div className="flex top-full flex-col py-1 ml-4"> | ||
<Link | ||
href="/projects/active" | ||
className="my-1 min-w-16" | ||
onClick={toggleMenu} | ||
> | ||
ACTIVE | ||
</Link> | ||
<Link href="/projects/past" className="mt-1 min-w-16"> | ||
PAST | ||
</Link> | ||
</div> | ||
)} | ||
</div> | ||
|
||
{links.map((link) => ( | ||
<Link | ||
className="mt-2" | ||
href={link.slug} | ||
key={link.title} | ||
onClick={toggleMenu} | ||
> | ||
{link.title.toLocaleUpperCase()} | ||
</Link> | ||
))} | ||
</div> | ||
</motion.div> | ||
)} | ||
</header> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import SmallNavbar from "../header/SmallNavbar"; | ||
import { getHeaderData } from "../header/headerDataFetcher"; | ||
|
||
export default async function SmallNavbarFetcher() { | ||
const headerData = await getHeaderData(); | ||
return <SmallNavbar data={headerData} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import fetchStrapi from "@/util/strapi"; | ||
import { headerSchema } from "@/schemas/single/Header"; | ||
import { z } from "zod"; | ||
|
||
export async function getHeaderData() { | ||
const resData = await fetchStrapi("header", headerSchema); | ||
const membersData = await fetchStrapi("member-teams", z.any()); | ||
const members = Array.isArray(membersData) | ||
? membersData.map((item) => ({ | ||
...item, | ||
CommitteeYear: Number(item.CommitteeYear), | ||
})).sort((a, b) => b.CommitteeYear - a.CommitteeYear) | ||
: []; | ||
|
||
const projects = [ | ||
{ Title: new Date().getFullYear().toString(), slug: "current" }, | ||
{ Title: "Past", slug: "past" }, | ||
]; | ||
|
||
return { | ||
...resData, | ||
members, | ||
projects, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export type Navigation = { | ||
title: string; | ||
slug: string; | ||
}; | ||
|
||
export type Member = { | ||
CommitteeYear: number; | ||
}; | ||
|
||
export type Project = { | ||
Title: string; | ||
slug: string; | ||
}; | ||
|
||
export type HeaderData = { | ||
navigation: Navigation[]; | ||
Logo?: any; | ||
members: Member[]; | ||
projects?: Project[]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export default function Cross() { | ||
return ( | ||
<svg | ||
className={`w-6 h-6 mr-2`} | ||
fill="none" | ||
stroke="currentColor" | ||
viewBox="0 0 24 24" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth={2} | ||
d="M6 18L18 6M6 6l12 12" | ||
/> | ||
</svg> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export default function Hamburger() { | ||
return ( | ||
<svg | ||
className={`w-6 h-6 mr-2`} | ||
fill="none" | ||
stroke="currentColor" | ||
viewBox="0 0 24 24" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth={2} | ||
d="M4 6h16 M4 12h16 M4 18h16" | ||
/> | ||
</svg> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export default function UpArrow({ className = "" }: { className?: String }) { | ||
return ( | ||
<svg | ||
className={`w-6 h-6 ml-1 inline ${className}`} | ||
fill="none" | ||
stroke="currentColor" | ||
viewBox="0 0 24 24" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth={2} | ||
d="M6 13 L11 7 L16 13" | ||
/> | ||
</svg> | ||
); | ||
} |