diff --git a/apps/website/src/app/page.tsx b/apps/website/src/app/page.tsx index 9e65badac..f5d627793 100644 --- a/apps/website/src/app/page.tsx +++ b/apps/website/src/app/page.tsx @@ -46,7 +46,7 @@ export default function Home() { - + Explore projects built with Semaphore @@ -54,7 +54,15 @@ export default function Home() { - + diff --git a/apps/website/src/components/ProjectsCarousel.tsx b/apps/website/src/components/ProjectsCarousel.tsx index bedf3d63a..91598b455 100644 --- a/apps/website/src/components/ProjectsCarousel.tsx +++ b/apps/website/src/components/ProjectsCarousel.tsx @@ -1,53 +1,70 @@ "use client" -import { Box, HStack, IconButton, Link, Stack, useBreakpointValue } from "@chakra-ui/react" +import { Box, HStack, IconButton, Link, VStack, useBreakpointValue } from "@chakra-ui/react" import NextLink from "next/link" -import { useCallback, useEffect, useState } from "react" -import allProjects from "../data/projects.json" +import { useCallback, useState } from "react" +import projects from "../data/projects.json" import IconArrowLeft from "../icons/IconArrowLeft" import IconArrowRight from "../icons/IconArrowRight" -import { circularSlice } from "../utils/circularSlice" import ProjectCard from "./ProjectCard" export default function ProjectsCarousel() { - const variant = useBreakpointValue( - { - base: 3, - sm: 3, - md: 2, - lg: 3 - }, - { - fallback: "md" - } - ) - - const [projects, setProjects] = useState() const [index, setIndex] = useState(0) - - useEffect(() => { - setProjects(circularSlice(allProjects, index, variant!)) - }, [index, variant]) + const numberOfItems = useBreakpointValue({ + md: 2, + lg: 3 + }) const nextProject = useCallback(() => { - setIndex((i) => (i + 1) % allProjects.length) - }, [index]) + if (index + 1 === Math.ceil(projects.length / numberOfItems!)) { + setIndex(0) + } else { + setIndex((prevIndex) => prevIndex + 1) + } + }, [index, numberOfItems]) const previousProject = useCallback(() => { - setIndex((i) => (i === 0 ? allProjects.length - 1 : i - 1)) + if (index === 0) { + setIndex(Math.ceil(projects.length / numberOfItems!) - 1) + } else { + setIndex((prevIndex) => prevIndex - 1) + } }, [index]) return ( <> - - {projects && - projects.map((project) => ( - - + + + {projects.map((project) => ( + + + + ))} - - + + + + + {projects.slice(0, 3).map((project) => ( + + + + ))} + + +