Don’t call useless `emojisToShowFilter` when undefined

release
Etienne Lemay 2017-04-18 10:22:32 -04:00
parent 046d489d7f
commit 4a9497df0e
3 changed files with 26 additions and 21 deletions

View File

@ -59,6 +59,7 @@ export default class Picker extends React.Component {
let isExcluded = props.exclude == undefined ? false : props.exclude.indexOf(category.name.toLowerCase()) > -1
if (!isIncluded || isExcluded) { continue }
if (props.emojisToShowFilter) {
let newEmojis = []
for (let emoji of category.emojis) {
@ -77,6 +78,9 @@ export default class Picker extends React.Component {
this.categories.push(newCategory)
}
} else {
this.categories.push(category)
}
}
let includeRecent = props.include == undefined ? true : props.include.indexOf('recent') > -1
@ -395,6 +399,6 @@ Picker.defaultProps = {
native: Emoji.defaultProps.native,
sheetSize: Emoji.defaultProps.sheetSize,
backgroundImageFn: Emoji.defaultProps.backgroundImageFn,
emojisToShowFilter: (codePoint) => true,
emojisToShowFilter: null,
autoFocus: false,
}

View File

@ -37,6 +37,6 @@ Search.propTypes = {
Search.defaultProps = {
onSearch: (() => {}),
maxResults: 75,
emojisToShowFilter: () => true,
emojisToShowFilter: null,
autoFocus: false,
}

View File

@ -92,16 +92,17 @@ function search(value, emojisToShowFilter = () => true, maxResults = 75) {
}
}
let filteredResults = null
if (results) {
filteredResults = results.filter((result) => emojisToShowFilter(data.emojis[result.id].unified))
if (filteredResults && filteredResults.length) {
filteredResults = filteredResults.slice(0, maxResults)
if (emojisToShowFilter) {
results = results.filter((result) => emojisToShowFilter(data.emojis[result.id].unified))
}
if (results && results.length) {
results = results.slice(0, maxResults)
}
}
return filteredResults
return results
}
export default { search, emojis: emojisList, emoticons: emoticonsList }