mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Enable to show the lock icon only the Editor state is CODE
This commit is contained in:
@@ -19,13 +19,11 @@ class MarkdownEditor extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.lockEditorCode = () => this.handleLockEditor()
|
this.lockEditorCode = () => this.handleLockEditor()
|
||||||
this.getEditorStatus = () => this.handleGetEditorStatus()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
this.value = this.refs.code.value
|
this.value = this.refs.code.value
|
||||||
eventEmitter.on('editor:lock', this.lockEditorCode)
|
eventEmitter.on('editor:lock', this.lockEditorCode)
|
||||||
eventEmitter.on('editor:status', this.getEditorStatus)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate () {
|
componentDidUpdate () {
|
||||||
@@ -41,7 +39,6 @@ class MarkdownEditor extends React.Component {
|
|||||||
componentWillUnmount () {
|
componentWillUnmount () {
|
||||||
this.cancelQueue()
|
this.cancelQueue()
|
||||||
eventEmitter.off('editor:lock', this.lockEditorCode)
|
eventEmitter.off('editor:lock', this.lockEditorCode)
|
||||||
eventEmitter.off('editor:status', this.getEditorStatus)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
queueRendering (value) {
|
queueRendering (value) {
|
||||||
@@ -94,6 +91,7 @@ class MarkdownEditor extends React.Component {
|
|||||||
this.setState({
|
this.setState({
|
||||||
status: 'PREVIEW'
|
status: 'PREVIEW'
|
||||||
}, () => {
|
}, () => {
|
||||||
|
eventEmitter.emit('topbar:lock')
|
||||||
this.refs.preview.focus()
|
this.refs.preview.focus()
|
||||||
this.refs.preview.scrollTo(cursorPosition.line)
|
this.refs.preview.scrollTo(cursorPosition.line)
|
||||||
})
|
})
|
||||||
@@ -143,6 +141,7 @@ class MarkdownEditor extends React.Component {
|
|||||||
this.setState({
|
this.setState({
|
||||||
status: 'CODE'
|
status: 'CODE'
|
||||||
}, () => {
|
}, () => {
|
||||||
|
eventEmitter.emit('topbar:lock')
|
||||||
this.refs.code.focus()
|
this.refs.code.focus()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -26,15 +26,22 @@ class MarkdownNoteDetail extends React.Component {
|
|||||||
title: '',
|
title: '',
|
||||||
content: ''
|
content: ''
|
||||||
}, props.note),
|
}, props.note),
|
||||||
|
isCODE: false,
|
||||||
locked: false
|
locked: false
|
||||||
}
|
}
|
||||||
this.dispatchTimer = null
|
this.dispatchTimer = null
|
||||||
|
|
||||||
|
this.showLockButton = () => this.handleShowLockButton()
|
||||||
}
|
}
|
||||||
|
|
||||||
focus () {
|
focus () {
|
||||||
this.refs.content.focus()
|
this.refs.content.focus()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount () {
|
||||||
|
ee.on('topbar:lock', this.showLockButton)
|
||||||
|
}
|
||||||
|
|
||||||
componentWillReceiveProps (nextProps) {
|
componentWillReceiveProps (nextProps) {
|
||||||
if (nextProps.note.key !== this.props.note.key && !this.isMovingNote) {
|
if (nextProps.note.key !== this.props.note.key && !this.isMovingNote) {
|
||||||
if (this.saveQueue != null) this.saveNow()
|
if (this.saveQueue != null) this.saveNow()
|
||||||
@@ -51,6 +58,10 @@ class MarkdownNoteDetail extends React.Component {
|
|||||||
if (this.saveQueue != null) this.saveNow()
|
if (this.saveQueue != null) this.saveNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidUnmount () {
|
||||||
|
ee.off('topbar:lock', this.showLockButton)
|
||||||
|
}
|
||||||
|
|
||||||
findTitle (value) {
|
findTitle (value) {
|
||||||
let splitted = value.split('\n')
|
let splitted = value.split('\n')
|
||||||
let title = null
|
let title = null
|
||||||
@@ -215,6 +226,10 @@ class MarkdownNoteDetail extends React.Component {
|
|||||||
if (e.keyCode === 27) this.handleDeleteCancelButtonClick(e)
|
if (e.keyCode === 27) this.handleDeleteCancelButtonClick(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleShowLockButton () {
|
||||||
|
this.setState({isCODE: !this.state.isCODE})
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
let { data, config } = this.props
|
let { data, config } = this.props
|
||||||
let { note } = this.state
|
let { note } = this.state
|
||||||
@@ -247,10 +262,8 @@ class MarkdownNoteDetail extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
<div styleName='info-right'>
|
<div styleName='info-right'>
|
||||||
{(() => {
|
{(() => {
|
||||||
// TODO: get a state of MarkdownEditor somehow
|
|
||||||
const editorStatus='CODE'
|
|
||||||
let faClassName=`fa ${this.toggleLockButton()}`
|
let faClassName=`fa ${this.toggleLockButton()}`
|
||||||
if (editorStatus === 'CODE') {
|
if (this.state.isCODE) {
|
||||||
return(
|
return(
|
||||||
<button styleName='info-right-button'
|
<button styleName='info-right-button'
|
||||||
onClick={(e) => this.handleLockButtonClick(e)}
|
onClick={(e) => this.handleLockButtonClick(e)}
|
||||||
|
|||||||
Reference in New Issue
Block a user