Remove autobind decorator. Fix bugs in AR view

This commit is contained in:
John Lyon-Smith
2018-05-28 16:12:20 -07:00
parent eb3649547a
commit f07c61c3b5
26 changed files with 1512 additions and 1481 deletions

View File

@@ -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} />
}