-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load and show Team and Summary blocks on FE pages
- Loading branch information
Showing
2 changed files
with
57 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,44 @@ | ||
import React from "react"; | ||
import { SWRConfig } from "swr"; | ||
|
||
import AboutTeam from "@/climatemappedafrica/components/AboutTeam"; | ||
import Page from "@/climatemappedafrica/components/Page"; | ||
import Summary from "@/climatemappedafrica/components/Summary"; | ||
import { getPageServerSideProps } from "@/climatemappedafrica/lib/data"; | ||
|
||
export default function Index(props) { | ||
return <Page {...props} />; | ||
const componentsBySlugs = { | ||
summary: Summary, | ||
team: AboutTeam, | ||
}; | ||
|
||
function Index({ blocks, fallback, ...props }) { | ||
if (!blocks?.length) { | ||
return null; | ||
} | ||
|
||
let PageConfig = React.Fragment; | ||
let pageConfigProps; | ||
if (fallback) { | ||
PageConfig = SWRConfig; | ||
pageConfigProps = { value: { fallback } }; | ||
} | ||
return ( | ||
<Page {...props}> | ||
<PageConfig {...pageConfigProps}> | ||
{blocks.map((block) => { | ||
const Component = componentsBySlugs[block.slug]; | ||
if (!Component) { | ||
return null; | ||
} | ||
return <Component {...block} key={block.slug} />; | ||
})} | ||
</PageConfig> | ||
</Page> | ||
); | ||
} | ||
|
||
export async function getServerSideProps(context) { | ||
return getPageServerSideProps(context); | ||
} | ||
|
||
export default Index; |