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. 56
      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() { render() {
return null return null
} }

56
src/components/modals/ReleaseNotes.js

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

Loading…
Cancel
Save