Display release changes from release notes instead of using GitHub's API.

This commit is contained in:
Franco Montenegro 2022-02-21 12:01:02 -03:00 committed by jessopb
parent 3058dbb4a6
commit 080eee7d92
7 changed files with 29 additions and 49 deletions

View file

@ -1,3 +1,12 @@
import { connect } from 'react-redux';
import { selectRemoteVersion, selectReleaseNotes } from 'redux/selectors/app';
import LastReleaseChanges from './view'; import LastReleaseChanges from './view';
export default LastReleaseChanges; const select = (state) => ({
releaseVersion: selectRemoteVersion(state),
releaseNotes: selectReleaseNotes(state),
});
const perform = () => ({});
export default connect(select, perform)(LastReleaseChanges);

View file

@ -1,23 +1,21 @@
// @flow // @flow
import React, { useState, useEffect } from 'react'; import React from 'react';
import MarkdownPreview from 'component/common/markdown-preview';
import Button from 'component/button'; import Button from 'component/button';
import I18nMessage from 'component/i18nMessage'; import I18nMessage from 'component/i18nMessage';
type Props = { type Props = {
hideReleaseVersion?: boolean, hideReleaseVersion?: boolean,
releaseVersion: string,
releaseNotes: string,
}; };
const LastReleaseChanges = (props: Props) => { const LastReleaseChanges = (props: Props) => {
const { hideReleaseVersion } = props; const { hideReleaseVersion, releaseVersion, releaseNotes } = props;
const [releaseTag, setReleaseTag] = useState('');
const [releaseChanges, setReleaseChanges] = useState('');
const [fetchingReleaseChanges, setFetchingReleaseChanges] = useState(false);
const [fetchReleaseFailed, setFetchReleaseFailed] = useState(false);
const releaseVersionTitle = ( const releaseVersionTitle = (
<p> <p>
{!hideReleaseVersion && __('A new version %release_tag% of LBRY is ready for you.', { release_tag: releaseTag })} {!hideReleaseVersion &&
__('A new version %release_tag% of LBRY is ready for you.', { release_tag: releaseVersion })}
</p> </p>
); );
const seeReleaseNotes = ( const seeReleaseNotes = (
@ -34,47 +32,10 @@ const LastReleaseChanges = (props: Props) => {
</p> </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)
.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>
);
}
return ( return (
<div className="release__notes"> <div className="release__notes">
{releaseVersionTitle} {releaseVersionTitle}
<p> <p className="last-release-changes" dangerouslySetInnerHTML={{ __html: releaseNotes }} />
<MarkdownPreview content={releaseChanges} />
</p>
{seeReleaseNotes} {seeReleaseNotes}
</div> </div>
); );

View file

@ -117,12 +117,13 @@ ipcRenderer.on('open-uri-requested', (event, url, newSession) => {
handleError(); handleError();
}); });
autoUpdater.on('update-available', ({ version }) => { autoUpdater.on('update-available', (e) => {
app.store.dispatch({ app.store.dispatch({
type: ACTIONS.CHECK_UPGRADE_SUCCESS, type: ACTIONS.CHECK_UPGRADE_SUCCESS,
data: { data: {
upgradeAvailable: true, upgradeAvailable: true,
remoteVersion: version, remoteVersion: e.releaseName || e.version,
releaseNotes: e.releaseNotes,
}, },
}); });
}); });

View file

@ -201,6 +201,7 @@ reducers[ACTIONS.CHECK_UPGRADE_SUCCESS] = (state, action) =>
Object.assign({}, state, { Object.assign({}, state, {
isUpgradeAvailable: action.data.upgradeAvailable, isUpgradeAvailable: action.data.upgradeAvailable,
remoteVersion: action.data.remoteVersion, remoteVersion: action.data.remoteVersion,
releaseNotes: action.data.releaseNotes,
}); });
reducers[ACTIONS.CHECK_UPGRADE_SUBSCRIBE] = (state, action) => reducers[ACTIONS.CHECK_UPGRADE_SUBSCRIBE] = (state, action) =>

View file

@ -23,6 +23,8 @@ export const selectHasClickedComment = createSelector(selectState, (state) => st
export const selectRemoteVersion = createSelector(selectState, (state) => state.remoteVersion); export const selectRemoteVersion = createSelector(selectState, (state) => state.remoteVersion);
export const selectReleaseNotes = createSelector(selectState, (state) => state.releaseNotes);
export const selectIsUpgradeAvailable = createSelector(selectState, (state) => state.isUpgradeAvailable); export const selectIsUpgradeAvailable = createSelector(selectState, (state) => state.isUpgradeAvailable);
export const selectUpgradeFilename = createSelector(selectPlatform, selectRemoteVersion, (platform, version) => { export const selectUpgradeFilename = createSelector(selectPlatform, selectRemoteVersion, (platform, version) => {

View file

@ -70,3 +70,4 @@
@import 'component/utils'; @import 'component/utils';
@import 'component/settings'; @import 'component/settings';
@import 'component/embed-player'; @import 'component/embed-player';
@import 'component/last-release-changes';

View file

@ -0,0 +1,5 @@
.last-release-changes {
a {
@extend .button--link;
}
}