2018-06-01 17:56:59 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { View, StyleSheet, Text } from 'react-native';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import moment from 'moment';
|
2019-03-29 19:36:07 +00:00
|
|
|
|
2018-06-01 17:56:59 +00:00
|
|
|
import I18n from '../../i18n';
|
2019-03-29 19:36:07 +00:00
|
|
|
import sharedStyles from '../Styles';
|
2019-12-11 23:01:12 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2018-06-01 17:56:59 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
2019-03-27 20:06:57 +00:00
|
|
|
marginTop: 16,
|
|
|
|
marginBottom: 4,
|
|
|
|
marginHorizontal: 14
|
2018-06-01 17:56:59 +00:00
|
|
|
},
|
|
|
|
line: {
|
2018-09-11 16:32:52 +00:00
|
|
|
height: 1,
|
2018-06-01 17:56:59 +00:00
|
|
|
flex: 1
|
|
|
|
},
|
|
|
|
text: {
|
2018-09-11 16:32:52 +00:00
|
|
|
fontSize: 14,
|
2019-12-11 23:01:12 +00:00
|
|
|
...sharedStyles.textMedium
|
2018-09-11 16:32:52 +00:00
|
|
|
},
|
|
|
|
marginLeft: {
|
2019-03-29 19:36:07 +00:00
|
|
|
marginLeft: 14
|
2018-09-11 16:32:52 +00:00
|
|
|
},
|
|
|
|
marginRight: {
|
2019-03-29 19:36:07 +00:00
|
|
|
marginRight: 14
|
2018-09-11 16:32:52 +00:00
|
|
|
},
|
|
|
|
marginHorizontal: {
|
2019-03-29 19:36:07 +00:00
|
|
|
marginHorizontal: 14
|
2018-06-01 17:56:59 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-12-11 23:01:12 +00:00
|
|
|
const DateSeparator = React.memo(({ ts, unread, theme }) => {
|
2018-09-11 16:32:52 +00:00
|
|
|
const date = ts ? moment(ts).format('MMM DD, YYYY') : null;
|
2019-12-11 23:01:12 +00:00
|
|
|
const unreadLine = { backgroundColor: themes[theme].dangerColor };
|
|
|
|
const unreadText = { color: themes[theme].dangerColor };
|
2018-06-01 17:56:59 +00:00
|
|
|
if (ts && unread) {
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
2019-12-11 23:01:12 +00:00
|
|
|
<Text style={[styles.text, unreadText]}>{I18n.t('unread_messages')}</Text>
|
|
|
|
<View style={[styles.line, unreadLine, styles.marginHorizontal]} />
|
|
|
|
<Text style={[styles.text, unreadText]}>{date}</Text>
|
2018-06-01 17:56:59 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (ts) {
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
2019-12-11 23:01:12 +00:00
|
|
|
<View style={[styles.line, { backgroundColor: themes[theme].borderColor }]} />
|
|
|
|
<Text style={[styles.text, { color: themes[theme].auxiliaryText }, styles.marginLeft]}>{date}</Text>
|
2018-06-01 17:56:59 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
2019-12-11 23:01:12 +00:00
|
|
|
<Text style={[styles.text, unreadText, styles.marginRight]}>{I18n.t('unread_messages')}</Text>
|
|
|
|
<View style={[styles.line, unreadLine]} />
|
2018-06-01 17:56:59 +00:00
|
|
|
</View>
|
|
|
|
);
|
2019-03-27 20:06:57 +00:00
|
|
|
});
|
2018-06-01 17:56:59 +00:00
|
|
|
|
|
|
|
DateSeparator.propTypes = {
|
|
|
|
ts: PropTypes.instanceOf(Date),
|
2019-12-11 23:01:12 +00:00
|
|
|
unread: PropTypes.bool,
|
|
|
|
theme: PropTypes.string
|
2018-06-01 17:56:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default DateSeparator;
|