Add react new error handeling with componentDidCatch
This commit is contained in:
@@ -7,21 +7,18 @@ import { push } from 'react-router-redux'
|
|||||||
import Snackbar from 'material-ui/Snackbar'
|
import Snackbar from 'material-ui/Snackbar'
|
||||||
import LinearProgress from 'material-ui/LinearProgress'
|
import LinearProgress from 'material-ui/LinearProgress'
|
||||||
|
|
||||||
|
|
||||||
// - Import components
|
// - Import components
|
||||||
import Home from 'components/Home'
|
import Home from 'components/Home'
|
||||||
import Signup from 'components/Signup'
|
import Signup from 'components/Signup'
|
||||||
import Login from 'components/Login'
|
import Login from 'components/Login'
|
||||||
import Settings from 'components/Settings'
|
import Settings from 'components/Settings'
|
||||||
import MasterLoading from 'components/MasterLoading'
|
import MasterLoading from 'components/MasterLoading'
|
||||||
import { IMasterProps } from "./IMasterProps"
|
import { IMasterProps } from './IMasterProps'
|
||||||
import { IMasterState } from "./IMasterState"
|
import { IMasterState } from './IMasterState'
|
||||||
|
|
||||||
|
|
||||||
// - Import API
|
// - Import API
|
||||||
import { PrivateRoute, PublicRoute } from 'api/AuthRouterAPI'
|
import { PrivateRoute, PublicRoute } from 'api/AuthRouterAPI'
|
||||||
|
|
||||||
|
|
||||||
// - Import actions
|
// - Import actions
|
||||||
import * as authorizeActions from 'actions/authorizeActions'
|
import * as authorizeActions from 'actions/authorizeActions'
|
||||||
import * as imageGalleryActions from 'actions/imageGalleryActions'
|
import * as imageGalleryActions from 'actions/imageGalleryActions'
|
||||||
@@ -33,12 +30,8 @@ import * as globalActions from 'actions/globalActions'
|
|||||||
import * as circleActions from 'actions/circleActions'
|
import * as circleActions from 'actions/circleActions'
|
||||||
import * as notifyActions from 'actions/notifyActions'
|
import * as notifyActions from 'actions/notifyActions'
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------ */
|
/* ------------------------------------ */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// - Create Master component class
|
// - Create Master component class
|
||||||
export class Master extends Component<IMasterProps,IMasterState> {
|
export class Master extends Component<IMasterProps,IMasterState> {
|
||||||
|
|
||||||
@@ -56,7 +49,6 @@ export class Master extends Component<IMasterProps,IMasterState>{
|
|||||||
this.handleLoading = this.handleLoading.bind(this)
|
this.handleLoading = this.handleLoading.bind(this)
|
||||||
this.handleMessage = this.handleMessage.bind(this)
|
this.handleMessage = this.handleMessage.bind(this)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle click on message
|
// Handle click on message
|
||||||
@@ -72,6 +64,12 @@ export class Master extends Component<IMasterProps,IMasterState>{
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidCatch (error: any, info: any) {
|
||||||
|
console.log('====================================')
|
||||||
|
console.log(error, info)
|
||||||
|
console.log('====================================')
|
||||||
|
}
|
||||||
|
|
||||||
componentWillMount () {
|
componentWillMount () {
|
||||||
|
|
||||||
firebaseAuth().onAuthStateChanged((user: any) => {
|
firebaseAuth().onAuthStateChanged((user: any) => {
|
||||||
@@ -81,7 +79,6 @@ export class Master extends Component<IMasterProps,IMasterState>{
|
|||||||
this.setState({
|
this.setState({
|
||||||
loading: false
|
loading: false
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!this.props.global.defaultLoadDataStatus) {
|
if (!this.props.global.defaultLoadDataStatus) {
|
||||||
this.props.clearData()
|
this.props.clearData()
|
||||||
this.props.loadData()
|
this.props.loadData()
|
||||||
@@ -102,8 +99,6 @@ export class Master extends Component<IMasterProps,IMasterState>{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render app DOM component
|
* Render app DOM component
|
||||||
*
|
*
|
||||||
@@ -116,10 +111,10 @@ export class Master extends Component<IMasterProps,IMasterState>{
|
|||||||
const {progress, global} = this.props
|
const {progress, global} = this.props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="master">
|
<div id='master'>
|
||||||
|
|
||||||
<div className='master__progress' style={{display: (progress.visible ? 'block' : 'none' )}}>
|
<div className='master__progress' style={{display: (progress.visible ? 'block' : 'none' )}}>
|
||||||
<LinearProgress mode="determinate" value={progress.percent} />
|
<LinearProgress mode='determinate' value={progress.percent} />
|
||||||
</div>
|
</div>
|
||||||
<div className='master__loading animate-fading2' style={{display: ( global.showTopLoading ? 'flex' : 'none' )}}>
|
<div className='master__loading animate-fading2' style={{display: ( global.showTopLoading ? 'flex' : 'none' )}}>
|
||||||
<div className='title'>Loading ... </div>
|
<div className='title'>Loading ... </div>
|
||||||
@@ -128,13 +123,13 @@ export class Master extends Component<IMasterProps,IMasterState>{
|
|||||||
|
|
||||||
{(!this.state.loading && (this.props.loaded || this.props.guest))
|
{(!this.state.loading && (this.props.loaded || this.props.guest))
|
||||||
? (<Switch>
|
? (<Switch>
|
||||||
<Route path="/signup" component={Signup} />
|
<Route path='/signup' component={Signup} />
|
||||||
<Route path="/settings" component={Settings} />
|
<Route path='/settings' component={Settings} />
|
||||||
<Route path="/login" render={() => {
|
<Route path='/login' render={() => {
|
||||||
console.log('this.props.authed: ', this.props.authed, "this.props: ", this.props)
|
console.log('this.props.authed: ', this.props.authed, 'this.props: ', this.props)
|
||||||
return (
|
return (
|
||||||
this.props.authed
|
this.props.authed
|
||||||
? <Redirect to="/" />
|
? <Redirect to='/' />
|
||||||
: <Login />
|
: <Login />
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user