2016-07-21 22:24:50 +08:00
|
|
|
import React, { Component, PropTypes, cloneElement } from 'react';
|
2016-04-29 03:02:51 +08:00
|
|
|
import { createContainer } from 'meteor/react-meteor-data';
|
2016-05-20 21:37:19 +08:00
|
|
|
import App from './component';
|
2016-07-29 03:48:26 +08:00
|
|
|
import { subscribeForData, pollExists, didUserWasKicked, redirectToLogoutUrl } from './service';
|
2016-05-20 21:44:27 +08:00
|
|
|
import NavBarContainer from '../nav-bar/container';
|
2016-05-20 21:37:19 +08:00
|
|
|
import ActionsBarContainer from '../actions-bar/container';
|
2016-05-20 21:44:27 +08:00
|
|
|
import MediaContainer from '../media/container';
|
2016-05-20 21:37:19 +08:00
|
|
|
import SettingsModal from '../modals/settings/SettingsModal';
|
2016-04-29 03:02:51 +08:00
|
|
|
|
|
|
|
const defaultProps = {
|
2016-07-21 22:24:50 +08:00
|
|
|
navbar: <NavBarContainer />,
|
|
|
|
actionsbar: <ActionsBarContainer />,
|
|
|
|
media: <MediaContainer />,
|
2016-05-13 00:10:43 +08:00
|
|
|
settings: <SettingsModal />,
|
2016-04-29 03:02:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class AppContainer extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-07-21 22:24:50 +08:00
|
|
|
// inject location on the navbar container
|
|
|
|
let navbarWithLocation = cloneElement(this.props.navbar, { location: this.props.location });
|
|
|
|
|
2016-04-29 03:02:51 +08:00
|
|
|
return (
|
2016-07-21 22:24:50 +08:00
|
|
|
<App {...this.props} navbar={navbarWithLocation}>
|
2016-04-29 03:02:51 +08:00
|
|
|
{this.props.children}
|
|
|
|
</App>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-06 02:50:18 +08:00
|
|
|
const actionControlsToShow = () => {
|
2016-05-12 23:43:09 +08:00
|
|
|
if (pollExists()) {
|
2016-05-06 02:50:18 +08:00
|
|
|
return <PollingContainer />;
|
|
|
|
} else {
|
|
|
|
return <ActionsBarContainer />;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-07-07 22:46:18 +08:00
|
|
|
let loading = true;
|
|
|
|
const loadingDep = new Tracker.Dependency;
|
2016-07-07 22:01:40 +08:00
|
|
|
|
2016-07-07 22:46:18 +08:00
|
|
|
const getLoading = () => {
|
2016-07-09 07:13:26 +08:00
|
|
|
loadingDep.depend();
|
2016-07-07 22:01:40 +08:00
|
|
|
return loading;
|
|
|
|
};
|
|
|
|
|
2016-07-07 22:46:18 +08:00
|
|
|
const setLoading = (val) => {
|
2016-07-07 22:01:40 +08:00
|
|
|
if (val !== loading) {
|
|
|
|
loading = val;
|
|
|
|
loadingDep.changed();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-29 03:02:51 +08:00
|
|
|
export default createContainer(() => {
|
2016-07-07 22:01:40 +08:00
|
|
|
Promise.all(subscribeForData())
|
|
|
|
.then(() => {
|
|
|
|
setLoading(false);
|
2016-07-29 03:48:26 +08:00
|
|
|
});
|
2016-07-07 22:01:40 +08:00
|
|
|
|
|
|
|
return {
|
2016-07-29 03:48:26 +08:00
|
|
|
wasKicked: didUserWasKicked(),
|
2016-07-07 22:01:40 +08:00
|
|
|
isLoading: getLoading(),
|
2016-07-29 03:48:26 +08:00
|
|
|
redirectToLogoutUrl,
|
2016-07-09 07:13:26 +08:00
|
|
|
actionsbar: <ActionsBarContainer />,
|
2016-07-07 22:01:40 +08:00
|
|
|
};
|
2016-04-29 03:02:51 +08:00
|
|
|
}, AppContainer);
|
2016-07-08 19:59:05 +08:00
|
|
|
|
|
|
|
AppContainer.defaultProps = defaultProps;
|