From 18a6da310f7f9fe692de012fbaf6ddc48b52eb56 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Wed, 29 Mar 2023 09:47:06 -0700 Subject: [PATCH] Adjust copy in loading screen --- _locales/en/messages.json | 14 ++++++++--- ts/components/Inbox.stories.tsx | 10 ++++---- ts/components/Inbox.tsx | 41 +++++++++++++++++++++++---------- 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 0257573c29..6dc6939083 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -399,9 +399,17 @@ "message": "Loading messages. $count$ so far...", "description": "(deleted 03/25/2023) Message shown on the loading screen when we're catching up on the backlog of messages" }, - "icu:loadingMessages": { - "messageformat": "Loading messages from {daysAgo, plural, one {1 day} other {# days}} ago...", - "description": "Message shown on the loading screen when we're catching up on the backlog of messages" + "icu:loadingMessages--other": { + "messageformat": "Loading messages from {daysAgo} days ago...", + "description": "Message shown on the loading screen when we're catching up on the backlog of messages from day before yesterday and earlier" + }, + "icu:loadingMessages--yesterday": { + "messageformat": "Loading messages from yesterday...", + "description": "Message shown on the loading screen when we're catching up on the backlog of messages from yesterday" + }, + "icu:loadingMessages--today": { + "messageformat": "Loading messages from today...", + "description": "Message shown on the loading screen when we're catching up on the backlog of messages from today" }, "view": { "message": "View", diff --git a/ts/components/Inbox.stories.tsx b/ts/components/Inbox.stories.tsx index 06106abae1..29f6306556 100644 --- a/ts/components/Inbox.stories.tsx +++ b/ts/components/Inbox.stories.tsx @@ -55,16 +55,18 @@ const Template: Story = ({ ...args }) => { const now = useMemo(() => Date.now(), []); - const [offset, setOffset] = useState(0); + const [dayOffset, setDayOffset] = useState(0); useEffect(() => { if (daysAgo === undefined) { - setOffset(0); + setDayOffset(0); return noop; } const interval = setInterval(() => { - setOffset(prevValue => (prevValue + 1 / 4) % daysAgo); + // Increment day offset by 1 / 24 of a day (an hour), and wrap it when it + // reaches `daysAgo` value. + setDayOffset(prevValue => (prevValue + 1 / 24) % daysAgo); }, SECOND / 10); return () => clearInterval(interval); @@ -75,7 +77,7 @@ const Template: Story = ({ const envelopeTimestamp = firstEnvelopeTimestamp === undefined ? undefined - : firstEnvelopeTimestamp + offset * DAY; + : firstEnvelopeTimestamp + dayOffset * DAY; return ( Date.now(), []); + const midnight = useMemo(() => { + const date = new Date(now); + date.setHours(0); + date.setMinutes(0); + date.setSeconds(0); + date.setMilliseconds(0); + return date.getTime(); + }, [now]); + useEffect(() => { if (prevConversationId !== selectedConversationId) { if (prevConversationId) { @@ -176,7 +186,6 @@ export function Inbox({ }, [hasInitialLoadCompleted]); if (!internalHasInitialLoadCompleted) { - const now = Date.now(); let loadingProgress = 0; if ( firstEnvelopeTimestamp !== undefined && @@ -193,6 +202,23 @@ export function Inbox({ ) * 100; } + let message = i18n('loading'); + if (envelopeTimestamp !== undefined) { + const daysBeforeMidnight = Math.ceil( + (midnight - envelopeTimestamp) / DAY + ); + + if (daysBeforeMidnight <= 0) { + message = i18n('icu:loadingMessages--today'); + } else if (daysBeforeMidnight === 1) { + message = i18n('icu:loadingMessages--yesterday'); + } else { + message = i18n('icu:loadingMessages--other', { + daysAgo: daysBeforeMidnight, + }); + } + } + return (
@@ -204,16 +230,7 @@ export function Inbox({ style={{ transform: `translateX(${loadingProgress - 100}%)` }} />
-
- {envelopeTimestamp - ? i18n('icu:loadingMessages', { - daysAgo: Math.max( - 1, - Math.round((now - envelopeTimestamp) / DAY) - ), - }) - : i18n('loading')} -
+
{message}
);