1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

Add lock icon to NoteDetail

This commit is contained in:
asmsuechan
2017-02-11 15:48:38 +09:00
parent dbf1d6403b
commit 74ee6ae6ce
2 changed files with 42 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ import CSSModules from 'browser/lib/CSSModules'
import styles from './MarkdownEditor.styl' import styles from './MarkdownEditor.styl'
import CodeEditor from 'browser/components/CodeEditor' import CodeEditor from 'browser/components/CodeEditor'
import MarkdownPreview from 'browser/components/MarkdownPreview' import MarkdownPreview from 'browser/components/MarkdownPreview'
import eventEmitter from 'browser/main/lib/eventEmitter'
class MarkdownEditor extends React.Component { class MarkdownEditor extends React.Component {
constructor (props) { constructor (props) {
@@ -13,12 +14,18 @@ class MarkdownEditor extends React.Component {
this.state = { this.state = {
status: 'PREVIEW', status: 'PREVIEW',
renderValue: props.value, renderValue: props.value,
keyPressed: {} keyPressed: {},
locked: false
} }
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:status', this.getEditorStatus)
} }
componentDidUpdate () { componentDidUpdate () {
@@ -33,6 +40,8 @@ class MarkdownEditor extends React.Component {
componentWillUnmount () { componentWillUnmount () {
this.cancelQueue() this.cancelQueue()
eventEmitter.off('editor:lock', this.lockEditorCode)
eventEmitter.off('editor:status', this.getEditorStatus)
} }
queueRendering (value) { queueRendering (value) {
@@ -77,6 +86,7 @@ class MarkdownEditor extends React.Component {
} }
handleBlur (e) { handleBlur (e) {
if (this.state.locked) return
this.setState({ keyPressed: [] }) this.setState({ keyPressed: [] })
let { config } = this.props let { config } = this.props
if (config.editor.switchPreview === 'BLUR') { if (config.editor.switchPreview === 'BLUR') {
@@ -152,7 +162,7 @@ class MarkdownEditor extends React.Component {
}) })
this.setState({ keyPressed }) this.setState({ keyPressed })
let isNoteHandlerKey = (el) => { return this.state.keyPressed[el] } let isNoteHandlerKey = (el) => { return this.state.keyPressed[el] }
if (this.state.status === 'CODE' && this.escapeFromEditor.every(isNoteHandlerKey)) { if (!this.state.locked && this.state.status === 'CODE' && this.escapeFromEditor.every(isNoteHandlerKey)) {
document.activeElement.blur() document.activeElement.blur()
} }
} }
@@ -164,6 +174,10 @@ class MarkdownEditor extends React.Component {
this.setState({ keyPressed }) this.setState({ keyPressed })
} }
handleLockEditor () {
this.setState({ locked: !this.state.locked })
}
render () { render () {
let { className, value, config } = this.props let { className, value, config } = this.props

View File

@@ -25,7 +25,8 @@ class MarkdownNoteDetail extends React.Component {
note: Object.assign({ note: Object.assign({
title: '', title: '',
content: '' content: ''
}, props.note) }, props.note),
locked: false
} }
this.dispatchTimer = null this.dispatchTimer = null
} }
@@ -200,6 +201,16 @@ class MarkdownNoteDetail extends React.Component {
} }
} }
handleLockButtonClick () {
ee.emit('editor:lock')
this.focus()
this.setState({ locked: !this.state.locked })
}
toggleLockButton () {
return this.state.locked ? 'fa-lock' : 'fa-unlock-alt'
}
handleDeleteKeyDown (e) { handleDeleteKeyDown (e) {
if (e.keyCode === 27) this.handleDeleteCancelButtonClick(e) if (e.keyCode === 27) this.handleDeleteCancelButtonClick(e)
} }
@@ -235,6 +246,20 @@ 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()}`
if (editorStatus === 'CODE') {
return(
<button styleName='info-right-button'
onClick={(e) => this.handleLockButtonClick(e)}
>
<i className={faClassName}/>
</button>
)
}
})()}
<button styleName='info-right-button' <button styleName='info-right-button'
onClick={(e) => this.handleContextButtonClick(e)} onClick={(e) => this.handleContextButtonClick(e)}
> >