diff --git a/apps/website/src/app/learn/page.tsx b/apps/website/src/app/learn/page.tsx index 1ebf316e4..3bc3fe1f5 100644 --- a/apps/website/src/app/learn/page.tsx +++ b/apps/website/src/app/learn/page.tsx @@ -29,6 +29,7 @@ import videos from "../../data/videos.json" import VideoCard from "../../components/VideoCard" import articles from "../../data/articles.json" import ArticleCard from "../../components/ArticleCard" +import { sortByDate } from "@/utils/sortByDate" export default function Learn() { const infoCardTexts: InfoBlock[][] = [ @@ -364,7 +365,7 @@ await verifyProof(verificationKey, fullProof)`, Videos - {videos.map((video) => ( + {sortByDate(videos).map((video) => ( @@ -383,7 +384,7 @@ await verifyProof(verificationKey, fullProof)`, Articles - {articles.map((article) => ( + {sortByDate(articles).map((article) => ( diff --git a/apps/website/src/components/Carousel.tsx b/apps/website/src/components/Carousel.tsx index bf12ef486..6b95faa77 100644 --- a/apps/website/src/components/Carousel.tsx +++ b/apps/website/src/components/Carousel.tsx @@ -12,6 +12,7 @@ import { getDataLength } from "../utils/getDataLength" import ArticleCard from "./ArticleCard" import ProjectCard from "./ProjectCard" import VideoCard from "./VideoCard" +import { sortByDate } from "@/utils/sortByDate" export type CarouselProps = { title: string @@ -96,7 +97,7 @@ export default function Carousel({ title, sizes, type, ...props }: CarouselProps ))} {type === "articles" && - articles.map((article) => ( + sortByDate(articles).map((article) => ( ( + sortByDate(videos).map((video) => ( { + const elem1 = new Date(a[propName]).valueOf() + const elem2 = new Date(b[propName]).valueOf() + + if (elem1 === elem2) { + return 0 + } + + if (sortType === "asc") { + return elem1 < elem2 ? -1 : 1 + } + + return elem1 > elem2 ? -1 : 1 + } +} + +/** + * Sort an array using a specific property and type descending or ascending. + * @param elems An array of objects with the property propName. + * @param propName A string which represents the property that will be used to sort. + * @param sortType The type that will be used to sort, it can be ascending or descending. + * @returns The initial array sorted. + */ +export function sortByDate(elems: any[], propName: string = "date", sortType: SortType = "desc") { + return elems.sort(propComparator(propName, sortType)) +}