2017-09-22 23:40:28 -04:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import EmojiPickerDropdown from '../components/emoji_picker_dropdown';
|
2017-10-07 13:02:30 -04:00
|
|
|
import { changeSetting } from '../../../actions/settings';
|
2017-10-08 15:47:15 -04:00
|
|
|
import { createSelector } from 'reselect';
|
|
|
|
import { Map as ImmutableMap } from 'immutable';
|
|
|
|
import { useEmoji } from '../../../actions/emojis';
|
|
|
|
|
|
|
|
const perLine = 8;
|
|
|
|
const lines = 2;
|
|
|
|
|
2017-10-10 14:47:14 -04:00
|
|
|
const DEFAULTS = [
|
|
|
|
'+1',
|
|
|
|
'grinning',
|
|
|
|
'kissing_heart',
|
|
|
|
'heart_eyes',
|
|
|
|
'laughing',
|
|
|
|
'stuck_out_tongue_winking_eye',
|
|
|
|
'sweat_smile',
|
|
|
|
'joy',
|
|
|
|
'yum',
|
|
|
|
'disappointed',
|
|
|
|
'thinking_face',
|
|
|
|
'weary',
|
|
|
|
'sob',
|
|
|
|
'sunglasses',
|
|
|
|
'heart',
|
|
|
|
'ok_hand',
|
|
|
|
];
|
|
|
|
|
2017-10-08 15:47:15 -04:00
|
|
|
const getFrequentlyUsedEmojis = createSelector([
|
|
|
|
state => state.getIn(['settings', 'frequentlyUsedEmojis'], ImmutableMap()),
|
2017-10-10 14:47:14 -04:00
|
|
|
], emojiCounters => {
|
|
|
|
let emojis = emojiCounters
|
2017-10-08 15:47:15 -04:00
|
|
|
.keySeq()
|
|
|
|
.sort((a, b) => emojiCounters.get(a) - emojiCounters.get(b))
|
|
|
|
.reverse()
|
|
|
|
.slice(0, perLine * lines)
|
2017-10-10 14:47:14 -04:00
|
|
|
.toArray();
|
|
|
|
|
|
|
|
if (emojis.length < DEFAULTS.length) {
|
2018-04-07 08:53:11 -04:00
|
|
|
let uniqueDefaults = DEFAULTS.filter(emoji => !emojis.includes(emoji));
|
|
|
|
emojis = emojis.concat(uniqueDefaults.slice(0, DEFAULTS.length - emojis.length));
|
2017-10-10 14:47:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return emojis;
|
|
|
|
});
|
2017-09-22 23:40:28 -04:00
|
|
|
|
2017-10-10 09:18:12 -04:00
|
|
|
const getCustomEmojis = createSelector([
|
|
|
|
state => state.get('custom_emojis'),
|
2017-10-27 10:11:30 -04:00
|
|
|
], emojis => emojis.filter(e => e.get('visible_in_picker')).sort((a, b) => {
|
2017-10-10 09:18:12 -04:00
|
|
|
const aShort = a.get('shortcode').toLowerCase();
|
|
|
|
const bShort = b.get('shortcode').toLowerCase();
|
|
|
|
|
|
|
|
if (aShort < bShort) {
|
|
|
|
return -1;
|
|
|
|
} else if (aShort > bShort ) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
2017-09-22 23:40:28 -04:00
|
|
|
const mapStateToProps = state => ({
|
2017-10-10 09:18:12 -04:00
|
|
|
custom_emojis: getCustomEmojis(state),
|
2017-10-07 13:02:30 -04:00
|
|
|
skinTone: state.getIn(['settings', 'skinTone']),
|
2017-10-08 15:47:15 -04:00
|
|
|
frequentlyUsedEmojis: getFrequentlyUsedEmojis(state),
|
2017-09-22 23:40:28 -04:00
|
|
|
});
|
|
|
|
|
2017-10-08 15:47:15 -04:00
|
|
|
const mapDispatchToProps = (dispatch, { onPickEmoji }) => ({
|
2017-10-07 13:02:30 -04:00
|
|
|
onSkinTone: skinTone => {
|
|
|
|
dispatch(changeSetting(['skinTone'], skinTone));
|
|
|
|
},
|
2017-10-08 15:47:15 -04:00
|
|
|
|
|
|
|
onPickEmoji: emoji => {
|
|
|
|
dispatch(useEmoji(emoji));
|
|
|
|
|
|
|
|
if (onPickEmoji) {
|
|
|
|
onPickEmoji(emoji);
|
|
|
|
}
|
|
|
|
},
|
2017-10-07 13:02:30 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(EmojiPickerDropdown);
|