Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
davidagustin committed Dec 26, 2018
1 parent 8e011e5 commit 4a9256b
Show file tree
Hide file tree
Showing 8 changed files with 442 additions and 139 deletions.
286 changes: 194 additions & 92 deletions .idea/workspace.xml

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions client/src/components/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';
import $ from 'jquery';

export default class App extends React.Component {
constructor(props) {
super(props);

this.state = {
text: '',
update: 'text will change if button works',
};

this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}

componentDidMount() {
$.get('/text');
}

handleChange(e) {
let newState = {};
newState[e.target.name] = e.target.value;
this.setState(newState);
}

handleSubmit(e) {
e.preventDefault();
console.log('handleSubmit fires');

let data = {
text: this.state.text
};
fetch('/text', {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
body: JSON.stringify(data)
});
}


render() {
return (
<div>
<h1>Reviews</h1>
<form onSubmit={this.handleSubmit}>
<label> Text
<input name="text" value={this.state.text} onChange={this.handleChange}/>
</label>
<button>Submit</button>
</form>
</div>
);
}

}

6 changes: 6 additions & 0 deletions client/src/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';

import App from './components/App.jsx';

ReactDOM.render(<App />, document.getElementById('app'));
Loading

0 comments on commit 4a9256b

Please sign in to comment.