2020-05-05 19:49:34 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import { get } from 'lodash';
|
|
|
|
import { StateType } from '../reducer';
|
|
|
|
import { useActions as useItemActions, useRecentEmojis } from '../ducks/items';
|
|
|
|
import { useActions as useEmojiActions } from '../ducks/emojis';
|
|
|
|
|
|
|
|
import {
|
|
|
|
EmojiPicker,
|
|
|
|
Props as EmojiPickerProps,
|
|
|
|
} from '../../components/emoji/EmojiPicker';
|
|
|
|
import { getIntl } from '../selectors/user';
|
|
|
|
import { LocalizerType } from '../../types/Util';
|
|
|
|
|
|
|
|
export const SmartEmojiPicker = React.forwardRef<
|
|
|
|
HTMLDivElement,
|
2020-05-11 23:14:02 +00:00
|
|
|
Pick<
|
|
|
|
EmojiPickerProps,
|
|
|
|
'onPickEmoji' | 'onClose' | 'style' | 'disableSkinTones'
|
|
|
|
>
|
|
|
|
>(({ onPickEmoji, onClose, style, disableSkinTones }, ref) => {
|
2020-05-05 19:49:34 +00:00
|
|
|
const i18n = useSelector<StateType, LocalizerType>(getIntl);
|
|
|
|
const skinTone = useSelector<StateType, number>(state =>
|
|
|
|
get(state, ['items', 'skinTone'], 0)
|
|
|
|
);
|
|
|
|
|
|
|
|
const recentEmojis = useRecentEmojis();
|
|
|
|
|
|
|
|
const { putItem } = useItemActions();
|
|
|
|
|
|
|
|
const onSetSkinTone = React.useCallback(
|
|
|
|
tone => {
|
|
|
|
putItem('skinTone', tone);
|
|
|
|
},
|
|
|
|
[putItem]
|
|
|
|
);
|
|
|
|
|
|
|
|
const { onUseEmoji } = useEmojiActions();
|
|
|
|
|
|
|
|
const handlePickEmoji = React.useCallback(
|
|
|
|
data => {
|
|
|
|
onUseEmoji({ shortName: data.shortName });
|
|
|
|
onPickEmoji(data);
|
|
|
|
},
|
|
|
|
[onUseEmoji, onPickEmoji]
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<EmojiPicker
|
|
|
|
ref={ref}
|
|
|
|
i18n={i18n}
|
|
|
|
skinTone={skinTone}
|
|
|
|
onSetSkinTone={onSetSkinTone}
|
|
|
|
onPickEmoji={handlePickEmoji}
|
|
|
|
recentEmojis={recentEmojis}
|
|
|
|
onClose={onClose}
|
|
|
|
style={style}
|
2020-05-11 23:14:02 +00:00
|
|
|
disableSkinTones={disableSkinTones}
|
2020-05-05 19:49:34 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|