From 080eee7d92a72762138508b0424098265e23a4e0 Mon Sep 17 00:00:00 2001 From: Franco Montenegro Date: Mon, 21 Feb 2022 12:01:02 -0300 Subject: [PATCH] Display release changes from release notes instead of using GitHub's API. --- ui/component/lastReleaseChanges/index.js | 11 +++- ui/component/lastReleaseChanges/view.jsx | 53 +++----------------- ui/index.jsx | 5 +- ui/redux/reducers/app.js | 1 + ui/redux/selectors/app.js | 2 + ui/scss/all.scss | 1 + ui/scss/component/_last-release-changes.scss | 5 ++ 7 files changed, 29 insertions(+), 49 deletions(-) create mode 100644 ui/scss/component/_last-release-changes.scss diff --git a/ui/component/lastReleaseChanges/index.js b/ui/component/lastReleaseChanges/index.js index 2784fe4d6..a23d1e419 100644 --- a/ui/component/lastReleaseChanges/index.js +++ b/ui/component/lastReleaseChanges/index.js @@ -1,3 +1,12 @@ +import { connect } from 'react-redux'; +import { selectRemoteVersion, selectReleaseNotes } from 'redux/selectors/app'; import LastReleaseChanges from './view'; -export default LastReleaseChanges; +const select = (state) => ({ + releaseVersion: selectRemoteVersion(state), + releaseNotes: selectReleaseNotes(state), +}); + +const perform = () => ({}); + +export default connect(select, perform)(LastReleaseChanges); diff --git a/ui/component/lastReleaseChanges/view.jsx b/ui/component/lastReleaseChanges/view.jsx index a41d2c778..62d129538 100644 --- a/ui/component/lastReleaseChanges/view.jsx +++ b/ui/component/lastReleaseChanges/view.jsx @@ -1,23 +1,21 @@ // @flow -import React, { useState, useEffect } from 'react'; -import MarkdownPreview from 'component/common/markdown-preview'; +import React from 'react'; import Button from 'component/button'; import I18nMessage from 'component/i18nMessage'; type Props = { hideReleaseVersion?: boolean, + releaseVersion: string, + releaseNotes: string, }; 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 { hideReleaseVersion, releaseVersion, releaseNotes } = props; const releaseVersionTitle = (

- {!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 })}

); const seeReleaseNotes = ( @@ -34,47 +32,10 @@ const LastReleaseChanges = (props: Props) => {

); - 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

{__('Loading...')}

; - } - - if (fetchReleaseFailed) { - return ( -
- {releaseVersionTitle} - {seeReleaseNotes} -
- ); - } - return (
{releaseVersionTitle} -

- -

+

{seeReleaseNotes}

); diff --git a/ui/index.jsx b/ui/index.jsx index cf1589bc7..a3728bc87 100644 --- a/ui/index.jsx +++ b/ui/index.jsx @@ -117,12 +117,13 @@ ipcRenderer.on('open-uri-requested', (event, url, newSession) => { handleError(); }); -autoUpdater.on('update-available', ({ version }) => { +autoUpdater.on('update-available', (e) => { app.store.dispatch({ type: ACTIONS.CHECK_UPGRADE_SUCCESS, data: { upgradeAvailable: true, - remoteVersion: version, + remoteVersion: e.releaseName || e.version, + releaseNotes: e.releaseNotes, }, }); }); diff --git a/ui/redux/reducers/app.js b/ui/redux/reducers/app.js index 6b805dcca..3dfa90362 100644 --- a/ui/redux/reducers/app.js +++ b/ui/redux/reducers/app.js @@ -201,6 +201,7 @@ reducers[ACTIONS.CHECK_UPGRADE_SUCCESS] = (state, action) => Object.assign({}, state, { isUpgradeAvailable: action.data.upgradeAvailable, remoteVersion: action.data.remoteVersion, + releaseNotes: action.data.releaseNotes, }); reducers[ACTIONS.CHECK_UPGRADE_SUBSCRIBE] = (state, action) => diff --git a/ui/redux/selectors/app.js b/ui/redux/selectors/app.js index 4656d3c92..28d503392 100644 --- a/ui/redux/selectors/app.js +++ b/ui/redux/selectors/app.js @@ -23,6 +23,8 @@ export const selectHasClickedComment = createSelector(selectState, (state) => st 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 selectUpgradeFilename = createSelector(selectPlatform, selectRemoteVersion, (platform, version) => { diff --git a/ui/scss/all.scss b/ui/scss/all.scss index 9deafe5b0..7c8f807a6 100644 --- a/ui/scss/all.scss +++ b/ui/scss/all.scss @@ -70,3 +70,4 @@ @import 'component/utils'; @import 'component/settings'; @import 'component/embed-player'; +@import 'component/last-release-changes'; diff --git a/ui/scss/component/_last-release-changes.scss b/ui/scss/component/_last-release-changes.scss new file mode 100644 index 000000000..cd8d182ea --- /dev/null +++ b/ui/scss/component/_last-release-changes.scss @@ -0,0 +1,5 @@ +.last-release-changes { + a { + @extend .button--link; + } +}