11import React , { PropTypes } from 'react'
2+ import ReactDOM from 'react-dom'
23import moment from 'moment'
34import _ from 'lodash'
45import ModeIcon from 'boost/components/ModeIcon'
56import MarkdownPreview from 'boost/components/MarkdownPreview'
67import CodeEditor from 'boost/components/CodeEditor'
7- import { IDLE_MODE , CREATE_MODE , EDIT_MODE , switchMode , switchArticle , switchFolder , clearSearch , updateArticle , destroyArticle } from 'boost/actions'
8+ import { IDLE_MODE , CREATE_MODE , EDIT_MODE , switchMode , switchArticle , switchFolder , clearSearch , updateArticle , destroyArticle , NEW } from 'boost/actions'
89import aceModes from 'boost/ace-modes'
910import Select from 'react-select'
1011import linkState from 'boost/linkState'
@@ -32,23 +33,33 @@ export default class ArticleDetail extends React.Component {
3233 }
3334 }
3435
36+ componentDidUpdate ( prevProps ) {
37+ let isModeChanged = prevProps . status . mode !== this . props . status . mode
38+ if ( isModeChanged && this . props . status . mode !== IDLE_MODE ) {
39+ ReactDOM . findDOMNode ( this . refs . title ) . focus ( )
40+ }
41+ }
42+
3543 componentWillReceiveProps ( nextProps ) {
3644 let nextState = { }
3745
3846 let isArticleChanged = nextProps . activeArticle != null && ( nextProps . activeArticle . key !== this . state . article . key )
3947 let isModeChanged = nextProps . status . mode !== this . props . status . mode
48+ // Reset article input
4049 if ( isArticleChanged || ( isModeChanged && nextProps . status . mode !== IDLE_MODE ) ) {
4150 Object . assign ( nextState , {
4251 article : makeInstantArticle ( nextProps . activeArticle )
4352 } )
4453 }
4554
55+ // Clean state
4656 if ( isModeChanged ) {
4757 Object . assign ( nextState , {
4858 openDeleteConfirmMenu : false ,
4959 previewMode : false
5060 } )
5161 }
62+
5263 this . setState ( nextState )
5364 }
5465
@@ -76,7 +87,7 @@ export default class ArticleDetail extends React.Component {
7687 this . setState ( { openDeleteConfirmMenu : false } )
7788 }
7889
79- handleDeleteCancleButtonClick ( e ) {
90+ handleDeleteCancelButtonClick ( e ) {
8091 this . setState ( { openDeleteConfirmMenu : false } )
8192 }
8293
@@ -102,7 +113,7 @@ export default class ArticleDetail extends React.Component {
102113 < button onClick = { e => this . handleDeleteConfirmButtonClick ( e ) } className = 'primary' >
103114 < i className = 'fa fa-fw fa-check' /> Sure
104115 </ button >
105- < button onClick = { e => this . handleDeleteCancleButtonClick ( e ) } >
116+ < button onClick = { e => this . handleDeleteCancelButtonClick ( e ) } >
106117 < i className = 'fa fa-fw fa-times' /> Cancel
107118 </ button >
108119 </ div >
@@ -119,8 +130,12 @@ export default class ArticleDetail extends React.Component {
119130 < div className = 'tags' > < i className = 'fa fa-fw fa-tags' /> { tags } </ div >
120131 </ div >
121132 < div className = 'right' >
122- < button onClick = { e => this . handleEditButtonClick ( e ) } > < i className = 'fa fa-fw fa-edit' /> </ button >
123- < button onClick = { e => this . handleDeleteButtonClick ( e ) } > < i className = 'fa fa-fw fa-trash' /> </ button >
133+ < button onClick = { e => this . handleEditButtonClick ( e ) } className = 'editBtn' >
134+ < i className = 'fa fa-fw fa-edit' /> < span className = 'tooltip' > Edit 編集(e)</ span >
135+ </ button >
136+ < button onClick = { e => this . handleDeleteButtonClick ( e ) } className = 'deleteBtn' >
137+ < i className = 'fa fa-fw fa-trash' /> < span className = 'tooltip' > Delete 削除(d)</ span >
138+ </ button >
124139 </ div >
125140 </ div >
126141 )
@@ -143,7 +158,9 @@ export default class ArticleDetail extends React.Component {
143158 }
144159
145160 handleCancelButtonClick ( e ) {
146- this . props . dispatch ( switchMode ( IDLE_MODE ) )
161+ let { activeArticle, dispatch } = this . props
162+ if ( activeArticle . status === NEW ) dispatch ( switchArticle ( null ) )
163+ dispatch ( switchMode ( IDLE_MODE ) )
147164 }
148165
149166 handleSaveButtonClick ( e ) {
0 commit comments