Skip to content

Commit

Permalink
feat: improve moreCaseStudies and moreBlogs
Browse files Browse the repository at this point in the history
  • Loading branch information
schettn committed May 2, 2024
1 parent c0db0d2 commit ff57948
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
15 changes: 12 additions & 3 deletions src/templates/BlogTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@ const Page: React.FC<PageProps> = () => {
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,
Expand All @@ -29,7 +38,7 @@ const Page: React.FC<PageProps> = () => {
href: `/blog/${childPage.slug}`,
};
});
}, [index]);
}, [index, page.id]);

const date = page.jaenPageMetadata?.blogPost?.date || "";

Expand Down
15 changes: 10 additions & 5 deletions src/templates/WorkTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,19 @@ const Page: React.FC<PageProps> = 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,
Expand All @@ -389,7 +394,7 @@ const Page: React.FC<PageProps> = withCMSManagement(() => {
href: `/work/${childPage.slug}`,
};
});
}, [index]);
}, [index, page.id]);

const clientField = useField<string>("client", "IMA:TextField");
const clientValue = clientField.value || clientField.staticValue || "";
Expand Down

0 comments on commit ff57948

Please sign in to comment.