Skip to content

Commit

Permalink
fix(website): set correct array length
Browse files Browse the repository at this point in the history
  • Loading branch information
cedoor committed Nov 8, 2023
1 parent 2935055 commit e660f1f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions apps/website/src/components/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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"
Expand All @@ -28,7 +29,7 @@ export default function Carousel({ title, sizes, type, ...props }: CarouselProps
const size = useBreakpointValue<number>(sizes)

const nextProject = useCallback(() => {
if (index + 1 === Math.ceil(projects.length / size!)) {
if (index + 1 === Math.ceil(getDataLength(type) / size!)) {
setIndex(0)
} else {
setIndex((prevIndex) => prevIndex + 1)
Expand All @@ -37,7 +38,7 @@ export default function Carousel({ title, sizes, type, ...props }: CarouselProps

const previousProject = useCallback(() => {
if (index === 0) {
setIndex(Math.ceil(projects.length / size!) - 1)
setIndex(Math.ceil(getDataLength(type) / size!) - 1)
} else {
setIndex((prevIndex) => prevIndex - 1)
}
Expand Down
16 changes: 16 additions & 0 deletions apps/website/src/utils/getDataLength.ts
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit e660f1f

Please sign in to comment.