Skip to content
Snippets Groups Projects
Commit 7b0f883c authored by chris's avatar chris Committed by john
Browse files

fix: on page refresh editor no longer crashes

parent 5078c76c
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,18 @@ export default class SimpleEditor extends React.Component { ...@@ -19,6 +19,18 @@ export default class SimpleEditor extends React.Component {
super(props) super(props)
this.save = this.save.bind(this) this.save = this.save.bind(this)
this.updateTrackChangesStatus = this.updateTrackChangesStatus.bind(this) this.updateTrackChangesStatus = this.updateTrackChangesStatus.bind(this)
this._checkRights = this._checkRights.bind(this)
this.state = {
canEdit: false
}
}
componentWillMount () {
const { fragment } = this.props
if (fragment) {
this._checkRights()
// this._acquireLock()
}
} }
createSession () { createSession () {
...@@ -59,15 +71,45 @@ export default class SimpleEditor extends React.Component { ...@@ -59,15 +71,45 @@ export default class SimpleEditor extends React.Component {
onSave(convertedSource, callback) onSave(convertedSource, callback)
} }
_checkRights () {
const { fragment, user } = this.props
if (user.admin) return this.setState({ canEdit: true })
if ((fragment.progress['review'] === 1 && user.teams[0].teamType.name === 'Author') ||
(fragment.progress['edit'] === 1 && user.teams[0].teamType.name === 'Copy Editor')) {
this.setState({ canEdit: true })
} else {
this.setState({ canEdit: false })
}
if (user.teams[0].teamType.name === 'Production Editor') {
this.setState({ canEdit: true })
}
}
componentWillReceiveProps (nextProps) {
const { fragment } = this.props
if (fragment) return
var self = this
if (nextProps.fragment) {
setTimeout(function () {
self._checkRights()
self.componentDidMount()
}, 0)
}
}
componentDidMount () { componentDidMount () {
const { canEdit } = this.props
const { onSave } = this.props const { onSave } = this.props
const el = ReactDOM.findDOMNode(this) const el = ReactDOM.findDOMNode(this)
const { fragment } = this.props
const session = this.createSession() const session = this.createSession()
const documentSession = session.documentSession const documentSession = session.documentSession
const configurator = session.configurator const configurator = session.configurator
if (!fragment) return
this.setState({ this.setState({
config: configurator.config config: configurator.config
}) })
...@@ -76,7 +118,7 @@ export default class SimpleEditor extends React.Component { ...@@ -76,7 +118,7 @@ export default class SimpleEditor extends React.Component {
book: this.props.book, book: this.props.book,
configurator: configurator, configurator: configurator,
containerId: 'body', containerId: 'body',
disabled: !canEdit, // set to true read only mode disabled: !this.state.canEdit, // set to true read only mode
documentSession: documentSession, documentSession: documentSession,
fileUpload: this.props.fileUpload, fileUpload: this.props.fileUpload,
fragment: this.props.fragment, fragment: this.props.fragment,
...@@ -110,9 +152,7 @@ export default class SimpleEditor extends React.Component { ...@@ -110,9 +152,7 @@ export default class SimpleEditor extends React.Component {
// } // }
render () { render () {
const { canEdit } = this.props let viewMode = !this.state.canEdit
let viewMode = !canEdit
? ( ? (
<Alert bsStyle='warning' className='view-mode'> <Alert bsStyle='warning' className='view-mode'>
<span>Editor is in Read-Only Mode</span> <span>Editor is in Read-Only Mode</span>
...@@ -131,10 +171,9 @@ export default class SimpleEditor extends React.Component { ...@@ -131,10 +171,9 @@ export default class SimpleEditor extends React.Component {
SimpleEditor.propTypes = { SimpleEditor.propTypes = {
book: React.PropTypes.object.isRequired, book: React.PropTypes.object.isRequired,
canEdit: React.PropTypes.bool, canEdit: React.PropTypes.bool,
fragment: React.PropTypes.object.isRequired, fragment: React.PropTypes.object,
history: React.PropTypes.object.isRequired, history: React.PropTypes.object.isRequired,
onSave: React.PropTypes.func.isRequired, onSave: React.PropTypes.func.isRequired,
trackChanges: React.PropTypes.bool.isRequired,
update: React.PropTypes.func.isRequired, update: React.PropTypes.func.isRequired,
updateComments: React.PropTypes.func.isRequired, updateComments: React.PropTypes.func.isRequired,
fileUpload: React.PropTypes.func.isRequired, fileUpload: React.PropTypes.func.isRequired,
......
...@@ -16,7 +16,6 @@ export class SimpleEditorWrapper extends React.Component { ...@@ -16,7 +16,6 @@ export class SimpleEditorWrapper extends React.Component {
this.updateComments = this.updateComments.bind(this) this.updateComments = this.updateComments.bind(this)
this.fileUpload = this.fileUpload.bind(this) this.fileUpload = this.fileUpload.bind(this)
this._checkRights = this._checkRights.bind(this)
this._releaseLock = this._releaseLock.bind(this) this._releaseLock = this._releaseLock.bind(this)
this._acquireLock = this._acquireLock.bind(this) this._acquireLock = this._acquireLock.bind(this)
...@@ -35,8 +34,8 @@ export class SimpleEditorWrapper extends React.Component { ...@@ -35,8 +34,8 @@ export class SimpleEditorWrapper extends React.Component {
const { user } = this.props const { user } = this.props
user.roles = this.getRoles() user.roles = this.getRoles()
this._checkRights() // this._checkRights()
this._acquireLock() // this._acquireLock()
} }
componentDidMount () { componentDidMount () {
...@@ -70,28 +69,6 @@ export class SimpleEditorWrapper extends React.Component { ...@@ -70,28 +69,6 @@ export class SimpleEditorWrapper extends React.Component {
updateFragment(book, fragment) updateFragment(book, fragment)
} }
// componentDidUpdate () {
// console.log('did update wrapper')
// // this._checkRights()
// }
// TODO -- refactor
_checkRights () {
const { fragment, user } = this.props
if (user.admin) return this.setState({ canEdit: true })
if ((fragment.progress['review'] === 1 && user.teams[0].teamType.name === 'Author') ||
(fragment.progress['edit'] === 1 && user.teams[0].teamType.name === 'Copy Editor')) {
this.setState({ canEdit: true })
} else {
this.setState({ canEdit: false })
}
if (user.teams[0].teamType.name === 'Production Editor') {
this.setState({ canEdit: true })
}
}
save (source, callback) { save (source, callback) {
const { book, fragment } = this.props const { book, fragment } = this.props
const { updateFragment } = this.props.actions const { updateFragment } = this.props.actions
...@@ -173,10 +150,10 @@ export class SimpleEditorWrapper extends React.Component { ...@@ -173,10 +150,10 @@ export class SimpleEditorWrapper extends React.Component {
SimpleEditorWrapper.propTypes = { SimpleEditorWrapper.propTypes = {
actions: React.PropTypes.object.isRequired, actions: React.PropTypes.object.isRequired,
book: React.PropTypes.object.isRequired, book: React.PropTypes.object.isRequired,
fragment: React.PropTypes.object.isRequired, fragment: React.PropTypes.object,
history: React.PropTypes.object.isRequired, history: React.PropTypes.object.isRequired,
user: React.PropTypes.object.isRequired, user: React.PropTypes.object.isRequired,
update: React.PropTypes.func.isRequired update: React.PropTypes.func
} }
function mapStateToProps (state, ownProps) { function mapStateToProps (state, ownProps) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment