From 2c35d5a8a85f3beb0bbeb79c6df92f9ef69c8449 Mon Sep 17 00:00:00 2001 From: Etienne Lemay Date: Mon, 24 Apr 2017 03:03:12 +0200 Subject: [PATCH] Handle empty include/exclude arrays --- src/components/picker.js | 8 ++++---- src/utils/emoji-index.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/picker.js b/src/components/picker.js index 2a82e03..6ae18e4 100644 --- a/src/components/picker.js +++ b/src/components/picker.js @@ -56,8 +56,8 @@ export default class Picker extends React.Component { } for (let category of data.categories) { - let isIncluded = props.include == undefined ? true : props.include.indexOf(category.name.toLowerCase()) > -1 - let isExcluded = props.exclude == undefined ? false : props.exclude.indexOf(category.name.toLowerCase()) > -1 + let isIncluded = props.include && props.include.length ? props.include.indexOf(category.name.toLowerCase()) > -1 : true + let isExcluded = props.exclude && props.exclude.length ? props.exclude.indexOf(category.name.toLowerCase()) > -1 : false if (!isIncluded || isExcluded) { continue } 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 excludeRecent = props.exclude == undefined ? false : props.exclude.indexOf('recent') > -1 + let includeRecent = props.include && props.include.length ? props.include.indexOf('recent') > -1 : true + let excludeRecent = props.exclude && props.exclude.length ? props.exclude.indexOf('recent') > -1 : false if (includeRecent && !excludeRecent) { this.categories.unshift(RECENT_CATEGORY) } diff --git a/src/utils/emoji-index.js b/src/utils/emoji-index.js index 7f48063..d50c288 100644 --- a/src/utils/emoji-index.js +++ b/src/utils/emoji-index.js @@ -39,8 +39,8 @@ function search(value, { emojisToShowFilter, maxResults, include, exclude } = {} pool = {} for (let category of data.categories) { - let isIncluded = include == undefined ? true : include.indexOf(category.name.toLowerCase()) > -1 - let isExcluded = exclude == undefined ? false : exclude.indexOf(category.name.toLowerCase()) > -1 + let isIncluded = include && include.length ? include.indexOf(category.name.toLowerCase()) > -1 : true + let isExcluded = exclude && exclude.length ? exclude.indexOf(category.name.toLowerCase()) > -1 : false if (!isIncluded || isExcluded) { continue } for (let emojiId of category.emojis) {