-
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.
Merge pull request #135 from samvera/feature/119-partners-from-cms
Wire up Samvera Partners UI to Contentful CMS data
- Loading branch information
Showing
21 changed files
with
723 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,41 @@ | ||
import Link from "next/link"; | ||
import { SAMVERA_PARTNERS } from "app-config"; | ||
import PartnersMap from "./PartnersMap"; | ||
import React from "react"; | ||
import getContentful from "lib/get-contentful"; | ||
import { useRouter } from "next/router"; | ||
import useSamveraPartners from "hooks/use-samvera-partners"; | ||
|
||
export default function BannerPartners() { | ||
const router = useRouter(); | ||
const isHomePage = router.pathname === "/"; | ||
|
||
const { partners } = useSamveraPartners(); | ||
|
||
return ( | ||
<section className="py-8 bg-samBlue"> | ||
<h3 className="pb-4 text-center title">Samvera Partners</h3> | ||
<div className="container"> | ||
<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 "> | ||
{SAMVERA_PARTNERS.map((partner) => ( | ||
<li key={partner.label} className="text-left"> | ||
<Link | ||
href={partner.href} | ||
className="text-samGreyDark hover:text-samDarkRed" | ||
> | ||
{partner.label} | ||
</Link> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
</section> | ||
<> | ||
<section className="py-8 bg-samBlue"> | ||
<h3 className="pb-4 text-center title">Samvera Partners</h3> | ||
<div className="container"> | ||
<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> | ||
</div> | ||
</section> | ||
|
||
{isHomePage && <PartnersMap partners={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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Map from "./leaflet-map/Map"; | ||
import React from "react"; | ||
|
||
const DEFAULT_CENTER = [38.907132, -77.036546]; | ||
|
||
const PartnersMap = ({ partners }) => { | ||
if (partners.length === 0) return null; | ||
|
||
return ( | ||
<> | ||
<Map width="800" height="400" center={DEFAULT_CENTER} zoom={3}> | ||
{({ TileLayer, Marker, Popup }) => ( | ||
<> | ||
<TileLayer | ||
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" | ||
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' | ||
/> | ||
{partners.map(({ id, location, name }) => { | ||
const hasLocation = location && location.lat && location.lon; | ||
if (!hasLocation) return; | ||
|
||
return ( | ||
<Marker key={id} position={[location.lat, location.lon]}> | ||
<Popup> | ||
<strong>{name}</strong> | ||
</Popup> | ||
</Marker> | ||
); | ||
})} | ||
</> | ||
)} | ||
</Map> | ||
</> | ||
); | ||
}; | ||
|
||
export default PartnersMap; |
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,35 @@ | ||
import { useEffect } from 'react'; | ||
import Leaflet from 'leaflet'; | ||
import * as ReactLeaflet from 'react-leaflet'; | ||
import 'leaflet/dist/leaflet.css'; | ||
|
||
import styles from './Map.module.scss'; | ||
|
||
const { MapContainer } = ReactLeaflet; | ||
|
||
const Map = ({ children, className, width, height, ...rest }) => { | ||
let mapClassName = styles.map; | ||
|
||
if ( className ) { | ||
mapClassName = `${mapClassName} ${className}`; | ||
} | ||
|
||
useEffect(() => { | ||
(async function init() { | ||
delete Leaflet.Icon.Default.prototype._getIconUrl; | ||
Leaflet.Icon.Default.mergeOptions({ | ||
iconRetinaUrl: 'leaflet/images/marker-icon-2x.png', | ||
iconUrl: 'leaflet/images/marker-icon.png', | ||
shadowUrl: 'leaflet/images/marker-shadow.png', | ||
}); | ||
})(); | ||
}, []); | ||
|
||
return ( | ||
<MapContainer className={mapClassName} {...rest}> | ||
{children(ReactLeaflet, Leaflet)} | ||
</MapContainer> | ||
) | ||
} | ||
|
||
export default Map; |
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,22 @@ | ||
import dynamic from 'next/dynamic'; | ||
|
||
const DynamicMap = dynamic(() => import('./DynamicMap'), { | ||
ssr: false | ||
}); | ||
|
||
// Set default sizing to control aspect ratio which will scale responsively | ||
// but also help avoid layout shift | ||
|
||
const DEFAULT_WIDTH = 600; | ||
const DEFAULT_HEIGHT = 600; | ||
|
||
const Map = (props) => { | ||
const { width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT } = props; | ||
return ( | ||
<div style={{ aspectRatio: width / height }}> | ||
<DynamicMap {...props} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default Map; |
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,4 @@ | ||
.map { | ||
width: 100%; | ||
height: 100%; | ||
} |
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 @@ | ||
export { default } from './Map'; |
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
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
Oops, something went wrong.