|
|
@ -7,9 +7,7 @@ const ToDo = props => ( |
|
|
|
<input /> |
|
|
|
</td> |
|
|
|
<td> |
|
|
|
<label> |
|
|
|
{props.createdAt.toTimeString()} |
|
|
|
</label> |
|
|
|
<label>{props.createdAt.toTimeString()}</label> |
|
|
|
</td> |
|
|
|
</tr> |
|
|
|
); |
|
|
@ -31,26 +29,18 @@ class ToDoList extends React.Component { |
|
|
|
} |
|
|
|
|
|
|
|
sortByEarliest() { |
|
|
|
const sortedList = this.state.list.sort( |
|
|
|
(a, b) => { |
|
|
|
return ( |
|
|
|
a.createdAt - b.createdAt |
|
|
|
); |
|
|
|
} |
|
|
|
); |
|
|
|
const sortedList = this.state.list.sort((a, b) => { |
|
|
|
return a.createdAt - b.createdAt; |
|
|
|
}); |
|
|
|
this.setState({ |
|
|
|
list: [...sortedList], |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
sortByLatest() { |
|
|
|
const sortedList = this.state.list.sort( |
|
|
|
(a, b) => { |
|
|
|
return ( |
|
|
|
b.createdAt - a.createdAt |
|
|
|
); |
|
|
|
} |
|
|
|
); |
|
|
|
const sortedList = this.state.list.sort((a, b) => { |
|
|
|
return b.createdAt - a.createdAt; |
|
|
|
}); |
|
|
|
this.setState({ |
|
|
|
list: [...sortedList], |
|
|
|
}); |
|
|
@ -58,8 +48,7 @@ class ToDoList extends React.Component { |
|
|
|
|
|
|
|
addToEnd() { |
|
|
|
const date = new Date(); |
|
|
|
const nextId = |
|
|
|
this.state.toDoCounter + 1; |
|
|
|
const nextId = this.state.toDoCounter + 1; |
|
|
|
const newList = [ |
|
|
|
...this.state.list, |
|
|
|
{id: nextId, createdAt: date}, |
|
|
@ -72,8 +61,7 @@ class ToDoList extends React.Component { |
|
|
|
|
|
|
|
addToStart() { |
|
|
|
const date = new Date(); |
|
|
|
const nextId = |
|
|
|
this.state.toDoCounter + 1; |
|
|
|
const nextId = this.state.toDoCounter + 1; |
|
|
|
const newList = [ |
|
|
|
{id: nextId, createdAt: date}, |
|
|
|
...this.state.list, |
|
|
@ -89,28 +77,16 @@ class ToDoList extends React.Component { |
|
|
|
<div> |
|
|
|
<code>key=id</code> |
|
|
|
<br /> |
|
|
|
<button |
|
|
|
onClick={this.addToStart.bind( |
|
|
|
this |
|
|
|
)}> |
|
|
|
<button onClick={this.addToStart.bind(this)}> |
|
|
|
Add New to Start |
|
|
|
</button> |
|
|
|
<button |
|
|
|
onClick={this.addToEnd.bind( |
|
|
|
this |
|
|
|
)}> |
|
|
|
<button onClick={this.addToEnd.bind(this)}> |
|
|
|
Add New to End |
|
|
|
</button> |
|
|
|
<button |
|
|
|
onClick={this.sortByEarliest.bind( |
|
|
|
this |
|
|
|
)}> |
|
|
|
<button onClick={this.sortByEarliest.bind(this)}> |
|
|
|
Sort by Earliest |
|
|
|
</button> |
|
|
|
<button |
|
|
|
onClick={this.sortByLatest.bind( |
|
|
|
this |
|
|
|
)}> |
|
|
|
<button onClick={this.sortByLatest.bind(this)}> |
|
|
|
Sort by Latest |
|
|
|
</button> |
|
|
|
<table> |
|
|
@ -119,14 +95,9 @@ class ToDoList extends React.Component { |
|
|
|
<th /> |
|
|
|
<th>created at</th> |
|
|
|
</tr> |
|
|
|
{this.state.list.map( |
|
|
|
(todo, index) => ( |
|
|
|
<ToDo |
|
|
|
key={todo.id} |
|
|
|
{...todo} |
|
|
|
/> |
|
|
|
) |
|
|
|
)} |
|
|
|
{this.state.list.map((todo, index) => ( |
|
|
|
<ToDo key={todo.id} {...todo} /> |
|
|
|
))} |
|
|
|
</table> |
|
|
|
</div> |
|
|
|
); |
|
|
|