File size: 1,972 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
import { defer } from 'lodash';
import AsyncLoad from 'calypso/components/async-load';
import { trackPageLoad } from 'calypso/reader/controller-helper';
import { isUserLoggedIn } from 'calypso/state/current-user/selectors';
const analyticsPageTitle = 'Reader';
const scrollTopIfNoHash = () =>
defer( () => {
if ( typeof window !== 'undefined' && ! window.location.hash ) {
window.scrollTo( 0, 0 );
}
} );
export function blogPost( context, next ) {
const state = context.store.getState();
const blogId = context.params.blog;
const postId = context.params.post;
const basePath = '/reader/blogs/:blog_id/posts/:post_id';
const fullPageTitle = analyticsPageTitle + ' > Blog Post > ' + blogId + ' > ' + postId;
let referral;
if ( context.query.ref_blog && context.query.ref_post ) {
referral = { blogId: context.query.ref_blog, postId: context.query.ref_post };
}
trackPageLoad( basePath, fullPageTitle, 'full_post' );
context.primary = (
<AsyncLoad
require="calypso/blocks/reader-full-post"
blogId={ blogId }
postId={ postId }
referral={ referral }
/>
);
if ( isUserLoggedIn( state ) ) {
context.secondary = (
<AsyncLoad require="calypso/reader/sidebar" path={ context.path } placeholder={ null } />
);
}
scrollTopIfNoHash();
next();
}
export function feedPost( context, next ) {
const state = context.store.getState();
const feedId = context.params.feed;
const postId = context.params.post;
const basePath = '/reader/feeds/:feed_id/posts/:feed_item_id';
const fullPageTitle = analyticsPageTitle + ' > Feed Post > ' + feedId + ' > ' + postId;
trackPageLoad( basePath, fullPageTitle, 'full_post' );
context.primary = (
<AsyncLoad require="calypso/blocks/reader-full-post" feedId={ feedId } postId={ postId } />
);
if ( isUserLoggedIn( state ) ) {
context.secondary = (
<AsyncLoad require="calypso/reader/sidebar" path={ context.path } placeholder={ null } />
);
}
scrollTopIfNoHash();
next();
}
|