forked from Ivasoft/mattermost-mobile
* RN-223 Emoji picker for adding new emoji reactions * Remove redundant setServerVersion and fetch custom emojis on reset * Review feedback * Review feedback 2 * Review feedback 3 * Review feedback 4 * Change aliases to array and add header to image source * Remove aliases from custom emojis
109 lines
2.6 KiB
JavaScript
109 lines
2.6 KiB
JavaScript
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
import {connect} from 'react-redux';
|
|
import {createSelector} from 'reselect';
|
|
|
|
import {getCustomEmojisByName} from 'mattermost-redux/selectors/entities/emojis';
|
|
|
|
import {getTheme} from 'app/selectors/preferences';
|
|
import {CategoryNames, Emojis, EmojiIndicesByCategory} from 'app/utils/emojis';
|
|
|
|
import EmojiPicker from './emoji_picker';
|
|
|
|
const categoryToI18n = {
|
|
activity: {
|
|
id: 'mobile.emoji_picker.activity',
|
|
defaultMessage: 'ACTIVITY'
|
|
},
|
|
custom: {
|
|
id: 'mobile.emoji_picker.custom',
|
|
defaultMessage: 'CUSTOM'
|
|
},
|
|
flags: {
|
|
id: 'mobile.emoji_picker.flags',
|
|
defaultMessage: 'FLAGS'
|
|
},
|
|
foods: {
|
|
id: 'mobile.emoji_picker.foods',
|
|
defaultMessage: 'FOODS'
|
|
},
|
|
nature: {
|
|
id: 'mobile.emoji_picker.nature',
|
|
defaultMessage: 'NATURE'
|
|
},
|
|
objects: {
|
|
id: 'mobile.emoji_picker.objects',
|
|
defaultMessage: 'OBJECTS'
|
|
},
|
|
people: {
|
|
id: 'mobile.emoji_picker.people',
|
|
defaultMessage: 'PEOPLE'
|
|
},
|
|
places: {
|
|
id: 'mobile.emoji_picker.places',
|
|
defaultMessage: 'PLACES'
|
|
},
|
|
symbols: {
|
|
id: 'mobile.emoji_picker.symbols',
|
|
defaultMessage: 'SYMBOLS'
|
|
}
|
|
};
|
|
|
|
function fillEmoji(indice) {
|
|
const emoji = Emojis[indice];
|
|
return {
|
|
name: emoji.aliases[0],
|
|
aliases: emoji.aliases
|
|
};
|
|
}
|
|
|
|
const getEmojisBySection = createSelector(
|
|
getCustomEmojisByName,
|
|
(customEmojis) => {
|
|
const emoticons = CategoryNames.filter((name) => name !== 'custom').map((category) => {
|
|
const section = {
|
|
...categoryToI18n[category],
|
|
key: category,
|
|
data: [{
|
|
key: `${category}-emojis`,
|
|
items: EmojiIndicesByCategory.get(category).map(fillEmoji)
|
|
}]
|
|
};
|
|
|
|
return section;
|
|
});
|
|
|
|
const customEmojiData = {
|
|
key: 'custom-emojis',
|
|
title: 'CUSTOM',
|
|
items: []
|
|
};
|
|
|
|
for (const [key] of customEmojis) {
|
|
customEmojiData.items.push({
|
|
name: key
|
|
});
|
|
}
|
|
|
|
emoticons.push({
|
|
...categoryToI18n.custom,
|
|
key: 'custom',
|
|
data: [customEmojiData]
|
|
});
|
|
|
|
return emoticons;
|
|
}
|
|
);
|
|
|
|
function mapStateToProps(state) {
|
|
const emojis = getEmojisBySection(state);
|
|
|
|
return {
|
|
emojis,
|
|
theme: getTheme(state)
|
|
};
|
|
}
|
|
|
|
export default connect(mapStateToProps)(EmojiPicker);
|