Handle empty include/exclude arrays

nolan/hinaloe-test
Etienne Lemay 2017-04-24 03:03:12 +02:00
parent 357653bb37
commit 2c35d5a8a8
2 changed files with 6 additions and 6 deletions

View File

@ -56,8 +56,8 @@ export default class Picker extends React.Component {
} }
for (let category of data.categories) { for (let category of data.categories) {
let isIncluded = props.include == undefined ? true : props.include.indexOf(category.name.toLowerCase()) > -1 let isIncluded = props.include && props.include.length ? props.include.indexOf(category.name.toLowerCase()) > -1 : true
let isExcluded = props.exclude == undefined ? false : props.exclude.indexOf(category.name.toLowerCase()) > -1 let isExcluded = props.exclude && props.exclude.length ? props.exclude.indexOf(category.name.toLowerCase()) > -1 : false
if (!isIncluded || isExcluded) { continue } if (!isIncluded || isExcluded) { continue }
if (props.emojisToShowFilter) { if (props.emojisToShowFilter) {
@ -84,8 +84,8 @@ export default class Picker extends React.Component {
} }
} }
let includeRecent = props.include == undefined ? true : props.include.indexOf('recent') > -1 let includeRecent = props.include && props.include.length ? props.include.indexOf('recent') > -1 : true
let excludeRecent = props.exclude == undefined ? false : props.exclude.indexOf('recent') > -1 let excludeRecent = props.exclude && props.exclude.length ? props.exclude.indexOf('recent') > -1 : false
if (includeRecent && !excludeRecent) { if (includeRecent && !excludeRecent) {
this.categories.unshift(RECENT_CATEGORY) this.categories.unshift(RECENT_CATEGORY)
} }

View File

@ -39,8 +39,8 @@ function search(value, { emojisToShowFilter, maxResults, include, exclude } = {}
pool = {} pool = {}
for (let category of data.categories) { for (let category of data.categories) {
let isIncluded = include == undefined ? true : include.indexOf(category.name.toLowerCase()) > -1 let isIncluded = include && include.length ? include.indexOf(category.name.toLowerCase()) > -1 : true
let isExcluded = exclude == undefined ? false : exclude.indexOf(category.name.toLowerCase()) > -1 let isExcluded = exclude && exclude.length ? exclude.indexOf(category.name.toLowerCase()) > -1 : false
if (!isIncluded || isExcluded) { continue } if (!isIncluded || isExcluded) { continue }
for (let emojiId of category.emojis) { for (let emojiId of category.emojis) {