Browse Source

Use a suspense-like pattern

master
Thibaut Boustany 7 years ago
parent
commit
7a4a4b7511
No known key found for this signature in database GPG Key ID: 32475B11A2B13EEC
  1. 6
      src/components/UpdateNotifier/UpdateInstalled.js
  2. 38
      src/components/modals/ReleaseNotes.js

6
src/components/UpdateNotifier/UpdateInstalled.js

@ -37,12 +37,6 @@ class UpdateInstalled extends PureComponent<Props> {
}
}
showModal = ({ data }) => {
const { openModal } = this.props
openModal(MODAL_RELEASES_NOTES, data)
}
render() {
return null
}

38
src/components/modals/ReleaseNotes.js

@ -21,6 +21,7 @@ type Props = {
type State = {
markdown: ?string,
loading: boolean,
}
const Notes = styled(Box).attrs({
@ -150,14 +151,11 @@ const Title = styled(Text).attrs({
class ReleaseNotes extends PureComponent<Props, State> {
state = {
markdown: null,
loading: false,
}
render() {
const { t } = this.props
const renderBody = ({ data, onClose }) => {
const version = data
const { markdown } = this.state
fetchNotes = version => {
if (!this.state.loading) {
axios
.get(`https://api.github.com/repos/LedgerHQ/ledger-live-desktop/releases/tags/v${version}`)
.then(response => {
@ -165,15 +163,23 @@ class ReleaseNotes extends PureComponent<Props, State> {
this.setState({
markdown: body,
loading: false,
})
})
}
}
const content = markdown ? (
<Notes>
<Title>{t('releaseNotes:version', { versionNb: version })}</Title>
<ReactMarkdown>{markdown}</ReactMarkdown>
</Notes>
) : (
render() {
const { t } = this.props
const renderBody = ({ data, onClose }) => {
const version = data
const { markdown } = this.state
let content
if (!markdown) {
this.fetchNotes(version)
content = (
<Box horizontal alignItems="center">
<Spinner
size={32}
@ -183,6 +189,14 @@ class ReleaseNotes extends PureComponent<Props, State> {
/>
</Box>
)
} else {
content = (
<Notes>
<Title>{t('releaseNotes:version', { versionNb: version })}</Title>
<ReactMarkdown>{markdown}</ReactMarkdown>
</Notes>
)
}
return (
<ModalBody onClose={onClose}>

Loading…
Cancel
Save