From e1a7899a0365961862634bfa5e1cb3fa9c895930 Mon Sep 17 00:00:00 2001 From: Jacob Bare Date: Mon, 13 Aug 2018 15:22:52 -0500 Subject: [PATCH] Add initial publisher context to story page --- src/gql/queries/pages/story.graphql | 6 +++++- src/pages/story.jsx | 21 ++++++++++++++++----- src/server/routes/story.js | 3 ++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/gql/queries/pages/story.graphql b/src/gql/queries/pages/story.graphql index 2e90bfe..bfbabb6 100644 --- a/src/gql/queries/pages/story.graphql +++ b/src/gql/queries/pages/story.graphql @@ -1,7 +1,11 @@ #import '../../fragments/story/view.graphql' -query StoryPage($input: PublishedStoryInput!) { +query StoryPage($input: PublishedStoryInput!, $publisherId: String) { publishedStory(input: $input) { ...StoryViewFragment + publisher(contextId: $publisherId) { + id + name + } } } diff --git a/src/pages/story.jsx b/src/pages/story.jsx index 01ff180..65f9404 100644 --- a/src/pages/story.jsx +++ b/src/pages/story.jsx @@ -2,6 +2,7 @@ import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { Query } from 'react-apollo'; import Head from 'next/head'; + import Title from '../components/Title'; import TrackPageView from '../components/TrackPageView'; import StoryView from '../components/StoryView'; @@ -10,11 +11,11 @@ import ErrorAlert from '../components/ErrorAlert'; import pageQuery from '../gql/queries/pages/story.graphql'; -const Story = ({ id, preview }) => { +const Story = ({ id, preview, publisherId }) => { const input = { id, preview }; return ( - + {({ loading, error, data }) => { if (loading) { return ; @@ -23,13 +24,20 @@ const Story = ({ id, preview }) => { return ; } const { publishedStory } = data; - const { title, teaser, url } = publishedStory; + const { + title, + teaser, + url, + publisher, + } = publishedStory; return ( <Head> <meta name="description" content={teaser} /> + {/* @todo Eventually use the publisher context. */} + <meta name="native-x:publisher" content={publisher.name} /> <link rel="canonical" href={url} /> </Head> <StoryView {...publishedStory} /> @@ -43,19 +51,22 @@ const Story = ({ id, preview }) => { Story.getInitialProps = async ({ req, query }) => { let preview = false; + if (req) { preview = Boolean(req.query); } - const { id } = query; - return { id, preview }; + const { id, publisherId } = query; + return { id, preview, publisherId }; }; Story.defaultProps = { preview: false, + publisherId: null, }; Story.propTypes = { id: PropTypes.string.isRequired, + publisherId: PropTypes.string, preview: PropTypes.bool, }; diff --git a/src/server/routes/story.js b/src/server/routes/story.js index 870f326..05e4438 100644 --- a/src/server/routes/story.js +++ b/src/server/routes/story.js @@ -11,7 +11,8 @@ module.exports = (client) => { client.render(req, res, '_error'); } else { const actualPage = '/story'; - const props = { id }; + const publisherId = req.query.pubid || null; + const props = { id, publisherId }; client.render(req, res, actualPage, props); } });