Merge pull request #43 from pivotaltracker/custom-emoji-filter
Add emojisToShow filternolan/hinaloe-test
commit
262e89463c
|
@ -88,7 +88,7 @@ export default class Category extends React.Component {
|
||||||
updateDisplay(display) {
|
updateDisplay(display) {
|
||||||
var emojis = this.getEmojis()
|
var emojis = this.getEmojis()
|
||||||
|
|
||||||
if (!display && !emojis) {
|
if (!emojis) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,7 @@ import { Anchors, Category, Emoji, Preview, Search } from '.'
|
||||||
const RECENT_CATEGORY = { name: 'Recent', emojis: null }
|
const RECENT_CATEGORY = { name: 'Recent', emojis: null }
|
||||||
const SEARCH_CATEGORY = { name: 'Search', emojis: null, anchor: RECENT_CATEGORY }
|
const SEARCH_CATEGORY = { name: 'Search', emojis: null, anchor: RECENT_CATEGORY }
|
||||||
|
|
||||||
const CATEGORIES = [
|
let CATEGORIES = [];
|
||||||
SEARCH_CATEGORY,
|
|
||||||
RECENT_CATEGORY,
|
|
||||||
].concat(data.categories)
|
|
||||||
|
|
||||||
const I18N = {
|
const I18N = {
|
||||||
search: 'Search',
|
search: 'Search',
|
||||||
|
@ -42,6 +39,32 @@ export default class Picker extends React.Component {
|
||||||
skin: store.get('skin') || props.skin,
|
skin: store.get('skin') || props.skin,
|
||||||
firstRender: true,
|
firstRender: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let filteredCategories = [];
|
||||||
|
|
||||||
|
for (let hash of data.categories) {
|
||||||
|
let new_emojis = [];
|
||||||
|
for (let emoji of hash.emojis) {
|
||||||
|
let unified = data.emojis[emoji].unified;
|
||||||
|
if (props.emojisToShowFilter(unified)) {
|
||||||
|
new_emojis.push(emoji)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (new_emojis.length) {
|
||||||
|
let new_hash = {
|
||||||
|
emojis: new_emojis,
|
||||||
|
name: hash.name
|
||||||
|
}
|
||||||
|
filteredCategories.push(new_hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CATEGORIES = [
|
||||||
|
SEARCH_CATEGORY,
|
||||||
|
RECENT_CATEGORY,
|
||||||
|
].concat(filteredCategories);
|
||||||
|
|
||||||
|
this.categories = CATEGORIES;
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(props) {
|
componentWillReceiveProps(props) {
|
||||||
|
@ -238,7 +261,7 @@ export default class Picker extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
var { perLine, emojiSize, set, sheetSize, style, title, emoji, color, backgroundImageFn } = this.props,
|
var { perLine, emojiSize, set, sheetSize, style, title, emoji, color, backgroundImageFn, emojisToShowFilter } = this.props,
|
||||||
{ skin } = this.state,
|
{ skin } = this.state,
|
||||||
width = (perLine * (emojiSize + 12)) + 12 + 2
|
width = (perLine * (emojiSize + 12)) + 12 + 2
|
||||||
|
|
||||||
|
@ -258,6 +281,7 @@ export default class Picker extends React.Component {
|
||||||
ref='search'
|
ref='search'
|
||||||
onSearch={this.handleSearch.bind(this)}
|
onSearch={this.handleSearch.bind(this)}
|
||||||
i18n={this.i18n}
|
i18n={this.i18n}
|
||||||
|
emojisToShowFilter={emojisToShowFilter}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{this.getCategories().map((category, i) => {
|
{this.getCategories().map((category, i) => {
|
||||||
|
@ -318,6 +342,7 @@ Picker.propTypes = {
|
||||||
backgroundImageFn: Emoji.propTypes.backgroundImageFn,
|
backgroundImageFn: Emoji.propTypes.backgroundImageFn,
|
||||||
skin: Emoji.propTypes.skin,
|
skin: Emoji.propTypes.skin,
|
||||||
sheetSize: Emoji.propTypes.sheetSize,
|
sheetSize: Emoji.propTypes.sheetSize,
|
||||||
|
emojisToShowFilter: React.PropTypes.func,
|
||||||
}
|
}
|
||||||
|
|
||||||
Picker.defaultProps = {
|
Picker.defaultProps = {
|
||||||
|
@ -333,4 +358,5 @@ Picker.defaultProps = {
|
||||||
skin: Emoji.defaultProps.skin,
|
skin: Emoji.defaultProps.skin,
|
||||||
sheetSize: Emoji.defaultProps.sheetSize,
|
sheetSize: Emoji.defaultProps.sheetSize,
|
||||||
backgroundImageFn: Emoji.defaultProps.backgroundImageFn,
|
backgroundImageFn: Emoji.defaultProps.backgroundImageFn,
|
||||||
|
emojisToShowFilter: (codePoint) => true,
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ export default class Search extends React.Component {
|
||||||
var { input } = this.refs,
|
var { input } = this.refs,
|
||||||
value = input.value
|
value = input.value
|
||||||
|
|
||||||
this.props.onSearch(emojiIndex.search(value))
|
this.props.onSearch(emojiIndex.search(value, this.props.emojisToShowFilter, this.props.maxResults))
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
|
@ -29,9 +29,11 @@ export default class Search extends React.Component {
|
||||||
Search.propTypes = {
|
Search.propTypes = {
|
||||||
onSearch: React.PropTypes.func,
|
onSearch: React.PropTypes.func,
|
||||||
maxResults: React.PropTypes.number,
|
maxResults: React.PropTypes.number,
|
||||||
|
emojisToShowFilter: React.PropTypes.func
|
||||||
}
|
}
|
||||||
|
|
||||||
Search.defaultProps = {
|
Search.defaultProps = {
|
||||||
onSearch: (() => {}),
|
onSearch: (() => {}),
|
||||||
maxResults: 75,
|
maxResults: 75,
|
||||||
|
emojisToShowFilter: () => true
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ for (let emoji in data.emojis) {
|
||||||
emojisList[id] = getSanitizedData(id)
|
emojisList[id] = getSanitizedData(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
function search(value, maxResults = 75) {
|
function search(value, emojisToShowFilter = () => true, maxResults = 75) {
|
||||||
var results = null
|
var results = null
|
||||||
|
|
||||||
if (value.length) {
|
if (value.length) {
|
||||||
|
@ -92,11 +92,16 @@ function search(value, maxResults = 75) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (results && results.length) {
|
let filtered_results = null;
|
||||||
results = results.slice(0, maxResults)
|
if (results) {
|
||||||
|
filtered_results = results.filter(
|
||||||
|
(result) => emojisToShowFilter(data.emojis[result.id].unified));
|
||||||
|
if (filtered_results && filtered_results.length) {
|
||||||
|
filtered_results = filtered_results.slice(0, maxResults)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return results
|
return filtered_results
|
||||||
}
|
}
|
||||||
|
|
||||||
export default { search, emojis: emojisList, emoticons: emoticonsList }
|
export default { search, emojis: emojisList, emoticons: emoticonsList }
|
||||||
|
|
Loading…
Reference in New Issue