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 {
|
2024-01-25 14:11:07 +00:00
|
|
|
messageId?: string;
|
2022-03-02 14:18:01 +00:00
|
|
|
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
|
|
|
|
2024-01-25 14:11:07 +00:00
|
|
|
const ReactionPicker = ({ onEmojiSelected, messageId, reactionClose }: IReactionPickerProps): React.ReactElement => {
|
2022-10-21 18:27:55 +00:00
|
|
|
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);
|
2024-01-25 14:11:07 +00:00
|
|
|
if (messageId && emoji) {
|
|
|
|
onEmojiSelected(emoji, messageId);
|
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;
|