5
5
* This source code is licensed under the license found in the LICENSE file in
6
6
* the root directory of this source tree.
7
7
*/
8
- import CodeEditor from 'components/CodeEditor/CodeEditor .react' ;
8
+ import CodeSnippet from 'components/CodeSnippet/CodeSnippet .react' ;
9
9
import DashboardView from 'dashboard/DashboardView.react' ;
10
10
import EmptyState from 'components/EmptyState/EmptyState.react' ;
11
11
import FileTree from 'components/FileTree/FileTree.react' ;
12
12
import history from 'dashboard/history' ;
13
13
import React from 'react' ;
14
14
import styles from 'dashboard/Data/CloudCode/CloudCode.scss' ;
15
15
import Toolbar from 'components/Toolbar/Toolbar.react' ;
16
- import SaveButton from 'components/SaveButton/SaveButton.react' ;
17
16
18
17
function getPath ( params ) {
19
18
const last = params . location . pathname . split ( 'cloud_code/' ) [ 1 ]
@@ -28,9 +27,7 @@ export default class CloudCode extends DashboardView {
28
27
29
28
this . state = {
30
29
files : undefined ,
31
- source : undefined ,
32
- saveState : SaveButton . States . WAITING ,
33
- saveError : '' ,
30
+ source : undefined
34
31
} ;
35
32
}
36
33
@@ -59,14 +56,8 @@ export default class CloudCode extends DashboardView {
59
56
history . replace ( this . context . generatePath ( `cloud_code/${ Object . keys ( release . files ) [ 0 ] } ` ) )
60
57
} else {
61
58
// Means we can load /cloud_code/<fileName>
62
- this . setState ( { source : undefined } )
63
59
app . getSource ( fileName ) . then (
64
- ( source ) => {
65
- this . setState ( { source : source } )
66
- if ( this . editor ) {
67
- this . editor . value = source ;
68
- }
69
- } ,
60
+ ( source ) => this . setState ( { source : source } ) ,
70
61
( ) => this . setState ( { source : undefined } )
71
62
) ;
72
63
}
@@ -96,23 +87,7 @@ export default class CloudCode extends DashboardView {
96
87
</ div >
97
88
) ;
98
89
}
99
- async getCode ( ) {
100
- if ( ! this . editor ) {
101
- return ;
102
- }
103
- this . setState ( { saveState : SaveButton . States . SAVING } ) ;
104
- let fileName = getPath ( this . props ) ;
105
- try {
106
- await this . context . currentApp . saveSource ( fileName , this . editor . value ) ;
107
- this . setState ( { saveState : SaveButton . States . SUCCEEDED } ) ;
108
- setTimeout ( ( ) => {
109
- this . setState ( { saveState : SaveButton . States . WAITING } ) ;
110
- } , 2000 ) ;
111
- } catch ( e ) {
112
- this . setState ( { saveState : SaveButton . States . FAILED } ) ;
113
- this . setState ( { saveError : e . message || e } ) ;
114
- }
115
- }
90
+
116
91
renderContent ( ) {
117
92
let toolbar = null ;
118
93
let content = null ;
@@ -136,20 +111,10 @@ export default class CloudCode extends DashboardView {
136
111
subsection = { fileName } /> ;
137
112
138
113
let source = this . state . files [ fileName ] ;
139
- if ( ( source && source . source ) || this . state . source ) {
114
+ if ( source && source . source ) {
140
115
content = (
141
116
< div className = { styles . content } >
142
- < CodeEditor
143
- placeHolder = { this . state . source || source . source }
144
- ref = { editor => ( this . editor = editor ) }
145
- fontSize = { '14px' }
146
- />
147
- < SaveButton
148
- state = { this . state . saveState }
149
- waitingText = { this . state . submitText }
150
- savingText = { this . state . inProgressText }
151
- failedText = { this . state . saveError }
152
- onClick = { ( ) => this . getCode ( this ) } > </ SaveButton >
117
+ < CodeSnippet source = { source . source } language = 'javascript' />
153
118
</ div >
154
119
) ;
155
120
}
0 commit comments