From a6af5de3e1044b7fedddce26fe00b0a5b6bcb21d Mon Sep 17 00:00:00 2001 From: bimlas Date: Fri, 18 May 2018 15:18:28 +0200 Subject: [PATCH] Refactor tag removing methods (duplicated code) --- browser/main/Detail/TagSelect.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/browser/main/Detail/TagSelect.js b/browser/main/Detail/TagSelect.js index ce0b4f79..d14c7a8c 100644 --- a/browser/main/Detail/TagSelect.js +++ b/browser/main/Detail/TagSelect.js @@ -44,16 +44,9 @@ class TagSelect extends React.Component { } removeLastTag () { - let { value } = this.props - - value = _.isArray(value) - ? value.slice() - : [] - value.pop() - value = _.uniq(value) - - this.value = value - this.props.onChange() + this.removeTagByCallback((value) => { + value.pop() + }) } reset () { @@ -96,12 +89,18 @@ class TagSelect extends React.Component { } handleTagRemoveButtonClick (tag) { + this.removeTagByCallback((value, tag) => { + value.splice(value.indexOf(tag), 1) + }, tag) + } + + removeTagByCallback (callback, tag = null) { let { value } = this.props value = _.isArray(value) ? value.slice() : [] - value.splice(value.indexOf(tag), 1) + callback(value, tag) value = _.uniq(value) this.value = value