2021-02-01 23:59:34 +01:00
|
|
|
// @flow
|
|
|
|
import React, { useState, useEffect } from 'react';
|
2021-02-02 22:34:21 +01:00
|
|
|
import MarkdownPreview from 'component/common/markdown-preview';
|
2021-02-01 23:59:34 +01:00
|
|
|
import Button from 'component/button';
|
|
|
|
import I18nMessage from 'component/i18nMessage';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
hideReleaseVersion?: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
const LastReleaseChanges = (props: Props) => {
|
|
|
|
const { hideReleaseVersion } = props;
|
|
|
|
const [releaseTag, setReleaseTag] = useState('');
|
|
|
|
const [releaseChanges, setReleaseChanges] = useState('');
|
|
|
|
const [fetchingReleaseChanges, setFetchingReleaseChanges] = useState(false);
|
|
|
|
const [fetchReleaseFailed, setFetchReleaseFailed] = useState(false);
|
|
|
|
|
|
|
|
const releaseVersionTitle = (
|
|
|
|
<p>
|
|
|
|
{!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>
|
|
|
|
);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const lastReleaseUrl = 'https://api.github.com/repos/lbryio/lbry-desktop/releases/latest';
|
|
|
|
const options = {
|
|
|
|
method: 'GET',
|
|
|
|
headers: { Accept: 'application/vnd.github.v3+json' },
|
|
|
|
};
|
|
|
|
|
|
|
|
setFetchingReleaseChanges(true);
|
|
|
|
fetch(lastReleaseUrl, options)
|
2021-03-18 23:16:08 +01:00
|
|
|
.then((response) => response.json())
|
|
|
|
.then((response) => {
|
2021-02-01 23:59:34 +01:00
|
|
|
setReleaseTag(response.tag_name);
|
|
|
|
setReleaseChanges(response.body);
|
|
|
|
setFetchingReleaseChanges(false);
|
|
|
|
setFetchReleaseFailed(false);
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
setFetchingReleaseChanges(false);
|
|
|
|
setFetchReleaseFailed(true);
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (fetchingReleaseChanges) {
|
|
|
|
return <p>{__('Loading...')}</p>;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fetchReleaseFailed) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{releaseVersionTitle}
|
|
|
|
{seeReleaseNotes}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-03-18 23:16:08 +01:00
|
|
|
<div className="release__notes">
|
2021-02-01 23:59:34 +01:00
|
|
|
{releaseVersionTitle}
|
|
|
|
<p>
|
2021-02-02 22:34:21 +01:00
|
|
|
<MarkdownPreview content={releaseChanges} />
|
2021-02-01 23:59:34 +01:00
|
|
|
</p>
|
|
|
|
{seeReleaseNotes}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default LastReleaseChanges;
|