Skip to content

Commit

Permalink
Query new slug field, use for links
Browse files Browse the repository at this point in the history
  • Loading branch information
ceolson01 committed Mar 31, 2019
1 parent 208ff57 commit b8e6cbe
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
62 changes: 61 additions & 1 deletion src/modules/pages/components/Tutorials/Tutorials.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,69 @@
/* @flow */
import type { IntlShape } from 'react-intl';

import React from 'react';
import { defineMessages } from 'react-intl';

import { graphql, useStaticQuery } from 'gatsby';

import type { TutorialNode } from '~types';

import Heading from '~core/Heading';
import Link from '~core/Link';
import Search from '~core/Search';

const MSG = defineMessages({
pageTitle: {
id: 'pages.Tutorials.pageTitle',
defaultMessage: 'Explore Tutorials',
},
pageSubtitle: {
id: 'pages.Tutorials.pageSubtitle',
defaultMessage: 'Tutorials',
},
});

type QueryData = {
allTutorials: {
edges: Array<{
node: TutorialNode,
}>,
},
};

type Props = {|
/** Injected via `injectIntl` */
intl: IntlShape,
|};

const displayName = 'pages.Tutorials';

const Tutorials = () => <div />;
const Tutorials = () => {
const tutorialsQueryData: QueryData = useStaticQuery(graphql`
{
...allTutorialsFragment
}
`);
return (
<>
<Heading text={MSG.pageTitle} />
<Search inputId="pagesTutorialsSearch" />
<Heading text={MSG.pageSubtitle} />
{tutorialsQueryData.allTutorials.edges.map(
({
node: {
fields: { slug },
name,
},
}) => (
<Link href={slug}>
<Heading text={name} />
</Link>
),
)}
</>
);
};

Tutorials.displayName = displayName;

Expand Down
4 changes: 3 additions & 1 deletion src/queries/tutorial.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export const allTutorialsFragment = graphql`
edges {
node {
name
slug
fields {
slug
}
}
}
}
Expand Down

0 comments on commit b8e6cbe

Please sign in to comment.