set and render page title
note this requires changes to thundercats to work see: thundercatsjs/thundercats-react/issues/3
This commit is contained in:
@ -20,9 +20,26 @@ export default contain(
|
|||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
children: PropTypes.node,
|
children: PropTypes.node,
|
||||||
username: PropTypes.string,
|
|
||||||
points: PropTypes.number,
|
points: PropTypes.number,
|
||||||
picture: PropTypes.string
|
picture: PropTypes.string,
|
||||||
|
title: PropTypes.string,
|
||||||
|
username: PropTypes.string
|
||||||
|
},
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
const title = this.props.title;
|
||||||
|
this.setTitle(title);
|
||||||
|
},
|
||||||
|
|
||||||
|
componentWillReceiveProps(nextProps) {
|
||||||
|
if (nextProps.title !== this.props.title) {
|
||||||
|
this.setTitle(nextProps.title);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
setTitle(title) {
|
||||||
|
const doc = typeof document !== 'undefined' ? document : {};
|
||||||
|
doc.title = title;
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -4,6 +4,10 @@ import debugFactory from 'debug';
|
|||||||
const debug = debugFactory('freecc:app:actions');
|
const debug = debugFactory('freecc:app:actions');
|
||||||
|
|
||||||
export default Actions({
|
export default Actions({
|
||||||
|
setTitle(title = 'Learn To Code') {
|
||||||
|
return { title: title + '| Free Code Camp' };
|
||||||
|
},
|
||||||
|
|
||||||
setUser({ username, picture, progressTimestamps = [] }) {
|
setUser({ username, picture, progressTimestamps = [] }) {
|
||||||
return {
|
return {
|
||||||
username,
|
username,
|
||||||
@ -11,6 +15,7 @@ export default Actions({
|
|||||||
points: progressTimestamps.length
|
points: progressTimestamps.length
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
getUser: null
|
getUser: null
|
||||||
})
|
})
|
||||||
.refs({ displayName: 'AppActions' })
|
.refs({ displayName: 'AppActions' })
|
||||||
@ -28,4 +33,5 @@ export default Actions({
|
|||||||
return appActions.setUser(user);
|
return appActions.setUser(user);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
return appActions;
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { Store } from 'thundercats';
|
import { Store } from 'thundercats';
|
||||||
|
|
||||||
const { createRegistrar, setter } = Store;
|
const { createRegistrar, setter, fromMany } = Store;
|
||||||
const initValue = {
|
const initValue = {
|
||||||
|
title: 'Learn To Code | Free Code Camp',
|
||||||
username: null,
|
username: null,
|
||||||
picture: null,
|
picture: null,
|
||||||
points: 0
|
points: 0
|
||||||
@ -10,9 +11,10 @@ const initValue = {
|
|||||||
export default Store(initValue)
|
export default Store(initValue)
|
||||||
.refs({ displayName: 'AppStore' })
|
.refs({ displayName: 'AppStore' })
|
||||||
.init(({ instance: appStore, args: [cat] }) => {
|
.init(({ instance: appStore, args: [cat] }) => {
|
||||||
const { setUser } = cat.getActions('appActions');
|
const { setUser, setTitle } = cat.getActions('appActions');
|
||||||
const register = createRegistrar(appStore);
|
const register = createRegistrar(appStore);
|
||||||
register(setter(setUser));
|
|
||||||
|
register(setter(fromMany(setUser, setTitle)));
|
||||||
|
|
||||||
return appStore;
|
return appStore;
|
||||||
});
|
});
|
||||||
|
@ -10,6 +10,7 @@ import HikesMap from './Map.jsx';
|
|||||||
export default contain(
|
export default contain(
|
||||||
{
|
{
|
||||||
store: 'hikesStore',
|
store: 'hikesStore',
|
||||||
|
actions: ['appActions'],
|
||||||
fetchAction: 'hikesActions.fetchHikes',
|
fetchAction: 'hikesActions.fetchHikes',
|
||||||
getPayload: ({ hikes, params }) => ({
|
getPayload: ({ hikes, params }) => ({
|
||||||
isPrimed: (hikes && !!hikes.length),
|
isPrimed: (hikes && !!hikes.length),
|
||||||
@ -23,11 +24,17 @@ export default contain(
|
|||||||
displayName: 'Hikes',
|
displayName: 'Hikes',
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
|
appActions: PropTypes.object,
|
||||||
children: PropTypes.element,
|
children: PropTypes.element,
|
||||||
currentHike: PropTypes.object,
|
currentHike: PropTypes.object,
|
||||||
hikes: PropTypes.array
|
hikes: PropTypes.array
|
||||||
},
|
},
|
||||||
|
|
||||||
|
componentWillMount() {
|
||||||
|
const { appActions } = this.props;
|
||||||
|
appActions.setTitle('Hikes');
|
||||||
|
},
|
||||||
|
|
||||||
renderMap(hikes) {
|
renderMap(hikes) {
|
||||||
return (
|
return (
|
||||||
<HikesMap hikes={ hikes }/>
|
<HikesMap hikes={ hikes }/>
|
||||||
|
@ -51,9 +51,13 @@ export default function reactSubRouter(app) {
|
|||||||
// makes sure we only get one onNext and closes subscription
|
// makes sure we only get one onNext and closes subscription
|
||||||
.flatMap(function({ data, markup }) {
|
.flatMap(function({ data, markup }) {
|
||||||
debug('react rendered');
|
debug('react rendered');
|
||||||
|
const { title } = data.AppStore;
|
||||||
res.expose(data, 'data');
|
res.expose(data, 'data');
|
||||||
// now render jade file with markup injected from react
|
// now render jade file with markup injected from react
|
||||||
return res.render$('layout-react', { markup: markup });
|
return res.render$(
|
||||||
|
'layout-react',
|
||||||
|
{ markup, title }
|
||||||
|
);
|
||||||
})
|
})
|
||||||
.subscribe(
|
.subscribe(
|
||||||
function(markup) {
|
function(markup) {
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
doctype html
|
doctype html
|
||||||
html(ng-app='profileValidation', lang='en')
|
html(ng-app='profileValidation', lang='en')
|
||||||
head
|
head
|
||||||
|
if title
|
||||||
|
title= title
|
||||||
|
else
|
||||||
|
title redirecting to | Free Code Camp
|
||||||
include partials/small-head
|
include partials/small-head
|
||||||
body.top-and-bottom-margins(style='overflow: hidden')
|
body.top-and-bottom-margins(style='overflow: hidden')
|
||||||
.container
|
.container
|
||||||
|
@ -7,7 +7,6 @@ link(rel='stylesheet', href='/css/lib/Vimeo.css')
|
|||||||
// End **REQUIRED** includes
|
// End **REQUIRED** includes
|
||||||
|
|
||||||
include meta
|
include meta
|
||||||
title redirecting to | Free Code Camp
|
|
||||||
meta(charset='utf-8')
|
meta(charset='utf-8')
|
||||||
meta(http-equiv='X-UA-Compatible', content='IE=edge')
|
meta(http-equiv='X-UA-Compatible', content='IE=edge')
|
||||||
meta(name='viewport', content='width=device-width, initial-scale=1.0')
|
meta(name='viewport', content='width=device-width, initial-scale=1.0')
|
||||||
|
Reference in New Issue
Block a user