Skip to content

Commit

Permalink
Merge pull request #461 from CodeForAfrica/chore/charterafrica_reuse_…
Browse files Browse the repository at this point in the history
…page

@/charterafrica reuse page
  • Loading branch information
kilemensi committed Jun 26, 2023
2 parents a59930f + 05df607 commit a06087b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 39 deletions.
4 changes: 2 additions & 2 deletions apps/charterafrica/src/lib/data/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ async function processGlobalBlockFocalCountries(block) {
}

async function processGlobalBlockHelpdesk(block) {
const { description, image, link, slug, title } = block || {};
const { description, id, image, link, slug, title } = block || {};
if (!title?.length) {
return null;
}

const helpdesk = { slug, title };
const helpdesk = { id, slug, title };
if (description?.length) {
helpdesk.description = description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ async function processPageExplainers(page, api, context) {
const { title, blocks } = page;
if (explainers?.length) {
blocks.push({
id: page.id,
explainers,
slug: "explainers",
title,
explainers,
});
}

Expand Down
2 changes: 2 additions & 0 deletions apps/charterafrica/src/pages/[...slugs].page.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Helpdesk from "@/charterafrica/components/Helpdesk";
import HelpdeskPageContent from "@/charterafrica/components/HelpdeskPageContent";
import Hero from "@/charterafrica/components/Hero";
import Impressum from "@/charterafrica/components/Impressum";
import Infographic from "@/charterafrica/components/Infographic";
import LongForm from "@/charterafrica/components/LongForm";
import Mooc from "@/charterafrica/components/Mooc";
import Opportunity from "@/charterafrica/components/Opportunity";
Expand All @@ -39,6 +40,7 @@ import Tools from "@/charterafrica/components/Tools";
import { getPageServerSideProps } from "@/charterafrica/lib/data";

const componentsBySlugs = {
"aga-infographic": Infographic,
datasets: Datasets,
dataset: Dataset,
documents: Documents,
Expand Down
42 changes: 6 additions & 36 deletions apps/charterafrica/src/pages/index.page.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,10 @@
import React from "react";

import Ecosystem from "@/charterafrica/components/Ecosystem";
import FocalCountries from "@/charterafrica/components/FocalCountries";
import Helpdesk from "@/charterafrica/components/Helpdesk";
import Hero from "@/charterafrica/components/Hero";
import Infographic from "@/charterafrica/components/Infographic";
import Mooc from "@/charterafrica/components/Mooc";
import Partners from "@/charterafrica/components/Partners";
import Resources from "@/charterafrica/components/Resources";
import Spotlight from "@/charterafrica/components/Spotlight";
import { getPageServerSideProps } from "@/charterafrica/lib/data";

const componentsBySlugs = {
ecosystem: Ecosystem,
"focal-countries": FocalCountries,
helpdesk: Helpdesk,
hero: Hero,
"aga-infographic": Infographic,
mooc: Mooc,
"our-partners": Partners,
"our-resources": Resources,
spotlight: Spotlight,
};

function Index({ blocks }) {
return blocks?.map((block) => {
const Component = componentsBySlugs[block?.slug];
if (!Component) {
return null;
}
return <Component {...block} key={block.id} />;
});
}
import Page, {
getServerSideProps as sharedGetServerSideProps,
} from "./[...slugs].page";

export async function getServerSideProps(context) {
return getPageServerSideProps(context);
const func = sharedGetServerSideProps.bind(this);
return func(context);
}

export default Index;
export default Page;

1 comment on commit a06087b

@vercel
Copy link

@vercel vercel bot commented on a06087b Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.