2021-02-01 23:59:34 +01:00
|
|
|
// @flow
|
2022-02-23 18:36:55 +01:00
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
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) => {
|
2022-02-23 18:36:55 +01:00
|
|
|
const { hideReleaseVersion } = props;
|
|
|
|
const [releaseTag, setReleaseTag] = useState('');
|
|
|
|
const [releaseChanges, setReleaseChanges] = useState('');
|
|
|
|
const [fetchingReleaseChanges, setFetchingReleaseChanges] = useState(false);
|
|
|
|
const [fetchReleaseFailed, setFetchReleaseFailed] = useState(false);
|
2021-02-01 23:59:34 +01:00
|
|
|
|
|
|
|
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 })}
|
2021-02-01 23:59:34 +01:00
|
|
|
</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/latest';
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (fetchingReleaseChanges) {
|
|
|
|
return <p>{__('Loading...')}</p>;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fetchReleaseFailed) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{releaseVersionTitle}
|
|
|
|
{seeReleaseNotes}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-01 23:59:34 +01:00
|
|
|
return (
|
2021-03-18 23:16:08 +01:00
|
|
|
<div className="release__notes">
|
2021-02-01 23:59:34 +01:00
|
|
|
{releaseVersionTitle}
|
2022-02-23 18:36:55 +01:00
|
|
|
<p>
|
|
|
|
<MarkdownPreview content={releaseChanges} />
|
|
|
|
</p>
|
2021-02-01 23:59:34 +01:00
|
|
|
{seeReleaseNotes}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default LastReleaseChanges;
|