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,23 +59,27 @@ export default class Picker extends React.Component {
let isExcluded = props.exclude == undefined ? false : props.exclude.indexOf(category.name.toLowerCase()) > -1
if (!isIncluded || isExcluded) { continue }
let newEmojis = []
if (props.emojisToShowFilter) {
let newEmojis = []
for (let emoji of category.emojis) {
let unified = data.emojis[emoji].unified
for (let emoji of category.emojis) {
let unified = data.emojis[emoji].unified
if (props.emojisToShowFilter(unified)) {
newEmojis.push(emoji)
}
}
if (newEmojis.length) {
let newCategory = {
emojis: newEmojis,
name: category.name,
if (props.emojisToShowFilter(unified)) {
newEmojis.push(emoji)
}
}
this.categories.push(newCategory)
if (newEmojis.length) {
let newCategory = {
emojis: newEmojis,
name: category.name,
}
this.categories.push(newCategory)
}
} else {
this.categories.push(category)
}
}
@ -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 }