Remove autobind decorator. Fix bugs in AR view
This commit is contained in:
@@ -1,28 +1,35 @@
|
||||
import React from 'react'
|
||||
import { Route, Redirect } from 'react-router-native'
|
||||
import { PropTypes } from 'prop-types'
|
||||
import { api } from '../API'
|
||||
import autobind from 'autobind-decorator'
|
||||
import React from "react"
|
||||
import { Route, Redirect } from "react-router-native"
|
||||
import { PropTypes } from "prop-types"
|
||||
import { api } from "../API"
|
||||
import { reactAutoBind, autoBind } from "auto-bind2"
|
||||
|
||||
export class ProtectedRoute extends React.Component {
|
||||
static propTypes = {
|
||||
location: PropTypes.shape({ pathname: PropTypes.string, search: PropTypes.string }),
|
||||
location: PropTypes.shape({
|
||||
pathname: PropTypes.string,
|
||||
search: PropTypes.string,
|
||||
}),
|
||||
admin: PropTypes.bool,
|
||||
}
|
||||
|
||||
@autobind
|
||||
constructor(props) {
|
||||
super(props)
|
||||
reactAutoBind(this)
|
||||
}
|
||||
|
||||
updateComponent() {
|
||||
this.forceUpdate()
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
api.addListener('login', this.updateComponent)
|
||||
api.addListener('logout', this.updateComponent)
|
||||
api.addListener("login", this.updateComponent)
|
||||
api.addListener("logout", this.updateComponent)
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
api.removeListener('login', this.updateComponent)
|
||||
api.removeListener('logout', this.updateComponent)
|
||||
api.removeListener("login", this.updateComponent)
|
||||
api.removeListener("logout", this.updateComponent)
|
||||
}
|
||||
|
||||
render(props) {
|
||||
@@ -32,7 +39,7 @@ export class ProtectedRoute extends React.Component {
|
||||
return null
|
||||
} else {
|
||||
if (!user._id || (this.props.admin && !user.administrator)) {
|
||||
return <Redirect to='/login' />
|
||||
return <Redirect to="/login" />
|
||||
} else {
|
||||
return <Route {...this.props} />
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user