mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
add toggle preview mode button
This commit is contained in:
@@ -101,6 +101,8 @@ export default class ArticleDetail extends React.Component {
|
|||||||
isModeChanged: false,
|
isModeChanged: false,
|
||||||
openShareDropdown: false
|
openShareDropdown: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (props.activeArticle != null && props.activeArticle.mode === 'markdown') this.state.previewMode = true
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
@@ -120,10 +122,16 @@ export default class ArticleDetail extends React.Component {
|
|||||||
let nextModified = nextArticle != null ? _.findWhere(nextProps.modified, {key: nextArticle.key}) : null
|
let nextModified = nextArticle != null ? _.findWhere(nextProps.modified, {key: nextArticle.key}) : null
|
||||||
|
|
||||||
let article = Object.assign({}, nextProps.activeArticle, nextModified)
|
let article = Object.assign({}, nextProps.activeArticle, nextModified)
|
||||||
|
let nextState = {
|
||||||
|
article,
|
||||||
|
previewMode: false
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({
|
if (article.mode === 'markdown') {
|
||||||
article
|
nextState.previewMode = true
|
||||||
})
|
}
|
||||||
|
|
||||||
|
this.setState(nextState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +242,7 @@ export default class ArticleDetail extends React.Component {
|
|||||||
this.setState({
|
this.setState({
|
||||||
previewMode: false
|
previewMode: false
|
||||||
}, function () {
|
}, function () {
|
||||||
console.log(this.state.cursorPosition)
|
if (this.state.cursorPosition == null) return true
|
||||||
this.refs.code.moveCursorTo(this.state.cursorPosition.row, this.state.cursorPosition.column)
|
this.refs.code.moveCursorTo(this.state.cursorPosition.row, this.state.cursorPosition.column)
|
||||||
this.refs.code.scrollToLine(this.state.firstVisibleRow)
|
this.refs.code.scrollToLine(this.state.firstVisibleRow)
|
||||||
this.refs.code.editor.focus()
|
this.refs.code.editor.focus()
|
||||||
@@ -281,6 +289,14 @@ export default class ArticleDetail extends React.Component {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<div className='ArticleDetail-info-control'>
|
<div className='ArticleDetail-info-control'>
|
||||||
|
{
|
||||||
|
this.state.article.mode === 'markdown'
|
||||||
|
? <button onClick={e => this.handleTogglePreviewButtonClick(e)}>
|
||||||
|
{this.state.previewMode ? <i className='fa fa-fw fa-code'/> : <i className='fa fa-fw fa-image'/>}<span className='tooltip'>Toggle preview (⌘ + p)</span>
|
||||||
|
</button>
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
|
||||||
<ShareButton
|
<ShareButton
|
||||||
article={activeArticle}
|
article={activeArticle}
|
||||||
user={user}
|
user={user}
|
||||||
|
|||||||
Reference in New Issue
Block a user