From ff57948f10c622ebef7f8d42309f03511d88f033 Mon Sep 17 00:00:00 2001 From: Nico Schett Date: Thu, 2 May 2024 12:01:43 +0200 Subject: [PATCH] feat: improve `moreCaseStudies` and `moreBlogs` --- src/templates/BlogTemplate.tsx | 15 ++++++++++++--- src/templates/WorkTemplate.tsx | 15 ++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/templates/BlogTemplate.tsx b/src/templates/BlogTemplate.tsx index e9cb216..2d3868e 100644 --- a/src/templates/BlogTemplate.tsx +++ b/src/templates/BlogTemplate.tsx @@ -18,9 +18,18 @@ const Page: React.FC = () => { const index = useJaenPageIndex({ jaenPageId: "JaenPage /blog/" }); const moreBlogs = useMemo(() => { - return index.childPages + const currentIndex = index.childPages.findIndex( + (childPage) => childPage.id === page.id + ); + + const nextPages = [ + ...index.childPages.slice(currentIndex + 1), + ...index.childPages.slice(0, currentIndex), + ]; // Reorder the array to start from the current page's position + + return nextPages .filter((childPage) => childPage.id !== page.id) - .slice(0, 2) + .slice(0, 2) // Take the next two pages .map((childPage) => { return { title: childPage.jaenPageMetadata?.title, @@ -29,7 +38,7 @@ const Page: React.FC = () => { href: `/blog/${childPage.slug}`, }; }); - }, [index]); + }, [index, page.id]); const date = page.jaenPageMetadata?.blogPost?.date || ""; diff --git a/src/templates/WorkTemplate.tsx b/src/templates/WorkTemplate.tsx index 476519b..0f21f11 100644 --- a/src/templates/WorkTemplate.tsx +++ b/src/templates/WorkTemplate.tsx @@ -373,14 +373,19 @@ const Page: React.FC = withCMSManagement(() => { const page = usePage({}); const manager = useCMSManagementContext(); - console.log("apge", page); - const index = useJaenPageIndex({ jaenPageId: "JaenPage /work/" }); const moreCaseStudies = useMemo(() => { - return index.childPages + const currentIndex = index.childPages.findIndex( + (childPage) => childPage.id === page.id + ); + const nextPages = [ + ...index.childPages.slice(currentIndex + 1), + ...index.childPages.slice(0, currentIndex), + ]; // Reorder the array to start from the current page's position + return nextPages .filter((childPage) => childPage.id !== page.id) - .slice(0, 2) + .slice(0, 2) // Take the next two pages .map((childPage) => { return { title: childPage.jaenPageMetadata?.title, @@ -389,7 +394,7 @@ const Page: React.FC = withCMSManagement(() => { href: `/work/${childPage.slug}`, }; }); - }, [index]); + }, [index, page.id]); const clientField = useField("client", "IMA:TextField"); const clientValue = clientField.value || clientField.staticValue || "";