Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit 4e19441

Browse files
tabcataphelionz
authored andcommitted
fix Clear completed
1 parent 49edf8a commit 4e19441

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/app.jsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,18 @@ var app = app || {};
9292
var main;
9393
var todos = this.props.model.todos;
9494

95-
var shownTodos = todos.filter(function (todo) {
96-
switch (this.state.nowShowing) {
97-
case app.ACTIVE_TODOS:
98-
return !todo.completed;
99-
case app.COMPLETED_TODOS:
100-
return todo.completed;
101-
default:
102-
return true;
103-
}
104-
}, this);
95+
var shownTodos = todos
96+
.filter(todo => !todo.cleared)
97+
.filter(function (todo) {
98+
switch (this.state.nowShowing) {
99+
case app.ACTIVE_TODOS:
100+
return !todo.completed;
101+
case app.COMPLETED_TODOS:
102+
return todo.completed;
103+
default:
104+
return true;
105+
}
106+
}, this);
105107

106108
var todoItems = shownTodos.map(function (todo) {
107109
return (

src/todoModel.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ var app = app || {};
5252
const newTodo = {
5353
id: Utils.uuid(),
5454
title: title,
55-
completed: false
55+
completed: false,
56+
cleared: false,
5657
}
5758
await Utils.store(this.db, this.key, newTodo);
5859
this.inform();
@@ -83,10 +84,13 @@ var app = app || {};
8384
this.inform();
8485
};
8586

86-
app.TodoModel.prototype.clearCompleted = function () {
87-
this.todos = this.todos.filter(function (todo) {
88-
return !todo.completed;
89-
});
87+
app.TodoModel.prototype.clearCompleted = async function () {
88+
for (let todo of this.todos) {
89+
if (todo.completed) {
90+
const updatedTodo = Utils.extend({}, todo, {cleared: true});
91+
await Utils.store(this.db, this.key, updatedTodo);
92+
}
93+
}
9094
this.inform();
9195
};
9296

0 commit comments

Comments
 (0)