-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathAgendaCountdown.tsx
More file actions
50 lines (43 loc) · 1.54 KB
/
AgendaCountdown.tsx
File metadata and controls
50 lines (43 loc) · 1.54 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 { TableCellValue } from 'mobx-lark';
import { observer } from 'mobx-react';
import { FC, useContext, useState } from 'react';
import { Countdown, TimeUnit } from 'idea-react';
import { Agenda } from '../../../models/Hackathon';
import { I18nContext } from '../../../models/Translation';
import styles from './AgendaCountdown.module.less';
import { agendaTypeLabelOf, resolveCountdownState } from './utility';
export interface AgendaCountdownProps {
agendaItems: Agenda[];
endTime?: TableCellValue;
startTime?: TableCellValue;
units: TimeUnit[];
}
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}
itemClassName={`${styles.item} d-flex flex-column align-items-center justify-content-center`}
endTime={countdownTo}
onEnd={() => setReferenceTime(Date.now())}
units={units}
/>
</div>
);
},
);
export default AgendaCountdown;