signal-desktop/ts/components/WhatsNewModal.tsx

85 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-01-03 11:55:46 -08: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 { 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<JSX.Element>;
};
const renderText: RenderTextCallbackType = ({ key, text }) => (
<Emojify key={key} text={text} />
);
2022-11-17 16:45:19 -08:00
export function WhatsNewModal({
i18n,
hideWhatsNewModal,
2022-11-17 16:45:19 -08:00
}: PropsType): JSX.Element {
let contentNode: ReactChild;
const releaseNotes: ReleaseNotesType = {
date: new Date(window.getBuildCreation?.() || Date.now()),
version: window.getVersion?.(),
features: [
2023-05-10 21:39:54 +02:00
<Intl i18n={i18n} id="icu:WhatsNew__v6.18--0" renderText={renderText} />,
<Intl i18n={i18n} id="icu:WhatsNew__v6.18--1" renderText={renderText} />,
<Intl i18n={i18n} id="icu:WhatsNew__v6.18--2" renderText={renderText} />,
<Intl i18n={i18n} id="icu:WhatsNew__v6.18--3" renderText={renderText} />,
<Intl
i18n={i18n}
id="icu:WhatsNew__v6.18--4"
renderText={renderText}
components={{
yusufsahinhamza: (
<a href="https://github.com/yusufsahinhamza">@yusufsahinhamza</a>
),
}}
/>,
],
};
if (releaseNotes.features.length === 1) {
contentNode = <p>{releaseNotes.features[0]}</p>;
} else {
contentNode = (
<ul>
{releaseNotes.features.map(element => {
return <li key={element.props.id}>{element}</li>;
})}
</ul>
);
}
return (
<Modal
2022-09-27 13:24:21 -07:00
modalName="WhatsNewModal"
hasXButton
i18n={i18n}
onClose={hideWhatsNewModal}
2023-03-29 17:03:25 -07:00
title={i18n('icu:WhatsNew__modal-title')}
>
<>
<span>
{moment(releaseNotes.date).format('LL')} &middot;{' '}
{releaseNotes.version}
</span>
{contentNode}
</>
</Modal>
);
2022-11-17 16:45:19 -08:00
}