-
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.
Create helper useSamveraPartners hook for multiple data fetches from CMS
- Loading branch information
1 parent
5d1853a
commit fce5330
Showing
7 changed files
with
120 additions
and
79 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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
import Breadcrumbs from "components/Breadcrumbs"; | ||
import Layout from "../layout/Layout"; | ||
import Main from "components/layout/Main"; | ||
import MarkdownContent from "components/MarkdownContent"; | ||
import useSamveraPartners from "hooks/use-samvera-partners"; | ||
|
||
export default function SamveraPartners({ config, content, frontmatter }) { | ||
const { partners } = useSamveraPartners(); | ||
|
||
return ( | ||
<Layout title={`${frontmatter.title} - ${config.parentDirLabel} - Samvera`}> | ||
<Breadcrumbs | ||
items={[ | ||
{ | ||
href: "/", | ||
label: config.parentDirLabel, | ||
}, | ||
{ | ||
label: frontmatter.title, | ||
}, | ||
]} | ||
/> | ||
|
||
<h1>{frontmatter.title}</h1> | ||
|
||
<Main> | ||
<ul className="grid grid-cols-2 gap-4 ml-0 list-none lg:gap-6 lg:px-10 md:grid-cols-3 xl:grid-cols-4"> | ||
{partners.map(({ id, name, url }) => ( | ||
<li key={id} className="text-left"> | ||
{!url && name} | ||
{url && ( | ||
<a | ||
href={url} | ||
className="text-samGreyDark hover:text-samDarkRed" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
{name} | ||
</a> | ||
)} | ||
</li> | ||
))} | ||
</ul> | ||
<hr /> | ||
|
||
<MarkdownContent content={content} /> | ||
</Main> | ||
</Layout> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
import getContentful from "lib/get-contentful"; | ||
|
||
export default function useSamveraPartners() { | ||
const contentful = getContentful(); | ||
|
||
const [partners, setPartners] = useState([]); | ||
|
||
useEffect(() => { | ||
(async function init() { | ||
const partners = await contentful.getEntries({ | ||
content_type: "samveraPartner", | ||
}); | ||
|
||
if (!partners.items) { | ||
return console.error("Error getting partners."); | ||
} | ||
|
||
const sorted = partners.items.sort((a, b) => | ||
a.fields.name.localeCompare(b.fields.name) | ||
); | ||
const groomedData = sorted.map((record) => ({ | ||
...record.fields, | ||
id: record.sys.id, | ||
})); | ||
setPartners(groomedData); | ||
})(); | ||
}, [contentful]); | ||
|
||
return { partners }; | ||
} |
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
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 |
---|---|---|
|
@@ -55,6 +55,10 @@ strong { | |
@apply font-fontinBold; | ||
} | ||
|
||
hr { | ||
@apply my-8; | ||
} | ||
|
||
.ul-disc { | ||
@apply ml-4 list-disc; | ||
} | ||
|