import React, {PureComponent} from 'react'; import autobind from 'autobind-decorator'; import Link from '../base/link'; import Modal from '../base/modal'; import ModalBody from '../base/modal-body'; import ModalHeader from '../base/modal-header'; import ModalFooter from '../base/modal-footer'; import {getAppVersion, CHANGELOG_URL, CHANGELOG_PAGE} from '../../../common/constants'; @autobind class ChangelogModal extends PureComponent { constructor (props) { super(props); this.state = { changelog: null }; } _setModalRef (m) { this.modal = m; } show () { this.modal.show(); } hide () { this.modal.hide(); } toggle () { this.modal.toggle(); } async componentDidMount () { let changelog; try { // TODO: Implement release channels // NOTE: We add current version to break CDN cache const response = await window.fetch(`${CHANGELOG_URL}?v=${getAppVersion()}&channel=stable`); changelog = await response.json(); } catch (e) { console.warn('Failed to fetch changelog', e); return; } this.setState({changelog}); } render () { const {changelog} = this.state; let html; if (!changelog) { html = [
{change.summary}
]; } else { html = [ ...html,{change.summary[0]}
, ...change.summary.slice(1).map( (text, j) =>{text}
) ]; } } if (change.link) { html = [ ...html, Read More ]; } const printThing = (text, key) => { const match = text.match(/\(PR:(\d+)(:([^)]+))?\)/); let link = null; if (match) { const prNumber = match[1]; const user = match[3] || ''; text = text.replace(match[0], ''); link = ( #{prNumber} {user ? ` by ${user}` : null} ); } return