Skip to content

Commit

Permalink
feat: pass pageContext to each module in related content
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Aug 1, 2020
1 parent 483c55a commit d7e7033
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
41 changes: 23 additions & 18 deletions src/components/PageLayout/RelatedContent.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import React from 'react';
import PropTypes from 'prop-types';
import { css } from '@emotion/core';
import usePageContext from '../../hooks/usePageContext';

const RelatedContent = ({ page, modules }) => (
<aside
data-swiftype-index={false}
css={css`
grid-area: related-content;
position: sticky;
top: calc(var(--global-header-height) + 2rem);
align-self: start;
padding: 1rem;
border: 1px solid var(--divider-color);
border-radius: 0.25rem;
`}
>
{modules.map((Module, idx) => (
<Module key={idx} page={page} />
))}
</aside>
);
const RelatedContent = ({ page, modules }) => {
const pageContext = usePageContext();

return (
<aside
data-swiftype-index={false}
css={css`
grid-area: related-content;
position: sticky;
top: calc(var(--global-header-height) + 2rem);
align-self: start;
padding: 1rem;
border: 1px solid var(--divider-color);
border-radius: 0.25rem;
`}
>
{modules.map((Module, idx) => (
<Module key={idx} page={page} pageContext={pageContext} />
))}
</aside>
);
};

RelatedContent.propTypes = {
modules: PropTypes.arrayOf(PropTypes.elementType).isRequired,
Expand Down
12 changes: 9 additions & 3 deletions src/components/RelatedContentModules/Contribute.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import PropTypes from 'prop-types';
import { css } from '@emotion/core';
import { Button, ExternalLink, Icon } from '@newrelic/gatsby-theme-newrelic';
import { graphql, useStaticQuery } from 'gatsby';
import Section from './Section';
import Title from './Title';
import usePageContext from '../../hooks/usePageContext';

const Contribute = () => {
const Contribute = ({ pageContext }) => {
const { site } = useStaticQuery(graphql`
query {
site {
Expand All @@ -17,7 +17,7 @@ const Contribute = () => {
}
`);

const { fileRelativePath } = usePageContext();
const { fileRelativePath } = pageContext;

const {
siteMetadata: { repository },
Expand Down Expand Up @@ -61,4 +61,10 @@ const Contribute = () => {
);
};

Contribute.propTypes = {
pageContext: PropTypes.shape({
fileRelativePath: PropTypes.string,
}),
};

export default Contribute;

0 comments on commit d7e7033

Please sign in to comment.