Skip to content

Commit

Permalink
Add initial publisher context to story page
Browse files Browse the repository at this point in the history
  • Loading branch information
zarathustra323 committed Aug 13, 2018
1 parent e6a2c3b commit e1a7899
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/gql/queries/pages/story.graphql
Original file line number Diff line number Diff line change
@@ -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
}
}
}
21 changes: 16 additions & 5 deletions src/pages/story.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 (
<Fragment>
<Query query={pageQuery} variables={{ input }}>
<Query query={pageQuery} variables={{ input, publisherId }}>
{({ loading, error, data }) => {
if (loading) {
return <LoadingBar />;
Expand All @@ -23,13 +24,20 @@ const Story = ({ id, preview }) => {
return <ErrorAlert message={error.message} />;
}
const { publishedStory } = data;
const { title, teaser, url } = publishedStory;
const {
title,
teaser,
url,
publisher,
} = publishedStory;
return (
<Fragment>
<TrackPageView params={{ story_id: id, page_title: title }} />
<Title value={title} />
<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} />
Expand All @@ -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,
};

Expand Down
3 changes: 2 additions & 1 deletion src/server/routes/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down

0 comments on commit e1a7899

Please sign in to comment.