signal-desktop/ts/components/WhatsNewModal.tsx

103 lines
2.3 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { ReactChild } from 'react';
import React from 'react';
import moment from 'moment';
import { Modal } from './Modal';
import type { IntlComponentsType } from './Intl';
import { Intl } from './Intl';
import { Emojify } from './conversation/Emojify';
import type { LocalizerType, RenderTextCallbackType } from '../types/Util';
export type PropsType = {
hideWhatsNewModal: () => unknown;
i18n: LocalizerType;
};
type ReleaseNotesType = {
date: Date;
version: string;
features: Array<{ key: string; components: IntlComponentsType }>;
};
const renderText: RenderTextCallbackType = ({ key, text }) => (
<Emojify key={key} text={text} />
);
const releaseNotes: ReleaseNotesType = {
date: new Date(window.getBuildCreation?.() || Date.now()),
2021-12-02 16:51:04 +00:00
version: window.getVersion?.(),
2022-04-07 19:48:02 +00:00
features: [
2022-04-15 22:18:47 +00:00
{
2023-03-02 00:34:23 +00:00
key: 'icu:WhatsNew__v6.9--0',
2023-01-26 00:37:03 +00:00
components: undefined,
2022-10-07 18:34:27 +00:00
},
2023-02-23 18:04:33 +00:00
{
2023-03-02 00:34:23 +00:00
key: 'icu:WhatsNew__v6.9--1',
components: undefined,
2023-02-23 18:04:33 +00:00
},
{
2023-03-02 00:34:23 +00:00
key: 'icu:WhatsNew__v6.9--2',
components: undefined,
2023-02-23 18:04:33 +00:00
},
2022-04-07 19:48:02 +00:00
],
};
2022-11-18 00:45:19 +00:00
export function WhatsNewModal({
i18n,
hideWhatsNewModal,
2022-11-18 00:45:19 +00:00
}: PropsType): JSX.Element {
let contentNode: ReactChild;
if (releaseNotes.features.length === 1) {
const { key, components } = releaseNotes.features[0];
contentNode = (
<p>
{/* eslint-disable-next-line local-rules/valid-i18n-keys */}
<Intl
i18n={i18n}
id={key}
renderText={renderText}
components={components}
/>
</p>
);
} else {
contentNode = (
<ul>
{releaseNotes.features.map(({ key, components }) => (
<li key={key}>
{/* eslint-disable-next-line local-rules/valid-i18n-keys */}
<Intl
i18n={i18n}
id={key}
renderText={renderText}
components={components}
/>
</li>
))}
</ul>
);
}
return (
<Modal
2022-09-27 20:24:21 +00:00
modalName="WhatsNewModal"
hasXButton
i18n={i18n}
onClose={hideWhatsNewModal}
title={i18n('WhatsNew__modal-title')}
>
<>
<span>
{moment(releaseNotes.date).format('LL')} &middot;{' '}
{releaseNotes.version}
</span>
{contentNode}
</>
</Modal>
);
2022-11-18 00:45:19 +00:00
}