import React, {Component} from 'react'; import Link from '../base/Link'; import Modal from '../base/Modal'; import ModalBody from '../base/ModalBody'; import ModalHeader from '../base/ModalHeader'; import ModalFooter from '../base/ModalFooter'; import {getAppVersion, CHANGELOG_URL, CHANGELOG_PAGE} from '../../../common/constants'; 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}); } } async componentDidMount () { let changelog; try { const response = await fetch(`${CHANGELOG_URL}?bust=${Date.now()}`); changelog = await response.json(); } catch (e) { console.warn('Failed to fetch changelog', e); return; } this.setState({changelog}); } shouldComponentUpdate (nextProps, nextState) { return nextState !== this.state; } render () { const {changelog, startVersion} = this.state; let html; if (!changelog) { html = [
]; } else { html = []; let startIndex = changelog.findIndex(c => c.version === startVersion); if (startIndex < 0) { startIndex = 0; console.warn(`Failed to find changelog version for ${startVersion}`) } changelog.slice(startIndex).map((change, i) => { 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, j) =>

{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 ( this.modal = m} {...this.props}> Insomnia Changelog {html} Visit Full Changelog ); } } ChangelogModal.propTypes = {}; export default ChangelogModal;