-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Add filterFunctions prop to enable emojis filtering #34
Merged
sskhandek
merged 4 commits into
sskhandek:master
from
darekg11:feature/allow-to-filter-rendered-emojis
Apr 30, 2019
+43
−9
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
60feb0c
Add filterFunctions prop allowing user to specify filter functions th…
darekg11 b3176f6
Chain lodash call to filter emojis. Drop checking for 0 length of fil…
darekg11 fcf92d5
Add call to value at the end of Lodash chain. Add missing semicolon
darekg11 4857b89
Move filtering to one place in common chain. Remove filteredEmojis va…
darekg11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,6 +287,9 @@ class EmojiInput extends React.PureComponent { | |
return e1.char !== e2.char; | ||
}); | ||
|
||
this.filtered = this.props.filterFunctions.length === 0 | ||
? emoji | ||
: _.pickBy(emoji, value => _.every(this.props.filterFunctions, fn => fn(value))) | ||
this.emoji = []; | ||
let categoryIndexMap = _(category) | ||
.map((v, idx) => ({ ...v, idx })) | ||
|
@@ -298,7 +301,7 @@ class EmojiInput extends React.PureComponent { | |
.map((v, k) => [ | ||
{ char: category[k].key, categoryMarker: true, ...category[k] } | ||
]); | ||
_(emoji) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: rename it to emojis There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have changed the param of function to |
||
_(this.filtered) | ||
.values() | ||
.each(e => { | ||
if (_.has(categoryIndexMap, e.category)) { | ||
|
@@ -633,7 +636,8 @@ EmojiInput.defaultProps = { | |
}, | ||
emojiFontSize: 40, | ||
categoryFontSize: 20, | ||
resetSearch: false | ||
resetSearch: false, | ||
filterFunctions: [] | ||
}; | ||
|
||
EmojiInput.propTypes = { | ||
|
@@ -657,7 +661,8 @@ EmojiInput.propTypes = { | |
enableFrequentlyUsedEmoji: PropTypes.bool, | ||
numFrequentlyUsedEmoji: PropTypes.number, | ||
defaultFrequentlyUsedEmoji: PropTypes.arrayOf(PropTypes.string), | ||
resetSearch: PropTypes.bool | ||
resetSearch: PropTypes.bool, | ||
filterFunctions: PropTypes.arrayOf(PropTypes.func) | ||
}; | ||
|
||
const styles = { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's directly connect the filter functions to lodash chain, e.g.
Also
_.every
will return true if the first argument is empty array, so it's safe not to check whether the length is zeroThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. 👍