2016-01-19 15:00:50 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { History } from 'react-router';
|
|
|
|
|
|
|
|
import GlobalNotification from './global_notification';
|
|
|
|
|
|
|
|
import AppConstants from '../constants/application_constants';
|
|
|
|
|
|
|
|
|
|
|
|
export default function AppBase(App) {
|
|
|
|
return React.createClass({
|
|
|
|
displayName: 'AppBase',
|
|
|
|
|
|
|
|
propTypes: {
|
2016-02-01 14:48:44 +01:00
|
|
|
children: React.PropTypes.element.isRequired,
|
2016-01-19 15:00:50 +01:00
|
|
|
history: React.PropTypes.object.isRequired,
|
|
|
|
location: React.PropTypes.object.isRequired,
|
2016-02-01 14:48:44 +01:00
|
|
|
routes: React.PropTypes.arrayOf(React.PropTypes.object).isRequired
|
2016-01-19 15:00:50 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
mixins: [History],
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.history.locationQueue.push(this.props.location);
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
const { locationQueue } = this.history;
|
|
|
|
locationQueue.unshift(nextProps.location);
|
|
|
|
|
|
|
|
// Limit the number of locations to keep in memory to avoid too much memory usage
|
|
|
|
if (locationQueue.length > AppConstants.locationThreshold) {
|
|
|
|
locationQueue.length = AppConstants.locationThreshold;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
2016-02-03 12:28:49 +01:00
|
|
|
const { routes } = this.props;
|
2016-02-01 14:48:44 +01:00
|
|
|
|
2016-02-03 12:28:49 +01:00
|
|
|
// The second element of the routes prop given to us by react-router is always the
|
|
|
|
// active second-level component object (ie. after App).
|
|
|
|
const activeRoute = routes[1];
|
2016-02-01 14:48:44 +01:00
|
|
|
|
2016-01-19 15:00:50 +01:00
|
|
|
return (
|
|
|
|
<div>
|
2016-02-01 14:48:44 +01:00
|
|
|
<App
|
|
|
|
{...this.props}
|
|
|
|
activeRoute={activeRoute} />
|
2016-01-19 15:00:50 +01:00
|
|
|
<GlobalNotification />
|
|
|
|
<div id="modal" className="container" />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|