From f1a9c889b8bd18013419d4c64b39e23b8fe93106 Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 24 Dec 2021 14:41:33 +0000 Subject: [PATCH] fix(messaging): only show date if date changes --- src/components/ui/DateDivider.tsx | 10 +++++----- src/pages/channels/messaging/MessageRenderer.tsx | 10 +++++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/ui/DateDivider.tsx b/src/components/ui/DateDivider.tsx index b2d69031..5bbec51c 100644 --- a/src/components/ui/DateDivider.tsx +++ b/src/components/ui/DateDivider.tsx @@ -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 ( - - {props.unread && NEW} - + + {unread && NEW} + {date && } ); } diff --git a/src/pages/channels/messaging/MessageRenderer.tsx b/src/pages/channels/messaging/MessageRenderer.tsx index 7ed45c59..9b1577c8 100644 --- a/src/pages/channels/messaging/MessageRenderer.tsx +++ b/src/pages/channels/messaging/MessageRenderer.tsx @@ -104,6 +104,7 @@ export default observer(({ last_id, renderer, highlight }: Props) => { prevAuthor: string, previousMasq: Nullable, ) { + 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(); + date = adate; + } + + if (unread || date) { + render.push(); head = true; }