fix(messaging): only show date if date changes

This commit is contained in:
Paul 2021-12-24 14:41:33 +00:00
parent 3b6519c530
commit f1a9c889b8
2 changed files with 12 additions and 8 deletions

View file

@ -37,15 +37,15 @@ const Unread = styled.div`
`;
interface Props {
date: Date;
date?: Date;
unread?: boolean;
}
export default function DateDivider(props: Props) {
export default function DateDivider({ unread, date }: Props) {
return (
<Base unread={props.unread}>
{props.unread && <Unread>NEW</Unread>}
<time>{dayjs(props.date).format("LL")}</time>
<Base unread={unread}>
{unread && <Unread>NEW</Unread>}
{date && <time>{dayjs(date).format("LL")}</time>}
</Base>
);
}

View file

@ -104,6 +104,7 @@ export default observer(({ last_id, renderer, highlight }: Props) => {
prevAuthor: string,
previousMasq: Nullable<Masquerade>,
) {
head = false;
const atime = decodeTime(current),
adate = new Date(atime),
btime = decodeTime(previous),
@ -115,14 +116,17 @@ export default observer(({ last_id, renderer, highlight }: Props) => {
divided = true;
}
head = false;
let date;
if (
unread ||
adate.getFullYear() !== bdate.getFullYear() ||
adate.getMonth() !== bdate.getMonth() ||
adate.getDate() !== bdate.getDate()
) {
render.push(<DateDivider date={adate} unread={unread} />);
date = adate;
}
if (unread || date) {
render.push(<DateDivider date={date} unread={unread} />);
head = true;
}