lbry-desktop/ui/component/lastReleaseChanges/view.jsx

85 lines
2.4 KiB
React
Raw Normal View History

// @flow
2022-02-23 18:36:55 +01:00
import React, { useState, useEffect } from 'react';
import MarkdownPreview from 'component/common/markdown-preview';
import Button from 'component/button';
import I18nMessage from 'component/i18nMessage';
type Props = {
releaseVersion: string,
hideReleaseVersion?: boolean,
};
const LastReleaseChanges = (props: Props) => {
const { hideReleaseVersion, releaseVersion } = props;
2022-02-23 18:36:55 +01:00
const [releaseTag, setReleaseTag] = useState('');
const [releaseChanges, setReleaseChanges] = useState('');
const [fetchingReleaseChanges, setFetchingReleaseChanges] = useState(false);
const [fetchReleaseFailed, setFetchReleaseFailed] = useState(false);
const releaseVersionTitle = (
<p>
2022-02-23 18:36:55 +01:00
{!hideReleaseVersion && __('A new version %release_tag% of LBRY is ready for you.', { release_tag: releaseTag })}
</p>
);
const seeReleaseNotes = (
<p className="help">
<I18nMessage
tokens={{
release_notes: (
<Button button="link" label={__('release notes')} href="https://github.com/lbryio/lbry-desktop/releases" />
),
}}
>
Want to know what has changed? See the %release_notes%.
</I18nMessage>
</p>
);
2022-02-23 18:36:55 +01:00
useEffect(() => {
const lastReleaseUrl = `https://api.github.com/repos/lbryio/lbry-desktop/releases/tags/${releaseVersion}`;
2022-02-23 18:36:55 +01:00
const options = {
method: 'GET',
headers: { Accept: 'application/vnd.github.v3+json' },
};
setFetchingReleaseChanges(true);
fetch(lastReleaseUrl, options)
.then((response) => response.json())
.then((response) => {
setReleaseTag(response.tag_name);
setReleaseChanges(response.body);
setFetchingReleaseChanges(false);
setFetchReleaseFailed(false);
})
.catch(() => {
setFetchingReleaseChanges(false);
setFetchReleaseFailed(true);
});
}, [releaseVersion, setFetchingReleaseChanges, setReleaseTag, setReleaseChanges, setFetchReleaseFailed]);
2022-02-23 18:36:55 +01:00
if (fetchingReleaseChanges) {
return <p>{__('Loading...')}</p>;
}
if (fetchReleaseFailed) {
return (
<div>
{releaseVersionTitle}
{seeReleaseNotes}
</div>
);
}
return (
<div className="release__notes">
{releaseVersionTitle}
2022-02-23 18:36:55 +01:00
<p>
<MarkdownPreview content={releaseChanges} />
</p>
{seeReleaseNotes}
</div>
);
};
export default LastReleaseChanges;