Skip to content

Commit 3934e37

Browse files
authored
Merge pull request element-hq#1972 from aviraldg/feature-changelog
add fancy changelog dialog
2 parents 2ee4fa4 + 56813eb commit 3934e37

5 files changed

Lines changed: 140 additions & 16 deletions

File tree

‎src/component-index.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module.exports.components['structures.ViewSource'] = require('./components/struc
3737
module.exports.components['views.context_menus.MessageContextMenu'] = require('./components/views/context_menus/MessageContextMenu');
3838
module.exports.components['views.context_menus.NotificationStateContextMenu'] = require('./components/views/context_menus/NotificationStateContextMenu');
3939
module.exports.components['views.context_menus.RoomTagContextMenu'] = require('./components/views/context_menus/RoomTagContextMenu');
40+
module.exports.components['views.dialogs.ChangelogDialog'] = require('./components/views/dialogs/ChangelogDialog');
4041
module.exports.components['views.elements.ImageView'] = require('./components/views/elements/ImageView');
4142
module.exports.components['views.elements.Spinner'] = require('./components/views/elements/Spinner');
4243
module.exports.components['views.globals.GuestWarningBar'] = require('./components/views/globals/GuestWarningBar');
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Copyright 2016 Aviral Dasgupta
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React from 'react';
18+
import sdk from 'matrix-react-sdk';
19+
import 'whatwg-fetch';
20+
import request from 'browser-request';
21+
22+
const REPOS = ['vector-im/vector-web', 'matrix-org/matrix-react-sdk', 'matrix-org/matrix-js-sdk'];
23+
24+
export default class ChangelogDialog extends React.Component {
25+
constructor(props) {
26+
super(props);
27+
28+
this.state = {};
29+
}
30+
31+
componentDidMount() {
32+
const version = this.props.newVersion.split('-');
33+
const version2 = this.props.version.split('-');
34+
if(version == null || version2 == null) return;
35+
for(let i=0; i<REPOS.length; i++) {
36+
const oldVersion = version2[2*i+1];
37+
const newVersion = version[2*i+1];
38+
request(`https://api.github.com/repos/${REPOS[i]}/compare/${oldVersion}...${newVersion}`, (a, b, body) => {
39+
if(body == null) return;
40+
this.setState({[REPOS[i]]: JSON.parse(body).commits});
41+
});
42+
}
43+
}
44+
45+
render() {
46+
const Spinner = sdk.getComponent('views.elements.Spinner');
47+
const QuestionDialog = sdk.getComponent('dialogs.QuestionDialog');
48+
49+
const logs = REPOS.map(repo => {
50+
if (this.state[repo] == null) return <Spinner key={repo} />;
51+
return (
52+
<div key={repo}>
53+
<h2>{repo}</h2>
54+
{this.state[repo].map(commit =>
55+
<div key={commit.commit.url}><a href={commit.commit.url}>{commit.commit.message}</a></div>
56+
)}
57+
</div>
58+
)
59+
});
60+
61+
const content = (
62+
<div className="mx_ChangelogDialog_content">
63+
{this.props.version == null || this.props.newVersion == null ? <h2>Unavailable</h2> : logs}
64+
</div>
65+
);
66+
67+
68+
return (
69+
<QuestionDialog
70+
title="Changelog"
71+
description={content}
72+
button="Update"
73+
onFinished={this.props.onFinished}
74+
/>
75+
)
76+
}
77+
}
78+
79+
ChangelogDialog.propTypes = {
80+
version: React.PropTypes.string.isRequired,
81+
newVersion: React.PropTypes.string.isRequired,
82+
onFinished: React.PropTypes.func.isRequired,
83+
};

‎src/components/views/globals/NewVersionBar.js‎

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,36 @@ limitations under the License.
1717
'use strict';
1818

1919
var React = require('react');
20-
var sdk = require('matrix-react-sdk')
21-
22-
module.exports = React.createClass({
23-
displayName: 'NewVersionBar',
24-
25-
render: function() {
26-
return (
27-
<div className="mx_MatrixToolbar">
28-
<img className="mx_MatrixToolbar_warning" src="img/warning.svg" width="24" height="23" alt="/!\"/>
29-
<div>
30-
A new version of Vector is available. Refresh your browser.
31-
</div>
20+
var sdk = require('matrix-react-sdk');
21+
import Modal from 'matrix-react-sdk/lib/Modal';
22+
23+
export default function NewVersionBar(props) {
24+
const onChangelogClicked = () => {
25+
const ChangelogDialog = sdk.getComponent('dialogs.ChangelogDialog');
26+
27+
Modal.createDialog(ChangelogDialog, {
28+
version: props.version,
29+
newVersion: props.newVersion,
30+
onFinished: (update) => {
31+
if(update) {
32+
window.location.reload();
33+
}
34+
}
35+
});
36+
};
37+
38+
return (
39+
<div className="mx_MatrixToolbar">
40+
<img className="mx_MatrixToolbar_warning" src="img/warning.svg" width="24" height="23" alt="/!\"/>
41+
<div className="mx_MatrixToolbar_content">
42+
A new version of Vector is available. Refresh your browser.
3243
</div>
33-
);
34-
}
35-
});
36-
44+
<button className="mx_MatrixToolbar_action" onClick={onChangelogClicked}>Changelog</button>
45+
</div>
46+
);
47+
}
48+
49+
NewVersionBar.propTypes = {
50+
version: React.PropTypes.string.isRequired,
51+
newVersion: React.PropTypes.string.isRequired,
52+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
Copyright 2016 Aviral Dasgupta
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
.mx_ChangelogDialog_content {
18+
max-height: 300px;
19+
overflow: auto;
20+
}

‎src/skins/vector/css/vector-web/views/globals/MatrixToolbar.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ limitations under the License.
5454
float: right;
5555
margin-right: 10px;
5656
}
57+
58+
.mx_MatrixToolbar_action {
59+
margin-right: 16px;
60+
}

0 commit comments

Comments
 (0)