Browse Source

Merge pull request #1065 from gre/fix/1061

Fixes #1061
master
Meriadec Pillet 7 years ago
committed by GitHub
parent
commit
1c233dadf6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 47
      src/components/modals/ReleaseNotes/ReleaseNotesBody.js

47
src/components/modals/ReleaseNotes/ReleaseNotesBody.js

@ -2,7 +2,7 @@
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import styled from 'styled-components' import styled from 'styled-components'
import semver from 'semver'
import network from 'api/network' import network from 'api/network'
import Button from 'components/base/Button' import Button from 'components/base/Button'
@ -24,7 +24,8 @@ type Props = {
} }
type State = { type State = {
markdown: ?string, notes: *,
error: ?Error,
} }
const Title = styled(Text).attrs({ const Title = styled(Text).attrs({
@ -35,7 +36,8 @@ const Title = styled(Text).attrs({
class ReleaseNotesBody extends PureComponent<Props, State> { class ReleaseNotesBody extends PureComponent<Props, State> {
state = { state = {
markdown: null, notes: null,
error: null,
} }
componentDidMount() { componentDidMount() {
@ -45,33 +47,46 @@ class ReleaseNotesBody extends PureComponent<Props, State> {
fetchNotes = async (version: string) => { fetchNotes = async (version: string) => {
try { try {
const { const { data } = await network({
data: { body },
} = await network({
method: 'GET', method: 'GET',
url: `https://api.github.com/repos/LedgerHQ/ledger-live-desktop/releases/tags/v${version}`, url: 'https://api.github.com/repos/LedgerHQ/ledger-live-desktop/releases',
// `https://api.github.com/repos/LedgerHQ/ledger-live-desktop/releases/tags/v${version}`,
}) })
if (body) { const v = semver.parse(version)
this.setState({ markdown: body }) if (!v) throw new Error(`can't parse semver ${version}`)
} else { const notes = data.filter(
this.setState({ markdown: this.props.t('app:common.error.load') }) d =>
} semver.gte(
d.tag_name,
v.prerelease.length
? `${v.major}.${v.minor}.${v.patch}-${v.prerelease[0]}`
: `${v.major}.${v.minor}.0`,
) && semver.lte(d.tag_name, version),
)
this.setState({ notes })
} catch (error) { } catch (error) {
this.setState({ markdown: this.props.t('app:common.error.load') }) this.setState({ error })
} }
} }
renderContent = () => { renderContent = () => {
const { markdown } = this.state const { error, notes } = this.state
const { t } = this.props const { t } = this.props
const { version } = this.props const { version } = this.props
if (markdown) { if (notes) {
return notes.map(note => (
<Notes mb={6}>
<Title>{t('app:releaseNotes.version', { versionNb: note.tag_name })}</Title>
<Markdow>{note.body}</Markdow>
</Notes>
))
} else if (error) {
return ( return (
<Notes> <Notes>
<Title>{t('app:releaseNotes.version', { versionNb: version })}</Title> <Title>{t('app:releaseNotes.version', { versionNb: version })}</Title>
<Markdow>{markdown}</Markdow> <Markdow>{t('app:common.error.load')}</Markdow>
</Notes> </Notes>
) )
} }

Loading…
Cancel
Save