Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Themes: SSR testing branch #846

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/boot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ function boot() {
} else {
if ( config.isEnabled( 'oauth' ) ) {
LoggedOutLayout = require( 'layout/logged-out-oauth' );
} else if ( startsWith( window.location.pathname, '/design' ) ) {
LoggedOutLayout = require( 'layout/themes-logged-out' );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since themes-logged-out is a 'pure' render tree, we can't render into sections directly in our controllers. How do we update our routing & controllers to take this into account, and how do we make this generically usable?

} else {
LoggedOutLayout = require( 'layout/logged-out' );
}
Expand Down
1 change: 1 addition & 0 deletions config/wpcalypso.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"manage/themes": true,
"manage/themes-jetpack": true,
"premium-themes": true,
"manage/themes/logged-out": true,
"press-this": true,
"manage/sharing": true,
"manage/plans": true,
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require( 'lib/local-storage' )( global );

/**
* External dependencies.
*/
Expand Down
2 changes: 1 addition & 1 deletion server/i18nlint/i18nlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var fs = require( 'fs' ),
babel = require( 'babel-core' ),
preProcessXGettextJSMatch = require( '../i18n/preprocess-xgettextjs-match.js' ),
SourceMapConsumer = require( 'source-map' ).SourceMapConsumer,
tokenize = require( '../../client/lib/interpolate-components/tokenize.js' ),
tokenize = require( '../../shared/lib/interpolate-components/tokenize.js' ),
contains = require( 'lodash' ).contains,
flow = require( 'lodash' ).flow;

Expand Down
3 changes: 3 additions & 0 deletions server/lib/viewport/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
isMobile: () => false
};
7 changes: 5 additions & 2 deletions server/pages/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ html(lang=lang, dir=isRTL ? 'rtl' : 'ltr', class=isFluidWidth ? 'is-fluid-width'
link(rel='stylesheet', href=urls['style.css'])

body(class=isRTL ? 'rtl' : '')
#wpcom.wpcom-site
.wpcom-site__logo.noticon.noticon-wordpress
if layout
#wpcom.wpcom-site!= layout
else
#wpcom.wpcom-site
.wpcom-site__logo.noticon.noticon-wordpress
if badge
div.environment-badge
a(class='bug-report', href=feedbackURL, title='Report an issue', target='_blank')
Expand Down
25 changes: 21 additions & 4 deletions server/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ var express = require( 'express' ),
qs = require( 'qs' ),
cookieParser = require( 'cookie-parser' ),
i18nUtils = require( 'lib/i18n-utils' ),
debug = require( 'debug' )( 'calypso:pages' );
assign = require( 'lodash/object/assign' ),
debug = require( 'debug' )( 'calypso:pages' ),
React = require( 'react' ),
ReactInjection = require( 'react/lib/ReactInjection' );

var config = require( 'config' ),
sanitize = require( 'sanitize' ),
utils = require( 'bundler/utils' ),
sections = require( '../../client/sections' );
sections = require( '../../client/sections' ),
i18n = require( 'lib/mixins/i18n' );

var HASH_LENGTH = 10,
URL_BASE_PATH = '/calypso',
Expand Down Expand Up @@ -344,12 +348,25 @@ module.exports = function() {
}
} );

app.get( '/design', function( req, res ) {
app.get( '/design/type?/:tier?', function( req, res ) {
if ( req.cookies.wordpress_logged_in || ! config.isEnabled( 'manage/themes/logged-out' ) ) {
// the user is probably logged in
renderLoggedInRoute( req, res );
} else {
renderLoggedOutRoute( req, res );
ReactInjection.Class.injectMixin( i18n.mixin );
i18n.initialize();

const themesLoggedOutLayoutComponent = require( 'layout/themes-logged-out' ),
themesLoggedOutLayout = React.createFactory( themesLoggedOutLayoutComponent ),
context = getDefaultContext( req ),
props = {
section: 'themes',
tier: req.params.tier || 'all',
};

context.layout = React.renderToString( themesLoggedOutLayout( props ) );

res.render( 'index.jade', context );
}
} );

Expand Down
9 changes: 9 additions & 0 deletions shared/components/empty/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const React = require( 'react' );

const EmptyComponent = React.createClass( {
render: function() {
return null;
}
} );

module.exports = EmptyComponent;
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,26 @@ module.exports = React.createClass( {
smartSetState: smartSetState,

componentWillMount: function() {
var url = page.current,
newState, scrollPosition;
if ( typeof( window ) !== 'undefined' ) {
var url = page.current,
newState, scrollPosition;

if ( detectHistoryNavigation.loadedViaHistory() ) {
newState = InfiniteListPositionsStore.get( url );
scrollPosition = InfiniteListScrollStore.get( url );
}
if ( detectHistoryNavigation.loadedViaHistory() ) {
newState = InfiniteListPositionsStore.get( url );
scrollPosition = InfiniteListScrollStore.get( url );
}

if ( newState && scrollPosition ) {
debug( 'overriding scrollTop:', scrollPosition );
newState.scrollTop = scrollPosition;
}
if ( newState && scrollPosition ) {
debug( 'overriding scrollTop:', scrollPosition );
newState.scrollTop = scrollPosition;
}

this.scrollHelper = new ScrollHelper( this.boundsForRef );
this.scrollHelper.props = this.props;
if ( this._contextLoaded() ) {
this._scrollContainer = this.props.context || window;
this.scrollHelper.updateContextHeight( this.getCurrentContextHeight() );
}
this.scrollHelper = new ScrollHelper( this.boundsForRef );
this.scrollHelper.props = this.props;
if ( this._contextLoaded() ) {
this._scrollContainer = this.props.context || window;
this.scrollHelper.updateContextHeight( this.getCurrentContextHeight() );
}

this.isScrolling = false;

Expand All @@ -87,9 +88,10 @@ module.exports = React.createClass( {
bottomPlaceholderHeight: 0,
scrollTop: 0
};
debug( 'infinite list mounting', newState );
this.setState( newState );
}
}
debug( 'infinite list mounting', newState );
this.setState( newState );
},

componentDidMount: function() {
Expand Down Expand Up @@ -316,21 +318,22 @@ module.exports = React.createClass( {
},

render: function() {
var lastRenderedIndex = this.state.lastRenderedIndex,
var lastRenderedIndex = this.state ? this.state.lastRenderedIndex : this.props.items.length - 1,
firstRenderedIndex = this.state ? this.state.firstRenderedIndex : 0,
itemsToRender = [],
propsToTransfer = omit( this.props, Object.keys( this.constructor.propTypes ) ),
spacerClassName = 'infinite-list__spacer',
i;

if ( lastRenderedIndex === -1 || lastRenderedIndex > this.props.items.length - 1 ) {
if ( this.state && lastRenderedIndex === -1 || lastRenderedIndex > this.props.items.length - 1 ) {
debug( 'resetting lastRenderedIndex, currently at %s, %d items', lastRenderedIndex, this.props.items.length );
lastRenderedIndex = Math.min( this.state.firstRenderedIndex + this.scrollHelper.initialLastRenderedIndex(), this.props.items.length - 1 );
debug( 'reset lastRenderedIndex to %s', lastRenderedIndex );
}

debug( 'rendering %d to %d', this.state.firstRenderedIndex, lastRenderedIndex );
debug( 'rendering %d to %d', firstRenderedIndex, lastRenderedIndex );

for ( i = this.state.firstRenderedIndex; i <= lastRenderedIndex; i++ ) {
for ( i = firstRenderedIndex; i <= lastRenderedIndex; i++ ) {
itemsToRender.push( this.props.renderItem( this.props.items[ i ], i ) );
}

Expand All @@ -342,12 +345,12 @@ module.exports = React.createClass( {
<div {...propsToTransfer}>
<div ref="topPlaceholder"
className={ spacerClassName }
style={ { height: this.state.topPlaceholderHeight } } />
style={ { height: this.state ? this.state.topPlaceholderHeight : 0 } } />
{ itemsToRender }
{ this.props.renderTrailingItems() }
<div ref="bottomPlaceholder"
className={ spacerClassName }
style={ { height: this.state.bottomPlaceholderHeight } } />
style={ { height: this.state ? this.state.bottomPlaceholderHeight : 0 } } />
</div>
);
},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
var React = require( 'react' ),
var React = require( 'react/addons' ),
classNames = require( 'classnames' ),
debounce = require( 'lodash/function/debounce' ),
noop = () => {};
Expand Down Expand Up @@ -60,12 +60,17 @@ module.exports = React.createClass( {
};
},

componentWillMount: function() {
componentDidMount: function() {
this.id = _instance;
_instance++;
this.onSearch = this.props.delaySearch
? debounce( this.props.onSearch, SEARCH_DEBOUNCE_MS )
: this.props.onSearch;
this.onSearch = ( this.props.delaySearch ) ? debounce( this.props.onSearch, SEARCH_DEBOUNCE_MS ) : this.props.onSearch;

if ( this.props.autoFocus ) {
this.focus();
}
},

componentWillReceiveProps: function( nextProps ) {
Expand Down Expand Up @@ -114,12 +119,6 @@ module.exports = React.createClass( {
this.props.onSearchChange( this.state.keyword );
},

componentDidMount: function() {
if ( this.props.autoFocus ) {
this.focus();
}
},

focus: function() {
React.findDOMNode( this.refs.searchInput ).focus();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var SelectDropdown = React.createClass( {
return initialState;
},

componentWillMount: function() {
componentDidMount: function() {
this.id = _instance;
_instance++;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ Spinner = React.createClass( {
* elements, or false otherwise.
*/
isSVGCSSAnimationSupported: function() {
return ! /(MSIE |Trident\/)/.test( global.window.navigator.userAgent );
return false;
return typeof( window ) === undefined || ! /(MSIE |Trident\/)/.test( global.window.navigator.userAgent );
},

getClassName: function() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
63 changes: 63 additions & 0 deletions shared/layout/themes-logged-out.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* External dependencies
*/
import React from 'react';
import partialRight from 'lodash/function/partialRight';

/**
* Internal dependencies
*/
import Masterbar from './masterbar';
//import NoticesList from 'notices/notices-list';
//import notices from 'notices';
//import title from 'lib/screen-title';
import Main from 'components/main';
import themesComponent from 'my-sites/themes/themes-selection';
import getButtonOptions from 'my-sites/themes/theme-options';

const themesFactory = React.createFactory( themesComponent );

const ThemesLoggedOutLayout = React.createClass( {

getDefaultProps() {
return {
section: 'themes',
}
},

themesProps: {
getOptions: partialRight( getButtonOptions, () => {}, () => {} ),
sites: false,
setSelectedTheme: () => {},
togglePreview: () => {},
loggedIn: false,
},

getTier() {
const tier = typeof( window ) !== 'undefined' && window.location.pathname.match( /^\/design\/type\/(free|premium|all)\/?/ );
if ( tier ) {
return { tier: tier[1] };
}
},

render() {
const sectionClass = 'wp' + ( this.props.section ? ' is-section-' + this.props.section : '' );
return (
<div className={ sectionClass }>
<Masterbar />
<div id="content" className="wp-content">
<div id="primary" className="wp-primary wp-section">
<Main className="themes">
{ themesFactory( Object.assign( {}, this.themesProps, this.getTier(), this.props ) ) }
</Main>
</div>
</div>
<div id="tertiary" className="wp-overlay fade-background">
{ this.props.tertiary }
</div>
</div>
);
}
} );

export default ThemesLoggedOutLayout;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion shared/my-sites/themes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const routing = {
middlewares: [
{ value: controller.navigation, enableLoggedOut: false },
{ value: controller.siteSelection, enableLoggedOut: false },
{ value: themesController.themes, enableLoggedOut: true },
{ value: themesController.themes, enableLoggedOut: false },
{ value: () => {}, enableLoggedOut: true }
]
};

Expand Down
Loading