diff --git a/components/Carousel.tsx b/components/Carousel.tsx index c9f7b18..81c1252 100644 --- a/components/Carousel.tsx +++ b/components/Carousel.tsx @@ -1,3 +1,4 @@ +/* eslint-disable react-hooks/exhaustive-deps */ import styles from "@/styles/Carousel.module.css"; import React, { useCallback, useEffect, useRef } from "react"; import Link from "next/link"; @@ -8,6 +9,7 @@ import { } from "embla-carousel"; import useEmblaCarousel from "embla-carousel-react"; import { NextButton, PrevButton, usePrevNextButtons } from "./CarouselArrows"; +import Image from "next/image"; const TWEEN_FACTOR_BASE = 0.84; @@ -93,10 +95,12 @@ const Carousel: React.FC = (props) => {
{slides.map((index) => (
- Your alt text
))} diff --git a/components/Navbar.tsx b/components/Navbar.tsx index 70aa401..e36d51f 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -1,3 +1,4 @@ +/* eslint-disable react-hooks/exhaustive-deps */ import styles from "@/styles/Navbar.module.css"; import Box from "@mui/material/Box"; import Button from "@mui/material/Button"; @@ -14,6 +15,8 @@ import { useState, useEffect } from "react"; import close from "../public/close.svg"; import menu from "../public/menu.svg"; import sato_logo_nav from "../public/sato_logo_nav.png"; +import { ListSubheader } from "@mui/material"; +import { useRouter } from "next/router"; type Anchor = "right"; @@ -21,8 +24,49 @@ const Navbar = () => { const [state, setState] = useState({ right: false, }); + const [cmsData, setCmsData] = useState({ data: [] }); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + const router = useRouter(); + const currentRoute = router.pathname; + const navGeneral = cmsData.data.slice(0, 4); + const navForMembers = cmsData.data.slice(4); useEffect(() => { + // Import text + const fetchData = async () => { + setLoading(true); + setError(null); + + const collectionName: string = "Nav"; + const url = `${process.env.NEXT_PUBLIC_DIRECTUS_URL}items/${collectionName}`; + const headers = { + "Content-Type": "application/json", + }; + + try { + const response = await fetch(url, { + method: "GET", + headers, + }); + if (!response.ok) { + throw new Error(`Error: ${response.status} ${response.statusText}`); + } + const result = await response.json(); + setCmsData(result); + } catch (err) { + if (err instanceof Error) { + setError(err.message); + } else { + setError("An unknown error occurred"); + } + } finally { + setLoading(false); + } + }; + fetchData(); + + // Scroll to hide header let prevScrollpos = window.scrollY; const handleScroll = () => { const currentScrollpos = window.scrollY; @@ -41,6 +85,7 @@ const Navbar = () => { return () => window.removeEventListener("scroll", handleScroll); }, []); + // MUI Drawer toggling const toggleDrawer = (anchor: Anchor, open: boolean) => (event: React.KeyboardEvent | React.MouseEvent) => { @@ -66,27 +111,68 @@ const Navbar = () => { close icon - - {["Inbox", "Starred", "Send email", "Drafts"].map((text, index) => ( - - - - - - - ))} + {/* {cmsData.data.map((data: any) => ( +

{data.text_en}

+ ))} */} + + {navGeneral.map((data: CMSItem) => { + const route = + data.text_en.toLowerCase() === "home" + ? "/" + : `/${data.text_en.toLowerCase().replace(" ", "-")}`; + + return ( + + + + + {data.text_en} + + + + ); + })} +
- - {["All mail", "Trash", "Spam"].map((text, index) => ( - + For Members + + {navForMembers.map((data: any) => ( + - + + {data.text_en} + ))} + +
+ + Languages +
+ + + + +
); diff --git a/hooks/types.ts b/hooks/types.ts new file mode 100644 index 0000000..57d6901 --- /dev/null +++ b/hooks/types.ts @@ -0,0 +1,14 @@ +type CMSItem = { + id: number; + user_created: null; + date_created: string; + user_updated: null; + date_updated: string | null; + text_en: string; + text_fi: string; + text_sv: string; +}; + +type CMSData = { + data: CMSItem[]; +}; diff --git a/pages/nation-info.tsx b/pages/nation-info.tsx new file mode 100644 index 0000000..71bab37 --- /dev/null +++ b/pages/nation-info.tsx @@ -0,0 +1,9 @@ +import Navbar from "@/components/Navbar"; + +export default function NationInfo() { + return ( + <> + + + ); +} diff --git a/styles/Navbar.module.css b/styles/Navbar.module.css index 0309602..ade94bf 100644 --- a/styles/Navbar.module.css +++ b/styles/Navbar.module.css @@ -17,3 +17,16 @@ align-items: center; top: 0; } + +.navLink { + text-decoration: none; + font-size: 1.2rem; + color: var(--black); +} + +.navLinkActive { + text-decoration: none; + font-size: 1.2rem; + font-weight: 700; + color: var(--orange200); +}