diff --git a/apps/website/src/app/learn/page.tsx b/apps/website/src/app/learn/page.tsx index 93c6d0c5f..303e7e891 100644 --- a/apps/website/src/app/learn/page.tsx +++ b/apps/website/src/app/learn/page.tsx @@ -15,7 +15,6 @@ import { import Image from "next/image" import InfoCard, { InfoBlock } from "../../components/InfoCard" import SectionBlock, { SectionBlockProps } from "../../components/SectionBlock" -import MediaCarousel from "../../components/VideosCarousel" import IconEyelash from "@/icons/IconEyelash" import IconEye from "@/icons/IconEye" import IconUser from "@/icons/IconUser" @@ -25,7 +24,7 @@ import IconGroup from "@/icons/IconGroup" import IconBadge from "@/icons/IconBadge" import IconCheck from "@/icons/IconCheck" import IconFlag from "@/icons/IconFlag" -import ArticlesCarousel from "@/components/ArticlesCarousel" +import Carousel from "@/components/Carousel" export default function Learn() { const infoCardTexts: InfoBlock[][] = [ @@ -270,6 +269,7 @@ await verifyProof(verificationKey, fullProof)`, + {sectionBlockTexts.map((sectionBlockText, i) => ( @@ -286,13 +286,37 @@ await verifyProof(verificationKey, fullProof)`, ))} - - - - + + - - + + + + diff --git a/apps/website/src/app/page.tsx b/apps/website/src/app/page.tsx index b69bffa3f..b72d8c878 100644 --- a/apps/website/src/app/page.tsx +++ b/apps/website/src/app/page.tsx @@ -1,8 +1,10 @@ import { Box, Button, Card, CardBody, Heading, HStack, Link, Stack, Text, VStack } from "@chakra-ui/react" import { Sora } from "next/font/google" import Image from "next/image" -import ProjectsCarousel from "../components/ProjectsCarousel" +import Carousel from "../components/Carousel" +import ProjectCard from "../components/ProjectCard" import events from "../data/events.json" +import projects from "../data/projects.json" import IconDiscord from "../icons/IconDiscord" const sora = Sora({ @@ -49,11 +51,26 @@ export default function Home() { - - Explore projects built with Semaphore - + - + + + Explore projects built with Semaphore + + + + {projects.slice(0, 3).map((project) => ( + + + + ))} + + (0) - const numberOfItems = useBreakpointValue({ - base: 1, - md: 2, - lg: 4 - }) - - const nextProject = useCallback(() => { - if (index + 1 === Math.ceil(articles.length / numberOfItems!)) { - setIndex(0) - } else { - setIndex((prevIndex) => prevIndex + 1) - } - }, [index, numberOfItems]) - - const previousProject = useCallback(() => { - if (index === 0) { - setIndex(Math.ceil(articles.length / numberOfItems!) - 1) - } else { - setIndex((prevIndex) => prevIndex - 1) - } - }, [index]) - - return ( - <> - - - - Articles - - - - - } - /> - } - /> - - - - - {articles.map((article, i) => ( - - - - - - ))} - - - - ) -} diff --git a/apps/website/src/components/Carousel.tsx b/apps/website/src/components/Carousel.tsx new file mode 100644 index 000000000..079e9a72b --- /dev/null +++ b/apps/website/src/components/Carousel.tsx @@ -0,0 +1,155 @@ +"use client" + +import { Box, HStack, Heading, IconButton, Link, StackProps, VStack, useBreakpointValue } from "@chakra-ui/react" +import NextLink from "next/link" +import { useCallback, useState } from "react" +import articles from "../data/articles.json" +import projects from "../data/projects.json" +import videos from "../data/videos.json" +import IconArrowLeft from "../icons/IconArrowLeft" +import IconArrowRight from "../icons/IconArrowRight" +import { getDataLength } from "../utils/getDataLength" +import ArticleCard from "./ArticleCard" +import ProjectCard from "./ProjectCard" +import VideoCard from "./VideoCard" + +export type CarouselProps = { + title: string + sizes: { + base?: number + sm?: number + md?: number + lg?: number + } + type: "projects" | "videos" | "articles" +} + +export default function Carousel({ title, sizes, type, ...props }: CarouselProps & StackProps) { + const [index, setIndex] = useState(0) + const size = useBreakpointValue(sizes) + + const nextProject = useCallback(() => { + if (index + 1 === Math.ceil(getDataLength(type) / size!)) { + setIndex(0) + } else { + setIndex((prevIndex) => prevIndex + 1) + } + }, [index, size]) + + const previousProject = useCallback(() => { + if (index === 0) { + setIndex(Math.ceil(getDataLength(type) / size!) - 1) + } else { + setIndex((prevIndex) => prevIndex - 1) + } + }, [index]) + + return ( + + + + {title} + + + {type !== "projects" && ( + + } + /> + } + /> + + )} + + + + + {type === "projects" && + projects.map((project, i) => ( + + + + + + ))} + + {type === "articles" && + articles.map((article, i) => ( + + + + ))} + + {type === "videos" && + videos.map((video, i) => ( + + + + ))} + + + + {type === "projects" && ( + + + + + } + /> + } + /> + + + + + View more + + + + )} + + ) +} diff --git a/apps/website/src/components/ProjectsCarousel.tsx b/apps/website/src/components/ProjectsCarousel.tsx deleted file mode 100644 index 91598b455..000000000 --- a/apps/website/src/components/ProjectsCarousel.tsx +++ /dev/null @@ -1,101 +0,0 @@ -"use client" - -import { Box, HStack, IconButton, Link, VStack, useBreakpointValue } from "@chakra-ui/react" -import NextLink from "next/link" -import { useCallback, useState } from "react" -import projects from "../data/projects.json" -import IconArrowLeft from "../icons/IconArrowLeft" -import IconArrowRight from "../icons/IconArrowRight" -import ProjectCard from "./ProjectCard" - -export default function ProjectsCarousel() { - const [index, setIndex] = useState(0) - const numberOfItems = useBreakpointValue({ - md: 2, - lg: 3 - }) - - const nextProject = useCallback(() => { - if (index + 1 === Math.ceil(projects.length / numberOfItems!)) { - setIndex(0) - } else { - setIndex((prevIndex) => prevIndex + 1) - } - }, [index, numberOfItems]) - - const previousProject = useCallback(() => { - if (index === 0) { - setIndex(Math.ceil(projects.length / numberOfItems!) - 1) - } else { - setIndex((prevIndex) => prevIndex - 1) - } - }, [index]) - - return ( - <> - - - {projects.map((project) => ( - - - - - - ))} - - - - - {projects.slice(0, 3).map((project) => ( - - - - ))} - - - - - - - } - /> - } - /> - - - - - View more - - - - - ) -} diff --git a/apps/website/src/components/VideosCarousel.tsx b/apps/website/src/components/VideosCarousel.tsx deleted file mode 100644 index ac5ae7be5..000000000 --- a/apps/website/src/components/VideosCarousel.tsx +++ /dev/null @@ -1,77 +0,0 @@ -"use client" - -import { Box, HStack, IconButton, VStack, useBreakpointValue, Text } from "@chakra-ui/react" -import { useCallback, useState } from "react" -import videos from "../data/videos.json" -import IconArrowLeft from "../icons/IconArrowLeft" -import IconArrowRight from "../icons/IconArrowRight" -import VideoCard from "./VideoCard" - -export default function VideosCarousel() { - const [index, setIndex] = useState(0) - const numberOfItems = useBreakpointValue({ - base: 1, - md: 2, - lg: 4 - }) - - const nextProject = useCallback(() => { - if (index + 1 === Math.ceil(videos.length / numberOfItems!)) { - setIndex(0) - } else { - setIndex((prevIndex) => prevIndex + 1) - } - }, [index, numberOfItems]) - - const previousProject = useCallback(() => { - if (index === 0) { - setIndex(Math.ceil(videos.length / numberOfItems!) - 1) - } else { - setIndex((prevIndex) => prevIndex - 1) - } - }, [index]) - - return ( - <> - - - - Videos - - - - - } - /> - } - /> - - - - - {videos.map((video, i) => ( - - - - - - ))} - - - - ) -} diff --git a/apps/website/src/utils/getDataLength.ts b/apps/website/src/utils/getDataLength.ts new file mode 100644 index 000000000..daf17cefb --- /dev/null +++ b/apps/website/src/utils/getDataLength.ts @@ -0,0 +1,16 @@ +import projects from "../data/projects.json" +import videos from "../data/videos.json" +import articles from "../data/articles.json" + +export function getDataLength(type: "projects" | "videos" | "articles"): number { + switch (type) { + case "projects": + return projects.length + case "videos": + return videos.length + case "articles": + return articles.length + default: + return 0 + } +}