import React, { useContext } from 'react'; import { Text, TouchableOpacity, View } from 'react-native'; import { themes } from '../../../lib/constants'; import { IEmoji } from '../../../definitions/IEmoji'; import { useTheme } from '../../../theme'; import Avatar from '../../Avatar'; import { MENTIONS_TRACKING_TYPE_CANNED, MENTIONS_TRACKING_TYPE_COMMANDS, MENTIONS_TRACKING_TYPE_EMOJIS } from '../constants'; import MessageboxContext from '../Context'; import styles from '../styles'; import FixedMentionItem from './FixedMentionItem'; import MentionEmoji from './MentionEmoji'; interface IMessageBoxMentionItem { item: { name: string; command: string; username: string; t: string; id: string; shortcut: string; text: string; } & IEmoji; trackingType: string; } const MentionItemContent = React.memo(({ trackingType, item }: IMessageBoxMentionItem) => { const { theme } = useTheme(); switch (trackingType) { case MENTIONS_TRACKING_TYPE_EMOJIS: return ( <> :{item.name ?? item}: ); case MENTIONS_TRACKING_TYPE_COMMANDS: return ( <> / {item.id} ); case MENTIONS_TRACKING_TYPE_CANNED: return ( <> !{item.shortcut} {item.text} ); default: return ( <> {item.username ?? item.name ?? item} ); } }); const MentionItem = ({ item, trackingType }: IMessageBoxMentionItem) => { const context = useContext(MessageboxContext); const { theme } = useTheme(); const { onPressMention } = context; const defineTestID = (type: string) => { switch (type) { case MENTIONS_TRACKING_TYPE_EMOJIS: return `mention-item-${item.name || item}`; case MENTIONS_TRACKING_TYPE_COMMANDS: return `mention-item-${item.command || item}`; case MENTIONS_TRACKING_TYPE_CANNED: return `mention-item-${item.shortcut || item}`; default: return `mention-item-${item.username || item.name || item}`; } }; const testID = defineTestID(trackingType); if (item.username === 'all' || item.username === 'here') { return ; } return ( onPressMention(item)} testID={testID} > ); }; export default MentionItem;