import React from 'react';
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
import PropTypes from 'prop-types';
import moment from 'moment';
import Markdown from './Markdown';
import QuoteMark from './QuoteMark';
import Avatar from '../Avatar';
import openLink from '../../utils/openLink';
const styles = StyleSheet.create({
button: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
marginTop: 2,
alignSelf: 'flex-end'
},
attachmentContainer: {
flex: 1,
flexDirection: 'column'
},
authorContainer: {
flexDirection: 'row',
alignItems: 'center'
},
author: {
fontWeight: 'bold',
marginHorizontal: 5,
flex: 1
},
time: {
fontSize: 10,
fontWeight: 'normal',
color: '#888',
marginLeft: 5
},
fieldsContainer: {
flex: 1,
flexWrap: 'wrap',
flexDirection: 'row'
},
fieldContainer: {
flexDirection: 'column',
padding: 10
},
fieldTitle: {
fontWeight: 'bold'
}
});
const onPress = (attachment) => {
const url = attachment.title_link || attachment.author_link;
if (!url) {
return;
}
openLink(attachment.title_link || attachment.author_link);
};
const Reply = ({ attachment, timeFormat }) => {
if (!attachment) {
return null;
}
const renderAvatar = () => {
if (!attachment.author_icon && !attachment.author_name) {
return null;
}
return (
);
};
const renderAuthor = () => (
attachment.author_name ? {attachment.author_name} : null
);
const renderTime = () => {
const time = attachment.ts ? moment(attachment.ts).format(timeFormat) : null;
return time ? { time } : null;
};
const renderTitle = () => {
if (!(attachment.author_icon || attachment.author_name || attachment.ts)) {
return null;
}
return (
{renderAvatar()}
{renderAuthor()}
{renderTime()}
);
};
const renderText = () => (
attachment.text ? : null
);
const renderFields = () => {
if (!attachment.fields) {
return null;
}
return (
{attachment.fields.map(field => (
{field.title}
{field.value}
))}
);
};
return (
onPress(attachment)}
style={styles.button}
>
{renderTitle()}
{renderText()}
{renderFields()}
{attachment.attachments ?
attachment.attachments
.map(attach => )
: null
}
);
};
Reply.propTypes = {
attachment: PropTypes.object.isRequired,
timeFormat: PropTypes.string.isRequired
};
export default Reply;