-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathtodoFooter.js
65 lines (57 loc) · 1.6 KB
/
todoFooter.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
import React from 'react';
import PropTypes from 'prop-types';
import {observer} from 'mobx-react';
import {makeObservable, action} from 'mobx';
import {pluralize} from '../utils';
import { ALL_TODOS, ACTIVE_TODOS, COMPLETED_TODOS } from '../constants';
class TodoFooter extends React.Component {
constructor(props) {
super(props);
makeObservable(this, {
clearCompleted: action.bound
});
}
render() {
const todoStore = this.props.todoStore;
if (!todoStore.activeTodoCount && !todoStore.completedCount)
return null;
const activeTodoWord = pluralize(todoStore.activeTodoCount, 'item');
return (
<footer className="footer">
<span className="todo-count">
<strong>{todoStore.activeTodoCount}</strong> {activeTodoWord} left
</span>
<ul className="filters">
{this.renderFilterLink(ALL_TODOS, "", "All")}
{this.renderFilterLink(ACTIVE_TODOS, "active", "Active")}
{this.renderFilterLink(COMPLETED_TODOS, "completed", "Completed")}
</ul>
{ todoStore.completedCount === 0
? null
: <button
className="clear-completed"
onClick={this.clearCompleted}>
Clear completed
</button>
}
</footer>
);
}
renderFilterLink(filterName, url, caption) {
return (<li>
<a href={"#/" + url}
className={filterName === this.props.viewStore.todoFilter ? "selected" : ""}>
{caption}
</a>
{' '}
</li>)
}
clearCompleted = () => {
this.props.todoStore.clearCompleted();
};
}
TodoFooter.propTypes = {
viewStore: PropTypes.object.isRequired,
todoStore: PropTypes.object.isRequired
}
export default observer(TodoFooter);