You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.0 KiB

  1. import { connect } from 'react-redux';
  2. import EmojiPickerDropdown from '../components/emoji_picker_dropdown';
  3. import { changeSetting } from '../../../actions/settings';
  4. import { createSelector } from 'reselect';
  5. import { Map as ImmutableMap } from 'immutable';
  6. import { useEmoji } from '../../../actions/emojis';
  7. const perLine = 8;
  8. const lines = 2;
  9. const DEFAULTS = [
  10. '+1',
  11. 'grinning',
  12. 'kissing_heart',
  13. 'heart_eyes',
  14. 'laughing',
  15. 'stuck_out_tongue_winking_eye',
  16. 'sweat_smile',
  17. 'joy',
  18. 'yum',
  19. 'disappointed',
  20. 'thinking_face',
  21. 'weary',
  22. 'sob',
  23. 'sunglasses',
  24. 'heart',
  25. 'ok_hand',
  26. ];
  27. const getFrequentlyUsedEmojis = createSelector([
  28. state => state.getIn(['settings', 'frequentlyUsedEmojis'], ImmutableMap()),
  29. ], emojiCounters => {
  30. let emojis = emojiCounters
  31. .keySeq()
  32. .sort((a, b) => emojiCounters.get(a) - emojiCounters.get(b))
  33. .reverse()
  34. .slice(0, perLine * lines)
  35. .toArray();
  36. if (emojis.length < DEFAULTS.length) {
  37. emojis = emojis.concat(DEFAULTS.slice(0, DEFAULTS.length - emojis.length));
  38. }
  39. return emojis;
  40. });
  41. const getCustomEmojis = createSelector([
  42. state => state.get('custom_emojis'),
  43. ], emojis => emojis.sort((a, b) => {
  44. const aShort = a.get('shortcode').toLowerCase();
  45. const bShort = b.get('shortcode').toLowerCase();
  46. if (aShort < bShort) {
  47. return -1;
  48. } else if (aShort > bShort ) {
  49. return 1;
  50. } else {
  51. return 0;
  52. }
  53. }));
  54. const mapStateToProps = state => ({
  55. custom_emojis: getCustomEmojis(state),
  56. autoPlay: state.getIn(['meta', 'auto_play_gif']),
  57. skinTone: state.getIn(['settings', 'skinTone']),
  58. frequentlyUsedEmojis: getFrequentlyUsedEmojis(state),
  59. });
  60. const mapDispatchToProps = (dispatch, { onPickEmoji }) => ({
  61. onSkinTone: skinTone => {
  62. dispatch(changeSetting(['skinTone'], skinTone));
  63. },
  64. onPickEmoji: emoji => {
  65. dispatch(useEmoji(emoji));
  66. if (onPickEmoji) {
  67. onPickEmoji(emoji);
  68. }
  69. },
  70. });
  71. export default connect(mapStateToProps, mapDispatchToProps)(EmojiPickerDropdown);