converting to object todos

This commit is contained in:
Micah Godbolt
2019-02-14 14:37:02 -08:00
parent 41a79e8883
commit ffc96d555e
13 changed files with 178 additions and 148 deletions

View File

@@ -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: '' });
};
}