Normalize emoticons when building data

exclude-unsupported-native-emojis
Etienne Lemay 2016-07-07 17:22:40 -04:00
parent 9e57de33ce
commit 49ec3b9efe
5 changed files with 20 additions and 27 deletions

File diff suppressed because one or more lines are too long

View File

@ -39,6 +39,14 @@ emojiData.forEach((datum) => {
throw new Error('“' + datum.short_name + '” doesnt have a name') throw new Error('“' + datum.short_name + '” doesnt have a name')
} }
datum.emoticons = datum.texts || []
if (datum.text && !datum.emoticons.length) {
datum.emoticons = [datum.text]
}
delete datum.text
delete datum.texts
if (datum.category == 'Skin Tones') { if (datum.category == 'Skin Tones') {
data.skins[datum.short_name] = datum data.skins[datum.short_name] = datum
} else { } else {

View File

@ -70,15 +70,10 @@ export default class Emoji extends React.Component {
handleClick(emojiData) { handleClick(emojiData) {
var { onClick } = this.props, var { onClick } = this.props,
{ name, short_names, skin_tone, text, texts, unified } = emojiData, { name, short_names, skin_tone, emoticons, unified } = emojiData,
id = short_names[0], id = short_names[0],
colons = `:${id}:` colons = `:${id}:`
texts || (texts = [])
if (text && !texts.length) {
texts = [text]
}
if (skin_tone) { if (skin_tone) {
colons += `:skin-tone-${skin_tone}:` colons += `:skin-tone-${skin_tone}:`
} }
@ -87,8 +82,8 @@ export default class Emoji extends React.Component {
id, id,
name, name,
colons, colons,
emoticons,
skin: skin_tone || 1, skin: skin_tone || 1,
emoticons: texts,
native: this.getNative(emojiData), native: this.getNative(emojiData),
}) })
} }

View File

@ -12,19 +12,14 @@ export default class Preview extends React.Component {
{ emojiProps, skinsProps } = this.props { emojiProps, skinsProps } = this.props
if (emoji) { if (emoji) {
var { text, texts } = emoji, var { emoticons } = emoji,
knownEmoticons = [], knownEmoticons = [],
emoticons = [] listedEmoticons = []
texts || (texts = []) for (let emoticon of emoticons) {
if (text && !texts.length) { if (knownEmoticons.indexOf(emoticon.toLowerCase()) == -1) {
texts = [text] knownEmoticons.push(emoticon.toLowerCase())
} listedEmoticons.push(emoticon)
for (let text of texts) {
if (knownEmoticons.indexOf(text.toLowerCase()) == -1) {
knownEmoticons.push(text.toLowerCase())
emoticons.push(text)
} }
} }
@ -43,7 +38,7 @@ export default class Preview extends React.Component {
{emoji.short_names.map((short_name) => {emoji.short_names.map((short_name) =>
<span key={short_name} className='emoji-picker-preview-shortname'>:{short_name}:</span> <span key={short_name} className='emoji-picker-preview-shortname'>:{short_name}:</span>
)}<br /> )}<br />
{emoticons.map((emoticon) => {listedEmoticons.map((emoticon) =>
<span key={emoticon} className='emoji-picker-preview-emoticon'>{emoticon}</span> <span key={emoticon} className='emoji-picker-preview-emoticon'>{emoticon}</span>
)} )}
</span> </span>

View File

@ -22,16 +22,11 @@ export default class Search extends React.Component {
for (let emoji in data.emojis) { for (let emoji in data.emojis) {
let emojiData = data.emojis[emoji], let emojiData = data.emojis[emoji],
{ short_name, name, text, texts } = emojiData { short_name, name, emoticons } = emojiData
texts || (texts = [])
if (text && !texts.length) {
texts = [text]
}
this.index.add({ this.index.add({
id: short_name, id: short_name,
emoticons: texts, emoticons: emoticons,
short_name: this.tokenize(short_name), short_name: this.tokenize(short_name),
name: this.tokenize(name), name: this.tokenize(name),
}) })