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, isDevelopment} from '../../../common/constants'; import * as querystring from '../../../common/querystring'; @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 params = [ {name: 'v', value: getAppVersion()}, {name: 'channel', value: 'stable'} ]; // Add extra param during dev so we don't affect CDN cache if (isDevelopment()) { params.push({name: 'dev'}); } const qs = querystring.buildFromParams(params); const url = querystring.joinUrl(CHANGELOG_URL, qs); const response = await window.fetch(url); 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