Skip to content
Snippets Groups Projects
Commit c0acc224 authored by Yannis Barlas's avatar Yannis Barlas
Browse files

Merged in locks (pull request #9)

lock fragment on editor use
parents 2094e65f 10d04c29
No related branches found
No related tags found
No related merge requests found
import { find } from 'lodash' import { get, find } from 'lodash'
import React from 'react' import React from 'react'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { bindActionCreators } from 'redux' import { bindActionCreators } from 'redux'
...@@ -13,7 +13,10 @@ export class SimpleEditorWrapper extends React.Component { ...@@ -13,7 +13,10 @@ export class SimpleEditorWrapper extends React.Component {
this.save = this.save.bind(this) this.save = this.save.bind(this)
this.updateComments = this.updateComments.bind(this) this.updateComments = this.updateComments.bind(this)
this._checkRights = this._checkRights.bind(this) this._checkRights = this._checkRights.bind(this)
this._releaseLock = this._releaseLock.bind(this)
this._acquireLock = this._acquireLock.bind(this)
this.state = { this.state = {
canEdit: false canEdit: false
...@@ -28,6 +31,37 @@ export class SimpleEditorWrapper extends React.Component { ...@@ -28,6 +31,37 @@ export class SimpleEditorWrapper extends React.Component {
}) })
this._checkRights() this._checkRights()
this._acquireLock()
}
componentDidMount () {
window.addEventListener('beforeunload', this._releaseLock)
}
componentWillUnmount () {
this._releaseLock()
window.removeEventListener('beforeunload', this._releaseLock)
}
_releaseLock () {
const { book, fragment, user } = this.props
const { updateFragment } = this.props.actions
if (get(fragment, 'lock.editor.username') && get(fragment, 'lock.editor.username') === user.username) {
fragment.lock = null
}
updateFragment(book, fragment)
}
_acquireLock () {
const { book, fragment, user } = this.props
const { updateFragment } = this.props.actions
fragment.lock = {
editor: {
username: user.username
}
}
updateFragment(book, fragment)
} }
// componentDidUpdate () { // componentDidUpdate () {
......
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