Skip to content

Commit

Permalink
Improved verbosity of check & star options. Fixes #27. (#51)
Browse files Browse the repository at this point in the history
* proper messages for unstarring and unchecking

* fixed linting errors

* resolved some issues

* used ternary in for loop

* added checks for empty id ary  for markIncomplete, markComplete, markStarred & markUnstarred methods.

* fixed ordering of checked and unchecked items
  • Loading branch information
ashinzekene authored and klaudiosinani committed Sep 2, 2018
1 parent b80d739 commit b6eca64
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
24 changes: 24 additions & 0 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,41 @@ class Render {
}

markComplete(ids) {
if (ids.length === 0) {
return;
}
const [prefix, suffix] = ['\n', grey(ids.join(', '))];
const message = `Checked ${ids.length > 1 ? 'tasks' : 'task'}:`;
success({prefix, message, suffix});
}

markIncomplete(ids) {
if (ids.length === 0) {
return;
}
const [prefix, suffix] = ['\n', grey(ids.join(', '))];
const message = `Unchecked ${ids.length > 1 ? 'tasks' : 'task'}:`;
success({prefix, message, suffix});
}

markStarred(ids) {
if (ids.length === 0) {
return;
}
const [prefix, suffix] = ['\n', grey(ids.join(', '))];
const message = `Starred ${ids.length > 1 ? 'items' : 'item'}:`;
success({prefix, message, suffix});
}

markUnstarred(ids) {
if (ids.length === 0) {
return;
}
const [prefix, suffix] = ['\n', grey(ids.join(', '))];
const message = `Unstarred ${ids.length > 1 ? 'items' : 'item'}:`;
success({prefix, message, suffix});
}

missingBoards() {
const prefix = '\n';
const message = 'No boards were given as input';
Expand Down
10 changes: 8 additions & 2 deletions lib/taskbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,16 @@ class Taskbook {
checkTasks(ids) {
ids = this._validateIDs(ids);
const {_data} = this;
const [checked, unchecked] = [[], []];

ids.forEach(id => {
_data[id].isComplete = !_data[id].isComplete;
return _data[id].isComplete ? checked.push(id) : unchecked.push(id);
});

this._save(_data);
render.markComplete(ids);
render.markComplete(checked);
render.markIncomplete(unchecked);
}

createTask(desc) {
Expand Down Expand Up @@ -465,13 +468,16 @@ class Taskbook {
starItems(ids) {
ids = this._validateIDs(ids);
const {_data} = this;
const [starred, unstarred] = [[], []];

ids.forEach(id => {
_data[id].isStarred = !_data[id].isStarred;
return _data[id].isStarred ? starred.push(id) : unstarred.push(id);
});

this._save(_data);
render.markStarred(ids);
render.markStarred(starred);
render.markUnstarred(unstarred);
}

updatePriority(input) {
Expand Down

0 comments on commit b6eca64

Please sign in to comment.