Skip to content

Commit

Permalink
Fix getting category names from i18n
Browse files Browse the repository at this point in the history
Since the Category names update in emoji-data (4.0.0)
  • Loading branch information
EtienneLem committed Dec 8, 2017
1 parent 63509f7 commit fdf3c2d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
19 changes: 15 additions & 4 deletions scripts/build-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,24 @@ var emojiLibByChar = Object.keys(emojiLib.lib).reduce(
{}
)

var categories = ['Smileys & People', 'Animals & Nature', 'Food & Drink', 'Activities', 'Travel & Places', 'Objects', 'Symbols', 'Flags'],
data = { categories: [], emojis: {}, skins: {}, short_names: {} },
var data = { categories: [], emojis: {}, skins: {}, short_names: {} },
categoriesIndex = {}

var categories = [
['Smileys & People', 'people'],
['Animals & Nature', 'nature'],
['Food & Drink', 'foods'],
['Activities', 'activity'],
['Travel & Places', 'places'],
['Objects', 'objects'],
['Symbols', 'symbols'],
['Flags', 'flags'],
]

categories.forEach((category, i) => {
data.categories[i] = { name: category, emojis: [] }
categoriesIndex[category] = i
let [name, id] = category
data.categories[i] = { id: id, name: name, emojis: [] }
categoriesIndex[name] = i
})

emojiData.sort((a, b) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export default class Category extends React.Component {
}

render() {
var { name, hasStickyPosition, emojiProps, i18n } = this.props,
var { id, name, hasStickyPosition, emojiProps, i18n } = this.props,
emojis = this.getEmojis(),
labelStyles = {},
labelSpanStyles = {},
Expand Down Expand Up @@ -180,7 +180,7 @@ export default class Category extends React.Component {
className="emoji-mart-category-label"
>
<span style={labelSpanStyles} ref={this.setLabelRef}>
{i18n.categories[name.toLowerCase()]}
{i18n.categories[id]}
</span>
</div>

Expand Down
7 changes: 4 additions & 3 deletions src/components/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { deepMerge, measureScrollbar } from '../utils'

import { Anchors, Category, Emoji, Preview, Search } from '.'

const RECENT_CATEGORY = { name: 'Recent', emojis: null }
const SEARCH_CATEGORY = { name: 'Search', emojis: null, anchor: false }
const CUSTOM_CATEGORY = { name: 'Custom', emojis: [] }
const RECENT_CATEGORY = { id: 'recent', name: 'Recent', emojis: null }
const SEARCH_CATEGORY = { id: 'search', name: 'Search', emojis: null, anchor: false }
const CUSTOM_CATEGORY = { id: 'custom', name: 'Custom', emojis: [] }

const I18N = {
search: 'Search',
Expand Down Expand Up @@ -459,6 +459,7 @@ export default class Picker extends React.PureComponent {
<Category
ref={this.setCategoryRef.bind(this, `category-${i}`)}
key={category.name}
id={category.id}
name={category.name}
emojis={category.emojis}
perLine={perLine}
Expand Down

0 comments on commit fdf3c2d

Please sign in to comment.