diff --git a/client/reader/discover/controller.js b/client/reader/discover/controller.js deleted file mode 100644 index 56c05602f7ed7..0000000000000 --- a/client/reader/discover/controller.js +++ /dev/null @@ -1,80 +0,0 @@ -import { translate } from 'i18n-calypso'; -import AsyncLoad from 'calypso/components/async-load'; -import DocumentHead from 'calypso/components/data/document-head'; -import { sectionify } from 'calypso/lib/route'; -import { - trackPageLoad, - trackUpdatesLoaded, - trackScrollPage, -} from 'calypso/reader/controller-helper'; -import { recordTrack } from 'calypso/reader/stats'; -import { isUserLoggedIn } from 'calypso/state/current-user/selectors'; -import getCurrentQueryArguments from 'calypso/state/selectors/get-current-query-arguments'; -import getCurrentRoute from 'calypso/state/selectors/get-current-route'; -import renderHeaderSection from '../lib/header-section'; -import { getSelectedTabTitle, DEFAULT_TAB } from './helper'; - -const ANALYTICS_PAGE_TITLE = 'Reader'; - -const exported = { - discover( context, next ) { - const basePath = sectionify( context.path ); - const fullAnalyticsPageTitle = ANALYTICS_PAGE_TITLE + ' > Discover'; - const streamKey = 'discover:recommended'; - const mcKey = 'discover'; - const state = context.store.getState(); - - const currentRoute = getCurrentRoute( state ); - const currentQueryArgs = new URLSearchParams( getCurrentQueryArguments( state ) ).toString(); - - trackPageLoad( basePath, fullAnalyticsPageTitle, mcKey ); - recordTrack( - 'calypso_reader_discover_viewed', - {}, - { pathnameOverride: `${ currentRoute }?${ currentQueryArgs }` } - ); - - if ( ! isUserLoggedIn( state ) ) { - context.renderHeaderSection = renderHeaderSection; - } - const selectedTab = context.query.selectedTab || DEFAULT_TAB; - const tabTitle = getSelectedTabTitle( selectedTab ) || ''; - /* eslint-disable wpcalypso/jsx-classname-namespace */ - context.primary = ( - <> - - - - ); - /* eslint-enable wpcalypso/jsx-classname-namespace */ - next(); - }, -}; - -export default exported; - -export const { discover } = exported; diff --git a/client/reader/discover/discover-document-head.js b/client/reader/discover/discover-document-head.js new file mode 100644 index 0000000000000..3d3f0a0e9cd9c --- /dev/null +++ b/client/reader/discover/discover-document-head.js @@ -0,0 +1,22 @@ +import { useTranslate } from 'i18n-calypso'; +import DocumentHead from 'calypso/components/data/document-head'; + +export const DiscoverDocumentHead = ( { tabTitle } ) => { + const translate = useTranslate(); + + const title = translate( 'Browse %s blogs & read articles ‹ Reader', { + args: [ tabTitle ], + comment: '%s is the type of blog being explored e.g. food, art, technology etc.', + } ); + + const meta = [ + { + name: 'description', + content: translate( + 'Explore millions of blogs on WordPress.com. Discover posts, from food and art to travel and photography, and find popular sites that inspire and inform.' + ), + }, + ]; + + return ; +}; diff --git a/client/reader/discover/discover-stream.js b/client/reader/discover/discover-stream.js index 2e73d91289419..aadc40c33cf45 100644 --- a/client/reader/discover/discover-stream.js +++ b/client/reader/discover/discover-stream.js @@ -23,6 +23,35 @@ import { FIRST_POSTS_TAB, } from './helper'; +const DISCOVER_HEADER_NAVIGATION_ITEMS = []; + +export const DiscoverHeader = ( props ) => { + const translate = useTranslate(); + + const { selectedTab } = props; + const tabTitle = getSelectedTabTitle( selectedTab ); + let subHeaderText = translate( 'Explore %s blogs that inspire, educate, and entertain.', { + args: [ tabTitle ], + comment: '%s is the type of blog being explored e.g. food, art, technology etc.', + } ); + if ( selectedTab === FIRST_POSTS_TAB ) { + subHeaderText = translate( + 'Fresh voices, fresh views. Explore first-time posts from new bloggers.' + ); + } + + return ( + WIDE_DISPLAY_CUTOFF, + } ) } + /> + ); +}; + const DiscoverStream = ( props ) => { const locale = useLocale(); const translate = useTranslate(); @@ -67,27 +96,6 @@ const DiscoverStream = ( props ) => { isLoggedIn ); const streamKey = buildDiscoverStreamKey( selectedTab, recommendedStreamTags ); - const tabTitle = getSelectedTabTitle( selectedTab ); - let subHeaderText = translate( 'Explore %s blogs that inspire, educate, and entertain.', { - args: [ tabTitle ], - comment: '%s is the type of blog being explored e.g. food, art, technology etc.', - } ); - if ( selectedTab === FIRST_POSTS_TAB ) { - subHeaderText = translate( - 'Fresh voices, fresh views. Explore first-time posts from new bloggers.' - ); - } - - const DiscoverHeader = () => ( - WIDE_DISPLAY_CUTOFF, - } ) } - /> - ); const streamSidebar = () => { if ( selectedTab === FIRST_POSTS_TAB && recommendedSites?.length ) { @@ -127,16 +135,14 @@ const DiscoverStream = ( props ) => { }; return ( - <> - - { DiscoverHeader() } - - - + + + + ); }; diff --git a/client/reader/discover/index.js b/client/reader/discover/index.js deleted file mode 100644 index 885fb48cbd131..0000000000000 --- a/client/reader/discover/index.js +++ /dev/null @@ -1,28 +0,0 @@ -import page from '@automattic/calypso-router'; -import { getLanguageRouteParam, getAnyLanguageRouteParam } from '@automattic/i18n-utils'; -import { - makeLayout, - redirectInvalidLanguage, - redirectWithoutLocaleParamInFrontIfLoggedIn, - render as clientRender, -} from 'calypso/controller'; -import { setLocaleMiddleware } from 'calypso/controller/shared'; -import { sidebar, updateLastRoute } from 'calypso/reader/controller'; -import { discover } from './controller'; - -export default function () { - const langParam = getLanguageRouteParam(); - const anyLangParam = getAnyLanguageRouteParam(); - page( `/${ anyLangParam }/discover`, redirectInvalidLanguage ); - - page( - [ '/discover', `/${ langParam }/discover` ], - redirectWithoutLocaleParamInFrontIfLoggedIn, - setLocaleMiddleware(), - updateLastRoute, - sidebar, - discover, - makeLayout, - clientRender - ); -} diff --git a/client/reader/discover/index.node.js b/client/reader/discover/index.node.js new file mode 100644 index 0000000000000..db9e25be894bf --- /dev/null +++ b/client/reader/discover/index.node.js @@ -0,0 +1,28 @@ +import { getAnyLanguageRouteParam } from '@automattic/i18n-utils'; +import { makeLayout, ssrSetupLocale } from 'calypso/controller'; +import PostPlaceholder from 'calypso/reader/stream/post-placeholder'; +import renderHeaderSection from '../lib/header-section'; +import { DiscoverDocumentHead } from './discover-document-head'; +import { DiscoverHeader } from './discover-stream'; +import { getSelectedTabTitle, DEFAULT_TAB } from './helper'; + +const discoverSsr = ( context, next ) => { + context.renderHeaderSection = renderHeaderSection; + + const selectedTab = context.query.selectedTab || DEFAULT_TAB; + const tabTitle = getSelectedTabTitle( selectedTab ); + context.primary = ( + <> + + + + + ); + next(); +}; + +export default function ( router ) { + const anyLangParam = getAnyLanguageRouteParam(); + + router( [ '/discover', `/${ anyLangParam }/discover` ], ssrSetupLocale, discoverSsr, makeLayout ); +} diff --git a/client/reader/discover/index.web.js b/client/reader/discover/index.web.js new file mode 100644 index 0000000000000..c81bc485876e9 --- /dev/null +++ b/client/reader/discover/index.web.js @@ -0,0 +1,91 @@ +import { getAnyLanguageRouteParam } from '@automattic/i18n-utils'; +import AsyncLoad from 'calypso/components/async-load'; +import { + makeLayout, + redirectInvalidLanguage, + redirectWithoutLocaleParamInFrontIfLoggedIn, + render as clientRender, +} from 'calypso/controller'; +import { setLocaleMiddleware } from 'calypso/controller/shared'; +import { sectionify } from 'calypso/lib/route'; +import { sidebar, updateLastRoute } from 'calypso/reader/controller'; +import { + trackPageLoad, + trackUpdatesLoaded, + trackScrollPage, +} from 'calypso/reader/controller-helper'; +import { recordTrack } from 'calypso/reader/stats'; +import { isUserLoggedIn } from 'calypso/state/current-user/selectors'; +import getCurrentQueryArguments from 'calypso/state/selectors/get-current-query-arguments'; +import getCurrentRoute from 'calypso/state/selectors/get-current-route'; +import renderHeaderSection from '../lib/header-section'; +import { DiscoverDocumentHead } from './discover-document-head'; +import { getSelectedTabTitle, DEFAULT_TAB } from './helper'; + +const ANALYTICS_PAGE_TITLE = 'Reader'; + +const discover = ( context, next ) => { + const basePath = sectionify( context.path ); + const fullAnalyticsPageTitle = ANALYTICS_PAGE_TITLE + ' > Discover'; + const streamKey = 'discover:recommended'; + const mcKey = 'discover'; + const state = context.store.getState(); + + const currentRoute = getCurrentRoute( state ); + const currentQueryArgs = new URLSearchParams( getCurrentQueryArguments( state ) ).toString(); + + trackPageLoad( basePath, fullAnalyticsPageTitle, mcKey ); + recordTrack( + 'calypso_reader_discover_viewed', + {}, + { pathnameOverride: `${ currentRoute }?${ currentQueryArgs }` } + ); + + if ( ! isUserLoggedIn( state ) ) { + context.renderHeaderSection = renderHeaderSection; + } + const selectedTab = context.query.selectedTab || DEFAULT_TAB; + const tabTitle = getSelectedTabTitle( selectedTab ); + context.primary = ( + <> + + + + ); + next(); +}; + +export default function ( router ) { + const anyLangParam = getAnyLanguageRouteParam(); + + router( + [ '/discover', `/${ anyLangParam }/discover` ], + redirectInvalidLanguage, + redirectWithoutLocaleParamInFrontIfLoggedIn, + setLocaleMiddleware(), + updateLastRoute, + sidebar, + discover, + makeLayout, + clientRender + ); +} diff --git a/client/reader/discover/package.json b/client/reader/discover/package.json new file mode 100644 index 0000000000000..a53931f3a6407 --- /dev/null +++ b/client/reader/discover/package.json @@ -0,0 +1,4 @@ +{ + "main": "index.node.js", + "browser": "index.web.js" +} diff --git a/client/reader/lib/header-section/index.tsx b/client/reader/lib/header-section/index.tsx index 4c0d4134fd95f..159ee7bb319b6 100644 --- a/client/reader/lib/header-section/index.tsx +++ b/client/reader/lib/header-section/index.tsx @@ -1,16 +1,22 @@ -import { translate } from 'i18n-calypso'; +import { useTranslate } from 'i18n-calypso'; import React from 'react'; -const renderHeaderSection = () => ( -
-

- { - // translators: The title of the reader tag page - translate( 'WordPress Reader' ) - } -

-

{ translate( 'Enjoy millions of blogs at your fingertips.' ) }

-
-); +const ReaderHeader = () => { + const translate = useTranslate(); + + return ( +
+

+ { + // translators: The title of the reader tag page + translate( 'WordPress Reader' ) + } +

+

{ translate( 'Enjoy millions of blogs at your fingertips.' ) }

+
+ ); +}; + +const renderHeaderSection = () => ; export default renderHeaderSection; diff --git a/client/sections.js b/client/sections.js index 8ae3b1bf811db..272928257c57e 100644 --- a/client/sections.js +++ b/client/sections.js @@ -416,6 +416,7 @@ const sections = [ group: 'reader', enableLoggedOut: true, trackLoadPerformance: true, + isomorphic: true, }, { name: 'reader',