mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
converting to object todos
This commit is contained in:
@@ -1,21 +1,45 @@
|
||||
import React from "react";
|
||||
import React from 'react';
|
||||
|
||||
export class TodoHeader extends React.Component<any, any> {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { labelInput: '' };
|
||||
}
|
||||
|
||||
render() {
|
||||
const { filter, inputValue, onInputChange, onTodoSubmit, onFilterClick } = this.props;
|
||||
const { filter } = this.props;
|
||||
return (
|
||||
<div>
|
||||
<h1>todos</h1>
|
||||
<input value={inputValue} onChange={onInputChange} className="textfield" />
|
||||
<button onClick={onTodoSubmit} className="button add">Add</button>
|
||||
<input value={this.state.labelInput} onChange={this._onChange} className="textfield" />
|
||||
<button onClick={this._onAdd} className="button add">
|
||||
Add
|
||||
</button>
|
||||
<div className="filter">
|
||||
<button onClick={() => onFilterClick('all')} className={filter == "all" ? "active" : ""}>all</button>
|
||||
<button onClick={() => onFilterClick('active')} className={filter == "active" ? "active" : ""}>active</button>
|
||||
<button onClick={() => onFilterClick('completed')} className={filter == "completed" ? "active" : ""}>
|
||||
<button onClick={() => this._onFilter('all')} className={filter == 'all' ? 'active' : ''}>
|
||||
all
|
||||
</button>
|
||||
<button onClick={() => this._onFilter('active')} className={filter == 'active' ? 'active' : ''}>
|
||||
active
|
||||
</button>
|
||||
<button onClick={() => this._onFilter('completed')} className={filter == 'completed' ? 'active' : ''}>
|
||||
completed
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
_onFilter = filter => {
|
||||
this.props.setFilter(filter);
|
||||
};
|
||||
|
||||
_onChange = evt => {
|
||||
this.setState({ labelInput: evt.target.value });
|
||||
};
|
||||
|
||||
_onAdd = () => {
|
||||
this.props.addTodo(this.state.labelInput);
|
||||
this.setState({ labelInput: '' });
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user