2018-01-30 19:48:26 +00:00
|
|
|
import React from 'react';
|
2019-01-29 19:52:56 +00:00
|
|
|
import { View } from 'react-native';
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2018-01-30 19:48:26 +00:00
|
|
|
import EmojiPicker from '../../containers/EmojiPicker';
|
2021-09-13 20:41:05 +00:00
|
|
|
import styles from './styles';
|
2022-10-21 18:27:55 +00:00
|
|
|
import { IEmoji } from '../../definitions';
|
|
|
|
import { EventTypes } from '../../containers/EmojiPicker/interfaces';
|
|
|
|
import { searchEmojis } from '../../lib/methods';
|
|
|
|
import { useDebounce } from '../../lib/methods/helpers/debounce';
|
|
|
|
import { EmojiSearch } from '../../containers/EmojiPicker/EmojiSearch';
|
|
|
|
import { events, logEvent } from '../../lib/methods/helpers/log';
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
interface IReactionPickerProps {
|
|
|
|
message?: any;
|
|
|
|
reactionClose: () => void;
|
2022-10-21 18:27:55 +00:00
|
|
|
onEmojiSelected: (emoji: IEmoji, id: string) => void;
|
2022-03-02 14:18:01 +00:00
|
|
|
}
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2022-10-21 18:27:55 +00:00
|
|
|
const ReactionPicker = ({ onEmojiSelected, message, reactionClose }: IReactionPickerProps): React.ReactElement => {
|
|
|
|
const [searchedEmojis, setSearchedEmojis] = React.useState<IEmoji[]>([]);
|
|
|
|
const [searching, setSearching] = React.useState<boolean>(false);
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2022-10-21 18:27:55 +00:00
|
|
|
const handleTextChange = useDebounce((text: string) => {
|
|
|
|
setSearching(text !== '');
|
|
|
|
handleSearchEmojis(text);
|
|
|
|
}, 300);
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2022-10-21 18:27:55 +00:00
|
|
|
const handleSearchEmojis = async (text: string) => {
|
|
|
|
logEvent(events.REACTION_PICKER_SEARCH_EMOJIS);
|
|
|
|
const emojis = await searchEmojis(text);
|
|
|
|
setSearchedEmojis(emojis);
|
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
|
2022-10-21 18:27:55 +00:00
|
|
|
const handleEmojiSelect = (_eventType: EventTypes, emoji?: IEmoji) => {
|
|
|
|
logEvent(events.REACTION_PICKER_EMOJI_SELECTED);
|
|
|
|
if (message && emoji) {
|
|
|
|
onEmojiSelected(emoji, message.id);
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
2022-10-21 18:27:55 +00:00
|
|
|
reactionClose();
|
|
|
|
};
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2022-10-21 18:27:55 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.reactionPickerContainer} testID='reaction-picker'>
|
|
|
|
<View style={styles.reactionSearchContainer}>
|
|
|
|
<EmojiSearch onChangeText={handleTextChange} bottomSheet />
|
|
|
|
</View>
|
|
|
|
<EmojiPicker onItemClicked={handleEmojiSelect} searching={searching} searchedEmojis={searchedEmojis} />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ReactionPicker;
|