/
WhatsNewModal.tsx
80 lines (71 loc) · 1.82 KB
/
WhatsNewModal.tsx
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { ReactNode } from 'react';
import React from 'react';
import moment from 'moment';
import { Modal } from './Modal';
import { Intl } from './Intl';
import type { LocalizerType } from '../types/Util';
export type PropsType = {
hideWhatsNewModal: () => unknown;
i18n: LocalizerType;
};
type ReleaseNotesType = {
date: Date;
version: string;
header?: JSX.Element;
features: Array<JSX.Element>;
};
// Exported so it doesn't get marked unused
export function ExternalLink(props: {
href: string;
children: ReactNode;
}): JSX.Element {
return (
<a href={props.href} target="_blank" rel="noreferrer">
{props.children}
</a>
);
}
export function WhatsNewModal({
i18n,
hideWhatsNewModal,
}: PropsType): JSX.Element {
let contentNode: ReactNode;
const releaseNotes: ReleaseNotesType = {
date: new Date(window.getBuildCreation?.() || Date.now()),
version: window.getVersion?.(),
features: [<Intl i18n={i18n} id="icu:WhatsNew__v7.1--0" />],
};
if (releaseNotes.features.length === 1 && !releaseNotes.header) {
contentNode = <p>{releaseNotes.features[0]}</p>;
} else {
contentNode = (
<>
{releaseNotes.header ? <p>{releaseNotes.header}</p> : null}
<ul>
{releaseNotes.features.map(element => {
return <li key={element.props.id}>{element}</li>;
})}
</ul>
</>
);
}
return (
<Modal
modalName="WhatsNewModal"
hasXButton
i18n={i18n}
onClose={hideWhatsNewModal}
title={i18n('icu:WhatsNew__modal-title')}
>
<>
<span>
{moment(releaseNotes.date).format('LL')} ·{' '}
{releaseNotes.version}
</span>
{contentNode}
</>
</Modal>
);
}