-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathAgendaCountdown.tsx
More file actions
48 lines (41 loc) · 1.43 KB
/
AgendaCountdown.tsx
File metadata and controls
48 lines (41 loc) · 1.43 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
import { TableCellValue } from 'mobx-lark';
import { observer } from 'mobx-react';
import { FC, useContext, useState } from 'react';
import { Agenda } from '../../../models/Hackathon';
import { I18nContext } from '../../../models/Translation';
import { Countdown, TimeUnit } from '../../Base/Countdown';
import styles from './AgendaCountdown.module.less';
import { agendaTypeLabelOf, resolveCountdownState } from './utility';
export interface AgendaCountdownProps {
agendaItems: Agenda[];
endTime?: TableCellValue;
startTime?: TableCellValue;
units: TimeUnit[];
}
export const AgendaCountdown: FC<AgendaCountdownProps> = observer(
({ agendaItems, endTime, startTime, units }) => {
const { t } = useContext(I18nContext);
const [referenceTime, setReferenceTime] = useState(Date.now());
const { nextItem: nextAgendaItem, countdownTo } = resolveCountdownState(
agendaItems,
referenceTime,
startTime,
endTime,
);
if (!countdownTo) return null;
const countdownLabel = nextAgendaItem
? agendaTypeLabelOf(nextAgendaItem.type, t, t('agenda'))
: t('event_duration');
return (
<div className={styles.wrap}>
{countdownLabel && <p className={styles.label}>{countdownLabel}</p>}
<Countdown
className={styles.grid}
endTime={countdownTo}
onEnd={() => setReferenceTime(Date.now())}
units={units}
/>
</div>
);
},
);