-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathReminderNotification.tsx
More file actions
50 lines (44 loc) · 1.6 KB
/
ReminderNotification.tsx
File metadata and controls
50 lines (44 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React from 'react';
import { useTranslationContext } from '../../context';
import { useStateStore } from '../../store';
import type { Reminder, ReminderState } from 'stream-chat';
export type ReminderNotificationProps = {
reminder?: Reminder;
};
const reminderStateSelector = (state: ReminderState) => ({
timeLeftMs: state.timeLeftMs,
});
export const ReminderNotification = ({ reminder }: ReminderNotificationProps) => {
const { t } = useTranslationContext();
const { timeLeftMs } = useStateStore(reminder?.state, reminderStateSelector) ?? {};
const stopRefreshBoundaryMs = reminder?.timer.stopRefreshBoundaryMs;
const stopRefreshTimeStamp =
reminder?.remindAt && stopRefreshBoundaryMs
? reminder?.remindAt.getTime() + stopRefreshBoundaryMs
: undefined;
const isBehindRefreshBoundary =
!!stopRefreshTimeStamp && new Date().getTime() > stopRefreshTimeStamp;
return (
<p className='str-chat__message-reminder'>
<span>{t<string>('Saved for later')}</span>
{reminder?.remindAt && timeLeftMs !== null && (
<>
<span> | </span>
<span>
{isBehindRefreshBoundary
? t<string>('Due since {{ dueSince }}', {
dueSince: t<string>(`timestamp/ReminderNotification`, {
timestamp: reminder.remindAt,
}),
})
: t<string>(`Due {{ timeLeft }}`, {
timeLeft: t<string>('duration/Message reminder', {
milliseconds: timeLeftMs,
}),
})}
</span>
</>
)}
</p>
);
};