2021-09-09 16:29:01 +00:00
|
|
|
// Copyright 2020-2021 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-05-05 19:49:34 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import { StateType } from '../reducer';
|
2021-04-27 22:35:35 +00:00
|
|
|
import { useRecentEmojis } from '../selectors/emojis';
|
2020-05-05 19:49:34 +00:00
|
|
|
import { useActions as useEmojiActions } from '../ducks/emojis';
|
|
|
|
|
|
|
|
import {
|
|
|
|
EmojiPicker,
|
|
|
|
Props as EmojiPickerProps,
|
|
|
|
} from '../../components/emoji/EmojiPicker';
|
|
|
|
import { getIntl } from '../selectors/user';
|
2021-09-09 16:29:01 +00:00
|
|
|
import { getEmojiSkinTone } from '../selectors/items';
|
2020-05-05 19:49:34 +00:00
|
|
|
import { LocalizerType } from '../../types/Util';
|
|
|
|
|
|
|
|
export const SmartEmojiPicker = React.forwardRef<
|
|
|
|
HTMLDivElement,
|
2021-09-09 16:29:01 +00:00
|
|
|
Pick<
|
|
|
|
EmojiPickerProps,
|
|
|
|
'onClickSettings' | 'onPickEmoji' | 'onSetSkinTone' | 'onClose' | 'style'
|
|
|
|
>
|
|
|
|
>(({ onClickSettings, onPickEmoji, onSetSkinTone, onClose, style }, ref) => {
|
2020-05-05 19:49:34 +00:00
|
|
|
const i18n = useSelector<StateType, LocalizerType>(getIntl);
|
|
|
|
const skinTone = useSelector<StateType, number>(state =>
|
2021-09-09 16:29:01 +00:00
|
|
|
getEmojiSkinTone(state)
|
2020-05-05 19:49:34 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const recentEmojis = useRecentEmojis();
|
|
|
|
|
|
|
|
const { onUseEmoji } = useEmojiActions();
|
|
|
|
|
|
|
|
const handlePickEmoji = React.useCallback(
|
|
|
|
data => {
|
|
|
|
onUseEmoji({ shortName: data.shortName });
|
|
|
|
onPickEmoji(data);
|
|
|
|
},
|
|
|
|
[onUseEmoji, onPickEmoji]
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<EmojiPicker
|
|
|
|
ref={ref}
|
|
|
|
i18n={i18n}
|
|
|
|
skinTone={skinTone}
|
2021-09-09 16:29:01 +00:00
|
|
|
onClickSettings={onClickSettings}
|
2020-05-05 19:49:34 +00:00
|
|
|
onSetSkinTone={onSetSkinTone}
|
|
|
|
onPickEmoji={handlePickEmoji}
|
|
|
|
recentEmojis={recentEmojis}
|
|
|
|
onClose={onClose}
|
|
|
|
style={style}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|