-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
62 lines (48 loc) · 1.36 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React from 'react';
import ReactDOM from 'react-dom';
import PersonList from './components/PersonList.jsx';
import PersonDetail from './components/PersonDetails.jsx';
const App = React.createClass({
getInitialState: function() {
return {
persons: [
{ name: 'Esa', desc: 'kova ukko' },
{ name: 'Kaija', desc: 'vielä kovempi' }
],
activePerson: {}
};
},
render: function() {
return <div className="site__wrapper">
<PersonList persons={this.state.persons}
handlePersonChange={(person) =>
this.setState({
activePerson:person
})}
handlePersonAdd={(e) => {
var name = prompt('Name'),
desc = prompt('Description'),
persons = this.state.persons;
if (name) {
persons.push({name:name, desc:desc})
this.setState({
persons:persons
})
}}
}/>
<PersonDetail
model={this.state.activePerson}
handleDetailAdd={newDetail => {
console.log(this.state.activePerson, newDetail);
if (!this.state.activePerson.name) {
console.log('no active person selected');
return;
}
this.state.activePerson.detailsList = this.state.activePerson.details || [];
this.state.activePerson.detailsList.push(newDetail);
this.setState({ activePerson });
}} />
</div>;
}
});
ReactDOM.render(<App />, document.getElementById('root'));