Skip to content

Commit 1e8097b

Browse files
authored
Fix "user not able to modify code" bug (#3)
1 parent 7bd731e commit 1e8097b

File tree

1 file changed

+10
-27
lines changed
  • DotNetSyntaxTreeVisualizer/ClientApp/src/components

1 file changed

+10
-27
lines changed

DotNetSyntaxTreeVisualizer/ClientApp/src/components/Home.js

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
11
import React, { Component } from 'react';
22
import Tree from 'react-d3-tree';
33

4-
const myTreeData =
5-
{
6-
name: 'Top Level Root',
7-
attributes: {
8-
keyA: 'val A',
9-
keyB: 'val B',
10-
keyC: 'val C',
11-
},
12-
children: [
13-
{
14-
name: 'Level 2: A',
15-
attributes: {
16-
keyA: 'val A',
17-
keyB: 'val B',
18-
keyC: 'val C',
19-
},
20-
},
21-
{
22-
name: 'Level 2: B',
23-
},
24-
],
25-
}
26-
274
const svgSquare = {
285
shape: 'rect',
296
shapeProps: {
@@ -39,13 +16,14 @@ const containerStyles = {
3916
height: '100vh',
4017
}
4118

19+
const helloWorldCode = 'using System;\r\n\r\npublic class Program\r\n{\r\n public static void Main(string[] args)\r\n {\r\n Console.WriteLine("Hello, world");\r\n }\r\n}'
4220

4321
export class Home extends Component {
4422
static displayName = Home.name;
4523

4624
state = {
4725
treeJson: {},
48-
sourceCodeText: 'using System;\r\n\r\npublic class Program\r\n{\r\n public static void Main(string[] args)\r\n {\r\n Console.WriteLine("Hello, world");\r\n }\r\n}'
26+
sourceCodeText: helloWorldCode
4927
};
5028

5129
componentDidMount() {
@@ -56,13 +34,18 @@ export class Home extends Component {
5634
y: dimensions.height / 2
5735
}
5836
});
37+
this.handleChanged({
38+
target: {
39+
value: helloWorldCode
40+
}
41+
});
5942
}
6043

61-
handleChanged = () => {
44+
handleChanged = (event) => {
6245
const requestOptions = {
6346
method: 'POST',
6447
headers: { 'Content-Type': 'text/plain;charset=UTF-8' },
65-
body: this.state.sourceCodeText
48+
body: event.target.value
6649
};
6750
fetch('SyntaxTree', requestOptions)
6851
.then(response => response.json())
@@ -72,7 +55,7 @@ export class Home extends Component {
7255
render() {
7356
return (
7457
<React.Fragment>
75-
<textarea value={this.state.sourceCodeText} onChange={this.handleChanged} style={{ width: '100%' }} />
58+
<textarea defaultValue={helloWorldCode} onChange={this.handleChanged} style={{ height: '230px', width: '100%' }} />
7659
<div id="treeWrapper" style={containerStyles} ref={tc => (this.treeContainer = tc)}>
7760
<Tree data={this.state.treeJson} nodeSvgShape={svgSquare} orientation="vertical" translate={this.state.translate} />
7861
</div>

0 commit comments

Comments
 (0)