From b6eca6485d69b56f9085c0344b9f836d932b0d3f Mon Sep 17 00:00:00 2001 From: Ashinze Ekene Date: Sun, 2 Sep 2018 16:57:00 +0100 Subject: [PATCH] Improved verbosity of `check` & `star` options. Fixes #27. (#51) * 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 --- lib/render.js | 24 ++++++++++++++++++++++++ lib/taskbook.js | 10 ++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/render.js b/lib/render.js index 628576df..7bcb761e 100644 --- a/lib/render.js +++ b/lib/render.js @@ -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'; diff --git a/lib/taskbook.js b/lib/taskbook.js index 69988722..8234fd25 100644 --- a/lib/taskbook.js +++ b/lib/taskbook.js @@ -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) { @@ -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) {