vn-verdnaturachat/app/containers/MessageBox/ReplyPreview.js

98 lines
2.6 KiB
JavaScript
Raw Normal View History

import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import PropTypes from 'prop-types';
import moment from 'moment';
import { connect } from 'react-redux';
import Markdown from '../markdown';
import { CustomIcon } from '../../lib/Icons';
2019-03-29 19:36:07 +00:00
import sharedStyles from '../../views/Styles';
2019-12-04 16:39:53 +00:00
import { themes } from '../../constants/colors';
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
2019-12-04 16:39:53 +00:00
paddingTop: 10
},
messageContainer: {
flex: 1,
marginHorizontal: 10,
paddingHorizontal: 15,
paddingVertical: 10,
borderRadius: 4
},
header: {
flexDirection: 'row',
alignItems: 'center'
},
username: {
fontSize: 16,
2019-03-29 19:36:07 +00:00
...sharedStyles.textMedium
},
time: {
fontSize: 12,
lineHeight: 16,
2019-03-29 19:36:07 +00:00
marginLeft: 6,
...sharedStyles.textRegular,
fontWeight: '300'
},
close: {
marginRight: 10
}
});
const ReplyPreview = React.memo(({
message, Message_TimeFormat, baseUrl, username, replying, getCustomEmoji, close, theme, useRealName
}) => {
if (!replying) {
return null;
}
const time = moment(message.ts).format(Message_TimeFormat);
return (
2019-12-04 16:39:53 +00:00
<View
style={[
styles.container,
{ backgroundColor: themes[theme].messageboxBackground }
]}
>
<View style={[styles.messageContainer, { backgroundColor: themes[theme].chatComponentBackground }]}>
<View style={styles.header}>
<Text style={[styles.username, { color: themes[theme].tintColor }]}>{useRealName ? message.u?.name : message.u?.username}</Text>
2019-12-04 16:39:53 +00:00
<Text style={[styles.time, { color: themes[theme].auxiliaryText }]}>{time}</Text>
</View>
2019-12-04 16:39:53 +00:00
<Markdown
msg={message.msg}
baseUrl={baseUrl}
username={username}
getCustomEmoji={getCustomEmoji}
numberOfLines={1}
preview
theme={theme}
/>
</View>
2020-07-27 19:53:33 +00:00
<CustomIcon name='close' color={themes[theme].auxiliaryText} size={20} style={styles.close} onPress={close} />
</View>
);
}, (prevProps, nextProps) => prevProps.replying === nextProps.replying && prevProps.theme === nextProps.theme && prevProps.message.id === nextProps.message.id);
ReplyPreview.propTypes = {
replying: PropTypes.bool,
message: PropTypes.object.isRequired,
Message_TimeFormat: PropTypes.string.isRequired,
close: PropTypes.func.isRequired,
baseUrl: PropTypes.string.isRequired,
username: PropTypes.string.isRequired,
2019-12-04 16:39:53 +00:00
getCustomEmoji: PropTypes.func,
theme: PropTypes.string,
useRealName: PropTypes.bool
};
const mapStateToProps = state => ({
Message_TimeFormat: state.settings.Message_TimeFormat,
baseUrl: state.server.server,
useRealName: state.settings.UI_Use_Real_Name
});
export default connect(mapStateToProps)(ReplyPreview);