Created
February 18, 2016 02:54
-
-
Save austinmao/1d9f5be9d1a6d30ca304 to your computer and use it in GitHub Desktop.
Attempt at adding Progress bar for loading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* App.js | |
* parent component of app | |
*/ | |
/* global $ */ // spec jquery global | |
/* boilerplate */ | |
import React, {Component, PropTypes} from 'react'; | |
import {connect} from 'react-redux'; | |
import {routeActions} from 'react-router-redux'; | |
import Helmet from 'react-helmet'; | |
/* helpers */ | |
import config from '../../config'; | |
/* reducers */ | |
/* render components */ | |
import {Menu} from 'containers'; | |
import injectTapEventPlugin from 'react-tap-event-plugin'; | |
import Progress from 'react-progress-2'; | |
/* styles */ | |
import './app.css'; | |
import 'react-progress-2/main.css'; | |
@connect( | |
state => ({ | |
user: state.auth.user, | |
location: state.routing.location, | |
isAsyncDataLoaded: state.reduxAsyncConnect.loaded | |
}), | |
{pushState: routeActions.push} | |
) | |
export default class App extends Component { | |
static propTypes = { | |
/* states */ | |
children: PropTypes.object.isRequired, | |
// user: PropTypes.object, | |
location: PropTypes.object.isRequired, | |
isAsyncDataLoaded: PropTypes.bool.isRequired, | |
/* actions */ | |
// logout: PropTypes.func.isRequired, | |
pushState: PropTypes.func.isRequired | |
}; | |
static contextTypes = { | |
store: PropTypes.object.isRequired | |
}; | |
componentWillReceiveProps() { | |
// hide progress bar if active and async data loaded | |
console.log(this.props.isAsyncDataLoaded); | |
this.props.isAsyncDataLoaded ? Progress.hide() : Progress.show(); | |
} | |
render() { | |
// pleasure theme. NOTE: required here because it contains references to `window` | |
require('theme'); | |
return ( | |
<div> | |
{/* meta data */} | |
<Helmet {...config.app.head}/> | |
<Menu /> | |
{/* animation transition on route change */} | |
<div className="content"> | |
<Progress.Component /> | |
{React.cloneElement(this.props.children)} | |
</div> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment