2021-09-13 20:41:05 +00:00
|
|
|
import React, { useContext } from 'react';
|
|
|
|
import { Text, View } from 'react-native';
|
|
|
|
|
|
|
|
import Touchable from './Touchable';
|
|
|
|
import { BUTTON_HIT_SLOP, formatMessageCount } from './utils';
|
|
|
|
import styles from './styles';
|
|
|
|
import I18n from '../../i18n';
|
2022-05-02 19:21:15 +00:00
|
|
|
import { CustomIcon } from '../CustomIcon';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { DISCUSSION } from './constants';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2021-09-13 20:41:05 +00:00
|
|
|
import MessageContext from './Context';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { formatDateThreads } from '../../lib/methods/helpers/room';
|
2022-04-01 21:52:38 +00:00
|
|
|
import { IMessage } from '../../definitions';
|
|
|
|
import { useTheme } from '../../theme';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
const Discussion = React.memo(
|
2022-04-01 21:52:38 +00:00
|
|
|
({ msg, dcount, dlm }: Pick<IMessage, 'msg' | 'dcount' | 'dlm'>) => {
|
|
|
|
const { theme } = useTheme();
|
2021-09-13 20:41:05 +00:00
|
|
|
let time;
|
|
|
|
if (dlm) {
|
|
|
|
time = formatDateThreads(dlm);
|
|
|
|
}
|
|
|
|
const buttonText = formatMessageCount(dcount, DISCUSSION);
|
|
|
|
const { onDiscussionPress } = useContext(MessageContext);
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Text style={[styles.startedDiscussion, { color: themes[theme].auxiliaryText }]}>{I18n.t('Started_discussion')}</Text>
|
|
|
|
<Text style={[styles.text, { color: themes[theme].bodyText }]}>{msg}</Text>
|
|
|
|
<View style={styles.buttonContainer}>
|
|
|
|
<Touchable
|
|
|
|
onPress={onDiscussionPress}
|
|
|
|
background={Touchable.Ripple(themes[theme].bannerBackground)}
|
|
|
|
style={[styles.button, { backgroundColor: themes[theme].tintColor }]}
|
|
|
|
hitSlop={BUTTON_HIT_SLOP}>
|
|
|
|
<>
|
|
|
|
<CustomIcon name='discussions' size={16} style={styles.buttonIcon} color={themes[theme].buttonText} />
|
|
|
|
<Text style={[styles.buttonText, { color: themes[theme].buttonText }]}>{buttonText}</Text>
|
|
|
|
</>
|
|
|
|
</Touchable>
|
|
|
|
<Text style={[styles.time, { color: themes[theme].auxiliaryText }]}>{time}</Text>
|
|
|
|
</View>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
(prevProps, nextProps) => {
|
|
|
|
if (prevProps.msg !== nextProps.msg) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (prevProps.dcount !== nextProps.dcount) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (prevProps.dlm !== nextProps.dlm) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
Discussion.displayName = 'MessageDiscussion';
|
|
|
|
|
|
|
|
export default Discussion;
|