2018-06-01 17:56:59 +00:00
|
|
|
import React from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { StyleSheet, Text, View } from 'react-native';
|
2018-06-01 17:56:59 +00:00
|
|
|
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';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2022-03-02 14:18:01 +00:00
|
|
|
import { useTheme } from '../../theme';
|
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-04 16:39:53 +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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
const DateSeparator = ({ ts, unread }: { ts: Date | string | null; unread: boolean }): React.ReactElement => {
|
|
|
|
const { theme } = useTheme();
|
2020-10-30 17:35:07 +00:00
|
|
|
const date = ts ? moment(ts).format('LL') : null;
|
2019-12-04 16:39:53 +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-04 16:39:53 +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-04 16:39:53 +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-04 16:39:53 +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>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DateSeparator;
|