signal-desktop/ts/components/WhatsNew.tsx

83 lines
2.2 KiB
TypeScript
Raw Normal View History

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React, { useState } from 'react';
import moment from 'moment';
import { Modal } from './Modal';
2021-09-22 01:01:14 +00:00
import { Intl, IntlComponentsType } from './Intl';
2021-08-26 20:41:43 +00:00
import { Emojify } from './conversation/Emojify';
import { LocalizerType } from '../types/Util';
export type PropsType = {
i18n: LocalizerType;
};
type ReleaseNotesType = {
date: Date;
version: string;
2021-09-22 01:01:14 +00:00
features: Array<{ key: string; components: IntlComponentsType }>;
};
export const WhatsNew = ({ i18n }: PropsType): JSX.Element => {
const [releaseNotes, setReleaseNotes] = useState<
ReleaseNotesType | undefined
>();
const viewReleaseNotes = () => {
setReleaseNotes({
date: new Date(window.getBuildCreation?.() || Date.now()),
version: window.getVersion(),
2021-09-22 01:01:14 +00:00
features: [
2021-09-30 00:10:38 +00:00
{ key: 'WhatsNew__v5.19--1', components: undefined },
{ key: 'WhatsNew__v5.19--2', components: undefined },
{ key: 'WhatsNew__v5.19--3', components: undefined },
2021-09-30 16:38:59 +00:00
{ key: 'WhatsNew__v5.19--4', components: undefined },
2021-09-22 01:01:14 +00:00
],
});
};
return (
<>
{releaseNotes && (
<Modal
hasXButton
i18n={i18n}
onClose={() => setReleaseNotes(undefined)}
title={i18n('WhatsNew__modal-title')}
>
<>
<span>
{moment(releaseNotes.date).format('LL')} &middot;{' '}
{releaseNotes.version}
</span>
<ul>
2021-09-22 01:01:14 +00:00
{releaseNotes.features.map(({ key, components }) => (
<li key={key}>
2021-08-26 20:41:43 +00:00
<Intl
i18n={i18n}
2021-09-22 01:01:14 +00:00
id={key}
renderText={({ key: innerKey, text }) => (
<Emojify key={innerKey} text={text} />
2021-08-26 20:41:43 +00:00
)}
2021-09-22 01:01:14 +00:00
components={components}
2021-08-26 20:41:43 +00:00
/>
</li>
))}
</ul>
</>
</Modal>
)}
<Intl
i18n={i18n}
id="whatsNew"
components={[
<button className="WhatsNew" type="button" onClick={viewReleaseNotes}>
{i18n('viewReleaseNotes')}
</button>,
]}
/>
</>
);
};