From d50b2db02e51927d6ba06da86703fae6c0192443 Mon Sep 17 00:00:00 2001 From: ashinzekene Date: Sat, 4 Aug 2018 05:51:06 +0100 Subject: [PATCH 1/6] proper messages for unstarring and unchecking --- lib/render.js | 12 ++++++++++++ lib/taskbook.js | 12 ++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/render.js b/lib/render.js index ef1f7d0b..a9f7d1f5 100644 --- a/lib/render.js +++ b/lib/render.js @@ -218,12 +218,24 @@ class Render { success({prefix, message, suffix}); } + markIncomplete(ids) { + const [prefix, suffix] = ['\n', grey(ids.join(', '))]; + const message = `Unchecked ${ids.length > 1 ? 'tasks' : 'task'}:`; + success({prefix, message, suffix}); + } + markStarred(ids) { const [prefix, suffix] = ['\n', grey(ids.join(', '))]; const message = `Starred ${ids.length > 1 ? 'items' : 'item'}:`; success({prefix, message, suffix}); } + markUnstarred(ids) { + 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 7ea54971..eaf21471 100644 --- a/lib/taskbook.js +++ b/lib/taskbook.js @@ -307,13 +307,17 @@ class Taskbook { checkTasks(ids) { ids = this._validateIDs(ids); const {_data} = this; + let checked = [] + let unChecked = [] ids.forEach(id => { + _data[id].isComplete ? checked.push(id) : unChecked.push(id); _data[id].isComplete = !_data[id].isComplete; }); this._save(_data); - render.markComplete(ids); + checked.length && render.markIncomplete(checked); + unChecked.length && render.markComplete(unChecked); } createTask(desc) { @@ -462,13 +466,17 @@ class Taskbook { starItems(ids) { ids = this._validateIDs(ids); const {_data} = this; + let starred = [] + let unStarred = [] ids.forEach(id => { + _data[id].isStarred ? starred.push(id) : unStarred.push(id); _data[id].isStarred = !_data[id].isStarred; }); this._save(_data); - render.markStarred(ids); + unStarred.length && render.markStarred(unStarred); + starred.length && render.markUnstarred(starred); } updatePriority(input) { From ff1b2afae5b4e913328ce604e63d36e98a061f14 Mon Sep 17 00:00:00 2001 From: ashinzekene Date: Sat, 4 Aug 2018 06:01:35 +0100 Subject: [PATCH 2/6] fixed linting errors --- lib/taskbook.js | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/taskbook.js b/lib/taskbook.js index eaf21471..6239c437 100644 --- a/lib/taskbook.js +++ b/lib/taskbook.js @@ -307,17 +307,25 @@ class Taskbook { checkTasks(ids) { ids = this._validateIDs(ids); const {_data} = this; - let checked = [] - let unChecked = [] + const checked = []; + const unChecked = []; ids.forEach(id => { - _data[id].isComplete ? checked.push(id) : unChecked.push(id); + if (_data[id].isComplete) { + checked.push(id); + } else { + unChecked.push(id); + } _data[id].isComplete = !_data[id].isComplete; }); this._save(_data); - checked.length && render.markIncomplete(checked); - unChecked.length && render.markComplete(unChecked); + if (checked.length > 0) { + render.markIncomplete(checked); + } + if (unChecked.length > 0) { + render.markComplete(unChecked); + } } createTask(desc) { @@ -466,17 +474,25 @@ class Taskbook { starItems(ids) { ids = this._validateIDs(ids); const {_data} = this; - let starred = [] - let unStarred = [] + const starred = []; + const unStarred = []; ids.forEach(id => { - _data[id].isStarred ? starred.push(id) : unStarred.push(id); + if (_data[id].isStarred) { + starred.push(id); + } else { + unStarred.push(id); + } _data[id].isStarred = !_data[id].isStarred; }); this._save(_data); - unStarred.length && render.markStarred(unStarred); - starred.length && render.markUnstarred(starred); + if (unStarred.length > 0) { + render.markStarred(unStarred); + } + if (starred.length > 0) { + render.markUnstarred(starred); + } } updatePriority(input) { From f6925467c120593f79ee0d5ba3acf8ab6099c87e Mon Sep 17 00:00:00 2001 From: ashinzekene Date: Mon, 20 Aug 2018 00:31:09 +0100 Subject: [PATCH 3/6] resolved some issues --- lib/taskbook.js | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/lib/taskbook.js b/lib/taskbook.js index 6239c437..0b1c21ef 100644 --- a/lib/taskbook.js +++ b/lib/taskbook.js @@ -307,8 +307,7 @@ class Taskbook { checkTasks(ids) { ids = this._validateIDs(ids); const {_data} = this; - const checked = []; - const unChecked = []; + const [checked, unChecked] = [[], []]; ids.forEach(id => { if (_data[id].isComplete) { @@ -320,12 +319,8 @@ class Taskbook { }); this._save(_data); - if (checked.length > 0) { - render.markIncomplete(checked); - } - if (unChecked.length > 0) { - render.markComplete(unChecked); - } + render.markIncomplete(checked); + render.markComplete(unChecked); } createTask(desc) { @@ -474,8 +469,7 @@ class Taskbook { starItems(ids) { ids = this._validateIDs(ids); const {_data} = this; - const starred = []; - const unStarred = []; + const [starred, unStarred] = [[], []]; ids.forEach(id => { if (_data[id].isStarred) { @@ -487,12 +481,8 @@ class Taskbook { }); this._save(_data); - if (unStarred.length > 0) { - render.markStarred(unStarred); - } - if (starred.length > 0) { - render.markUnstarred(starred); - } + render.markStarred(unStarred); + render.markUnstarred(starred); } updatePriority(input) { From abfbb8f83edb622a960bd210b9ed18989df76760 Mon Sep 17 00:00:00 2001 From: ashinzekene Date: Wed, 29 Aug 2018 09:49:33 +0100 Subject: [PATCH 4/6] used ternary in for loop --- lib/taskbook.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/taskbook.js b/lib/taskbook.js index 0b1c21ef..ded3dbf5 100644 --- a/lib/taskbook.js +++ b/lib/taskbook.js @@ -310,12 +310,8 @@ class Taskbook { const [checked, unChecked] = [[], []]; ids.forEach(id => { - if (_data[id].isComplete) { - checked.push(id); - } else { - unChecked.push(id); - } _data[id].isComplete = !_data[id].isComplete; + return _data[id].isComplete ? unChecked.push(id) : checked.push(id); }); this._save(_data); @@ -472,12 +468,8 @@ class Taskbook { const [starred, unStarred] = [[], []]; ids.forEach(id => { - if (_data[id].isStarred) { - starred.push(id); - } else { - unStarred.push(id); - } _data[id].isStarred = !_data[id].isStarred; + return _data[id].isStarred ? unStarred.push(id) : starred.push(id); }); this._save(_data); From 03f383e57ba019288e6b077964fa4099b537015d Mon Sep 17 00:00:00 2001 From: ashinzekene Date: Wed, 29 Aug 2018 09:59:37 +0100 Subject: [PATCH 5/6] added checks for empty id ary for markIncomplete, markComplete, markStarred & markUnstarred methods. --- lib/render.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/render.js b/lib/render.js index a9f7d1f5..9fe42843 100644 --- a/lib/render.js +++ b/lib/render.js @@ -213,24 +213,36 @@ 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}); From 01367681ae6e0c2229970e24a4958fa4cfc74a45 Mon Sep 17 00:00:00 2001 From: ashinzekene Date: Sun, 2 Sep 2018 01:43:15 +0100 Subject: [PATCH 6/6] fixed ordering of checked and unchecked items --- lib/taskbook.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/taskbook.js b/lib/taskbook.js index ded3dbf5..83176b61 100644 --- a/lib/taskbook.js +++ b/lib/taskbook.js @@ -307,16 +307,16 @@ class Taskbook { checkTasks(ids) { ids = this._validateIDs(ids); const {_data} = this; - const [checked, unChecked] = [[], []]; + const [checked, unchecked] = [[], []]; ids.forEach(id => { _data[id].isComplete = !_data[id].isComplete; - return _data[id].isComplete ? unChecked.push(id) : checked.push(id); + return _data[id].isComplete ? checked.push(id) : unchecked.push(id); }); this._save(_data); - render.markIncomplete(checked); - render.markComplete(unChecked); + render.markComplete(checked); + render.markIncomplete(unchecked); } createTask(desc) { @@ -465,16 +465,16 @@ class Taskbook { starItems(ids) { ids = this._validateIDs(ids); const {_data} = this; - const [starred, unStarred] = [[], []]; + const [starred, unstarred] = [[], []]; ids.forEach(id => { _data[id].isStarred = !_data[id].isStarred; - return _data[id].isStarred ? unStarred.push(id) : starred.push(id); + return _data[id].isStarred ? starred.push(id) : unstarred.push(id); }); this._save(_data); - render.markStarred(unStarred); - render.markUnstarred(starred); + render.markStarred(starred); + render.markUnstarred(unstarred); } updatePriority(input) {