// @flow
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;
const [releaseTag, setReleaseTag] = useState('');
const [releaseChanges, setReleaseChanges] = useState('');
const [fetchingReleaseChanges, setFetchingReleaseChanges] = useState(false);
const [fetchReleaseFailed, setFetchReleaseFailed] = useState(false);
const releaseVersionTitle = (
{!hideReleaseVersion && __('A new version %release_tag% of LBRY is ready for you.', { release_tag: releaseTag })}
);
const seeReleaseNotes = (
),
}}
>
Want to know what has changed? See the %release_notes%.
);
useEffect(() => {
const lastReleaseUrl = `https://api.github.com/repos/lbryio/lbry-desktop/releases/tags/${releaseVersion}`;
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]);
if (fetchingReleaseChanges) {
return {__('Loading...')}
;
}
if (fetchReleaseFailed) {
return (
{releaseVersionTitle}
{seeReleaseNotes}
);
}
return (
{releaseVersionTitle}
{seeReleaseNotes}
);
};
export default LastReleaseChanges;