@@ -3,6 +3,7 @@ import { connect } from 'react-redux';
3
3
import { bindActionCreators } from 'redux' ;
4
4
import { browserHistory , withRouter , Link } from 'react-router' ;
5
5
import _ from 'underscore' ;
6
+ import { HotKeys } from 'react-hotkeys' ;
6
7
import Button from '../../components/Button' ;
7
8
import Splitter from '../../components/Splitter' ;
8
9
import Errors from '../../components/Errors' ;
@@ -14,13 +15,20 @@ import Metadata from '../MetaFields';
14
15
import { fetchPage , deletePage , putPage } from '../../actions/pages' ;
15
16
import { updateTitle , updateBody , updatePath } from '../../actions/metadata' ;
16
17
import { clearErrors } from '../../actions/utils' ;
18
+ import { preventDefault } from '../../utils/helpers' ;
17
19
import {
18
20
getLeaveMessage , getDeleteMessage , getNotFoundMessage
19
21
} from '../../constants/lang' ;
20
22
import { ADMIN_PREFIX } from '../../constants' ;
21
23
22
24
export class PageEdit extends Component {
23
25
26
+ constructor ( props ) {
27
+ super ( props ) ;
28
+
29
+ this . handleClickSave = this . handleClickSave . bind ( this ) ;
30
+ }
31
+
24
32
componentDidMount ( ) {
25
33
const { fetchPage, params, router, route } = this . props ;
26
34
const [ directory , ...rest ] = params . splat ;
@@ -55,8 +63,12 @@ export class PageEdit extends Component {
55
63
}
56
64
}
57
65
58
- handleClickSave ( ) {
66
+ handleClickSave ( e ) {
59
67
const { putPage, fieldChanged, params } = this . props ;
68
+
69
+ // Prevent the default event from bubbling
70
+ preventDefault ( e ) ;
71
+
60
72
if ( fieldChanged ) {
61
73
const [ directory , ...rest ] = params . splat ;
62
74
const filename = rest . join ( '.' ) ;
@@ -87,11 +99,17 @@ export class PageEdit extends Component {
87
99
return < h1 > { `Could not find the page.` } </ h1 > ;
88
100
}
89
101
102
+ const keyboardHandlers = {
103
+ 'save' : this . handleClickSave ,
104
+ } ;
105
+
90
106
const { name, raw_content, http_url, path, front_matter } = page ;
91
107
const [ directory , ...rest ] = params . splat ;
92
108
const title = front_matter && front_matter . title ? front_matter . title : '' ;
93
109
return (
94
- < div className = "single" >
110
+ < HotKeys
111
+ handlers = { keyboardHandlers }
112
+ className = "single" >
95
113
{ errors . length > 0 && < Errors errors = { errors } /> }
96
114
< div className = "content-header" >
97
115
< Breadcrumbs splat = { directory || '' } type = "pages" />
@@ -103,7 +121,7 @@ export class PageEdit extends Component {
103
121
< InputTitle onChange = { updateTitle } title = { title } ref = "title" />
104
122
< MarkdownEditor
105
123
onChange = { updateBody }
106
- onSave = { ( ) => this . handleClickSave ( ) }
124
+ onSave = { this . handleClickSave }
107
125
placeholder = "Body"
108
126
initialValue = { raw_content }
109
127
ref = "editor" />
@@ -113,7 +131,7 @@ export class PageEdit extends Component {
113
131
114
132
< div className = "content-side" >
115
133
< Button
116
- onClick = { ( ) => this . handleClickSave ( ) }
134
+ onClick = { this . handleClickSave }
117
135
type = "save"
118
136
active = { fieldChanged }
119
137
triggered = { updated }
@@ -134,7 +152,7 @@ export class PageEdit extends Component {
134
152
block />
135
153
</ div >
136
154
</ div >
137
- </ div >
155
+ </ HotKeys >
138
156
) ;
139
157
}
140
158
0 commit comments