Skip to content

Commit 63d63be

Browse files
authored
added state var to track changes in js_console (#427)
1 parent dc7ee8b commit 63d63be

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/dashboard/Data/Playground/Playground.react.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import Toolbar from 'components/Toolbar/Toolbar.react';
1111

1212
import styles from './Playground.scss';
1313

14+
const placeholderCode = "const myObj = new Parse.Object('MyClass');\nmyObj.set('myField', 'Hello World!');\nawait myObj.save();\nconsole.log(myObj);";
1415
export default class Playground extends Component {
1516
constructor() {
1617
super();
1718
this.section = 'API';
1819
this.subsection = 'JS Console';
1920
this.localKey = 'parse-dashboard-playground-code';
2021
this.state = {
22+
code: '',
2123
results: [],
2224
running: false,
2325
saving: false,
@@ -90,7 +92,7 @@ export default class Playground extends Component {
9092
}
9193
})()`;
9294

93-
this.setState({ running: true, results: [] });
95+
this.setState({ running: true, results: [], code: originalCode });
9496

9597
await new Function('Parse', finalCode)(Parse);
9698
} catch (e) {
@@ -109,6 +111,7 @@ export default class Playground extends Component {
109111

110112
window.localStorage.setItem(this.localKey, code);
111113
this.setState({
114+
code,
112115
saving: false,
113116
savingState: SaveButton.States.SUCCEEDED
114117
});
@@ -134,9 +137,14 @@ export default class Playground extends Component {
134137
componentDidMount() {
135138
if (window.localStorage) {
136139
const initialCode = window.localStorage.getItem(this.localKey);
140+
let code = '';
137141
if (initialCode) {
138-
this.editor.value = initialCode;
142+
code = initialCode;
143+
} else {
144+
code = placeholderCode;
139145
}
146+
this.editor.value = code;
147+
this.setState({ code });
140148
}
141149
}
142150

@@ -148,10 +156,7 @@ export default class Playground extends Component {
148156
<Toolbar section={this.section} subsection={this.subsection} />
149157
<div style={{ height: 'calc(100vh - 96px)' }}>
150158
<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}
155160
ref={editor => (this.editor = editor)}
156161
/>
157162
<div className={styles['console-ctn']}>

0 commit comments

Comments
 (0)