mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
Refactor tag removing methods (duplicated code)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user