2019-10-30 14:14:41 +00:00
|
|
|
import React, { useContext } from 'react';
|
|
|
|
import { TouchableOpacity, Text } from 'react-native';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import styles from '../styles';
|
|
|
|
import Avatar from '../../Avatar';
|
|
|
|
import MessageboxContext from '../Context';
|
|
|
|
import FixedMentionItem from './FixedMentionItem';
|
|
|
|
import MentionEmoji from './MentionEmoji';
|
|
|
|
import {
|
|
|
|
MENTIONS_TRACKING_TYPE_EMOJIS,
|
|
|
|
MENTIONS_TRACKING_TYPE_COMMANDS
|
|
|
|
} from '../constants';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../../constants/colors';
|
2019-10-30 14:14:41 +00:00
|
|
|
|
|
|
|
const MentionItem = ({
|
2019-12-04 16:39:53 +00:00
|
|
|
item, trackingType, theme
|
2019-10-30 14:14:41 +00:00
|
|
|
}) => {
|
|
|
|
const context = useContext(MessageboxContext);
|
|
|
|
const { baseUrl, user, onPressMention } = context;
|
|
|
|
|
|
|
|
const defineTestID = (type) => {
|
|
|
|
switch (type) {
|
|
|
|
case MENTIONS_TRACKING_TYPE_EMOJIS:
|
|
|
|
return `mention-item-${ item.name || item }`;
|
|
|
|
case MENTIONS_TRACKING_TYPE_COMMANDS:
|
|
|
|
return `mention-item-${ item.command || item }`;
|
|
|
|
default:
|
|
|
|
return `mention-item-${ item.username || item.name || item }`;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const testID = defineTestID(trackingType);
|
|
|
|
|
|
|
|
if (item.username === 'all' || item.username === 'here') {
|
2019-12-04 16:39:53 +00:00
|
|
|
return <FixedMentionItem item={item} onPress={onPressMention} theme={theme} />;
|
2019-10-30 14:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let content = (
|
|
|
|
<>
|
|
|
|
<Avatar
|
|
|
|
style={styles.avatar}
|
|
|
|
text={item.username || item.name}
|
|
|
|
size={30}
|
|
|
|
type={item.t}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
userId={user.id}
|
|
|
|
token={user.token}
|
|
|
|
/>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.mentionText, { color: themes[theme].titleText }]}>{ item.username || item.name || item }</Text>
|
2019-10-30 14:14:41 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
if (trackingType === MENTIONS_TRACKING_TYPE_EMOJIS) {
|
|
|
|
content = (
|
|
|
|
<>
|
|
|
|
<MentionEmoji item={item} />
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.mentionText, { color: themes[theme].titleText }]}>:{ item.name || item }:</Text>
|
2019-10-30 14:14:41 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (trackingType === MENTIONS_TRACKING_TYPE_COMMANDS) {
|
|
|
|
content = (
|
|
|
|
<>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.slash, { backgroundColor: themes[theme].borderColor, color: themes[theme].tintColor }]}>/</Text>
|
|
|
|
<Text style={[styles.mentionText, { color: themes[theme].titleText }]}>{ item.command}</Text>
|
2019-10-30 14:14:41 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableOpacity
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[
|
|
|
|
styles.mentionItem,
|
|
|
|
{
|
|
|
|
backgroundColor: themes[theme].auxiliaryBackground,
|
|
|
|
borderTopColor: themes[theme].separatorColor
|
|
|
|
}
|
|
|
|
]}
|
2019-10-30 14:14:41 +00:00
|
|
|
onPress={() => onPressMention(item)}
|
|
|
|
testID={testID}
|
|
|
|
>
|
|
|
|
{content}
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
MentionItem.propTypes = {
|
|
|
|
item: PropTypes.object,
|
2019-12-04 16:39:53 +00:00
|
|
|
trackingType: PropTypes.string,
|
|
|
|
theme: PropTypes.string
|
2019-10-30 14:14:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default MentionItem;
|