import React, {Component} from 'react'; import request from 'request'; import Modal from '../base/Modal'; import ModalBody from '../base/ModalBody'; import ModalHeader from '../base/ModalHeader'; import ModalFooter from '../base/ModalFooter'; import {CHANGELOG_URL} from '../../../lib/constants'; import {getAppVersion} from '../../../lib/appInfo'; class ChangelogModal extends Component { constructor (props) { super(props); this.state = { startVersion: getAppVersion(), changelog: null }; } show (startVersion = null) { this.modal.show(); if (startVersion) { this.setState({startVersion}); } } componentDidMount () { request.get(CHANGELOG_URL, (err, response) => { if (err) { console.warn('Failed to load changelog', err); return; } if (response.statusCode !== 200) { console.warn( 'Failed to fetch changelog', response.statusCode, response.body ); return; } let changelog; try { changelog = JSON.parse(response.body); } catch (e) { console.error('Failed to parse changelog', e); return; } this.setState({changelog}); }); } shouldComponentUpdate (nextProps, nextState) { return nextState !== this.state; } render () { const {changelog, startVersion} = this.state; let html; if (!changelog) { html = [
, ...change.summary.slice(1).map( (text, j) => ) ] } } if (change.major && change.major.length) { html = [ ...html,