import React 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 ModalComponent from './lib/ModalComponent'; import {CHANGELOG_URL} from '../lib/constants'; class ChangelogModal extends ModalComponent { constructor (props) { super(props); this.state = { startVersion: null, changelog: null }; } show (startVersion) { super.show(); request.get(CHANGELOG_URL, (err, response) => { if (err) { console.error('Failed to load changelog', err); return; } let changelog; try { changelog = JSON.parse(response.body); } catch (e) { console.error('Failed to parse changelog', e); return; } this.setState({changelog, startVersion}); }); } render () { const {changelog, startVersion} = this.state; let html; if (!changelog) { html = [
]; } else { html = []; changelog.map(change => { html = [ ...html,

v{change.version} Changes

]; if (change.summary) { if (!Array.isArray(change.summary)) { html = [ ...html,

{change.summary}

] } else { html = [ ...html,

{change.summary[0]}

, ...change.summary.slice(1).map(text =>

{text}

) ] } } if (change.major && change.major.length) { html = [ ...html,

Noteworthy

, ]; } if (change.fixes && change.fixes.length) { html = [ ...html,

Fixes

, ]; } if (change.minor && change.minor.length) { html = [ ...html,

Minor Changes

, ]; } html = [ ...html,
] }); } return ( Insomnia Changelog {html}
); } } ChangelogModal.propTypes = {}; export default ChangelogModal;