-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
74 lines (46 loc) · 1.65 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
63
64
65
66
67
68
69
70
71
72
73
74
import React, { Component } from 'react';
import Note from './Note'
import ListNotes from './ListNotes'
import './App.css';
const notesArray= [{id: 1, heading:'Note Uno', value:'This is a note'},
{id: 2, heading:'Note Dos', value:'This is another note'},
{id: 3, heading:'Note Tres', value:'This is the third note'}]
class App extends Component {
state = {
currentNote: null,
notes: notesArray
}
changeCurrentNote = (note) =>{
this.setState({ currentNote: note })
}
deletenote = (note) =>{
this.setState((state) => ({ notes: state.notes.filter(noteIterator => (noteIterator.id !== note.id)) }))
this.setState({ currentNote: null })
}
saveNote = (note) =>{
this.setState((state) => { state.notes.concat([note]) })
this.setState({ currentNote: note })
}
addNew = () =>{
const note = {id: this.state.notes.length + 1, heading: '', value: ' '}
this.setState((state) => ({ notes: state.notes.concat([note]) }))
this.setState({ currentNote: note })
}
render() {
this.state.notes.sort((a, b) => {return b.id-a.id})
return (
<div className="App">
<button className='add-note' onClick={this.addNew}>+</button>
<div className='notes-wrapper'>
<div className='list-notes-top'>
<ListNotes notes={this.state.notes} changeCurrentNote={this.changeCurrentNote} deletenote={this.deletenote}/>
</div>
<div className='current-note'>
{( this.state.currentNote !== null ) && ( <Note note={this.state.currentNote} savenote={this.saveNote}/> )}
</div>
</div>
</div>
);
}
}
export default App;