Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-message-separator-today-label.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/livechat': patch
---

fix(livechat): show "Today"/"Yesterday" labels in message date separator instead of full date
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isToday, isYesterday } from 'date-fns';
import type { TFunction } from 'i18next';
import type { CSSProperties } from 'preact/compat';
import { memo } from 'preact/compat';
Expand All @@ -15,6 +16,16 @@ type MessageSeparatorProps = {
use?: any;
};

const formatDateLabel = (date: string, t: TFunction): string => {
const d = new Date(date);
if (isToday(d)) return t('today').toUpperCase();
if (isYesterday(d)) return t('yesterday').toUpperCase();
return t('message_separator_date', {
val: d,
formatParams: { val: { month: 'short', day: '2-digit', year: 'numeric' } },
}).toUpperCase();
};

// TODO: find a better way to pass `use` and do not default to a string
// eslint-disable-next-line @typescript-eslint/naming-convention
const MessageSeparator = ({ date, unread, use: Element = 'div', className, style = {}, t }: MessageSeparatorProps) => (
Expand All @@ -33,14 +44,7 @@ const MessageSeparator = ({ date, unread, use: Element = 'div', className, style
<hr className={createClassName(styles, 'separator__line')} />
{(date || unread) && (
<span className={createClassName(styles, 'separator__text')}>
{(!!date &&
t('message_separator_date', {
val: new Date(date),
formatParams: {
val: { month: 'short', day: '2-digit', year: 'numeric' },
},
}).toUpperCase()) ||
(unread && t('unread_messages'))}
{(!!date && formatDateLabel(date, t)) || (unread && t('unread_messages'))}
</span>
)}
<hr className={createClassName(styles, 'separator__line')} />
Expand Down
2 changes: 2 additions & 0 deletions packages/livechat/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
"message": "Message",
"messages": "Messages",
"message_separator_date": "{{val, datetime}}",
"today": "Today",
"yesterday": "Yesterday",
"message_time": "{{val, datetime}}",
"minimize_chat": "Minimize chat",
"name": "Name",
Expand Down