@@ -11,13 +11,15 @@ import Toolbar from 'components/Toolbar/Toolbar.react';
11
11
12
12
import styles from './Playground.scss' ;
13
13
14
+ const placeholderCode = "const myObj = new Parse.Object('MyClass');\nmyObj.set('myField', 'Hello World!');\nawait myObj.save();\nconsole.log(myObj);" ;
14
15
export default class Playground extends Component {
15
16
constructor ( ) {
16
17
super ( ) ;
17
18
this . section = 'API' ;
18
19
this . subsection = 'JS Console' ;
19
20
this . localKey = 'parse-dashboard-playground-code' ;
20
21
this . state = {
22
+ code : '' ,
21
23
results : [ ] ,
22
24
running : false ,
23
25
saving : false ,
@@ -90,7 +92,7 @@ export default class Playground extends Component {
90
92
}
91
93
})()` ;
92
94
93
- this . setState ( { running : true , results : [ ] } ) ;
95
+ this . setState ( { running : true , results : [ ] , code : originalCode } ) ;
94
96
95
97
await new Function ( 'Parse' , finalCode ) ( Parse ) ;
96
98
} catch ( e ) {
@@ -109,6 +111,7 @@ export default class Playground extends Component {
109
111
110
112
window . localStorage . setItem ( this . localKey , code ) ;
111
113
this . setState ( {
114
+ code,
112
115
saving : false ,
113
116
savingState : SaveButton . States . SUCCEEDED
114
117
} ) ;
@@ -134,9 +137,14 @@ export default class Playground extends Component {
134
137
componentDidMount ( ) {
135
138
if ( window . localStorage ) {
136
139
const initialCode = window . localStorage . getItem ( this . localKey ) ;
140
+ let code = '' ;
137
141
if ( initialCode ) {
138
- this . editor . value = initialCode ;
142
+ code = initialCode ;
143
+ } else {
144
+ code = placeholderCode ;
139
145
}
146
+ this . editor . value = code ;
147
+ this . setState ( { code } ) ;
140
148
}
141
149
}
142
150
@@ -148,10 +156,7 @@ export default class Playground extends Component {
148
156
< Toolbar section = { this . section } subsection = { this . subsection } />
149
157
< div style = { { height : 'calc(100vh - 96px)' } } >
150
158
< CodeEditor
151
- placeHolder = { `const myObj = new Parse.Object('MyClass');
152
- myObj.set('myField', 'Hello World!')
153
- await myObj.save();
154
- console.log(myObj);` }
159
+ code = { this . state . code }
155
160
ref = { editor => ( this . editor = editor ) }
156
161
/>
157
162
< div className = { styles [ 'console-ctn' ] } >
0 commit comments