Skip to content

Commit

Permalink
add fancy changelog dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
aviraldg committed Aug 15, 2016
1 parent d3eccc1 commit 145d2da
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 17 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
"react-gemini-scrollbar": "matrix-org/react-gemini-scrollbar#5e97aef",
"sanitize-html": "^1.11.1",
"ua-parser-js": "^0.7.10",
"url": "^0.11.0"
"url": "^0.11.0",
"whatwg-fetch": "^1.0.0"
},
"devDependencies": {
"babel": "^5.8.23",
Expand Down
1 change: 1 addition & 0 deletions src/component-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports.components['structures.ViewSource'] = require('./components/struc
module.exports.components['views.context_menus.MessageContextMenu'] = require('./components/views/context_menus/MessageContextMenu');
module.exports.components['views.context_menus.NotificationStateContextMenu'] = require('./components/views/context_menus/NotificationStateContextMenu');
module.exports.components['views.context_menus.RoomTagContextMenu'] = require('./components/views/context_menus/RoomTagContextMenu');
module.exports.components['views.dialogs.ChangelogDialog'] = require('./components/views/dialogs/ChangelogDialog');
module.exports.components['views.elements.ImageView'] = require('./components/views/elements/ImageView');
module.exports.components['views.elements.Spinner'] = require('./components/views/elements/Spinner');
module.exports.components['views.globals.GuestWarningBar'] = require('./components/views/globals/GuestWarningBar');
Expand Down
83 changes: 83 additions & 0 deletions src/components/views/dialogs/ChangelogDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
Copyright 2016 Aviral Dasgupta
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React from 'react';
import sdk from 'matrix-react-sdk';
import 'whatwg-fetch';

const REPOS = ['vector-im/vector-web', 'matrix-org/matrix-react-sdk', 'matrix-org/matrix-js-sdk'];

export default class ChangelogDialog extends React.Component {
constructor(props) {
super(props);

this.state = {};
}

componentDidMount() {
console.log(this.props);
const version = this.props.newVersion;
const version2 = this.props.version;
if(version == null || version2 == null) return;
for(let i=0; i<REPOS.length; i++) {
const oldVersion = version2[2*i+1];
const newVersion = version[2*i+1];
fetch(`https://api.github.com/repos/${REPOS[i]}/compare/${oldVersion}...${newVersion}`)
.then(response => response.json())
.then(json => this.setState({[REPOS[i]]: json.commits}));

}
}

render() {
const Spinner = sdk.getComponent('views.elements.Spinner');
const QuestionDialog = sdk.getComponent('dialogs.QuestionDialog');

const logs = REPOS.map(repo => {
if (this.state[repo] == null) return <Spinner key={repo} />;
return (
<div key={repo}>
<h2>{repo}</h2>
{this.state[repo].map(commit =>
<div key={commit.commit.url}><a href={commit.commit.url}>{commit.commit.message}</a></div>
)}
</div>
)
});

const content = (
<div className="mx_ChangelogDialog_content">
{this.props.version == null || this.props.newVersion == null ? <h2>Unavailable</h2> : logs}
</div>
);


return (
<QuestionDialog
title="Changelog"
description={content}
button="Update"
onFinished={this.props.onFinished}
/>
)
}
}

ChangelogDialog.propTypes = {
version: React.PropTypes.string.isRequired,
newVersion: React.PropTypes.string.isRequired,
onFinished: React.PropTypes.func.isRequired,
};
48 changes: 32 additions & 16 deletions src/components/views/globals/NewVersionBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,36 @@ limitations under the License.
'use strict';

var React = require('react');
var sdk = require('matrix-react-sdk')

module.exports = React.createClass({
displayName: 'NewVersionBar',

render: function() {
return (
<div className="mx_MatrixToolbar">
<img className="mx_MatrixToolbar_warning" src="img/warning.svg" width="24" height="23" alt="/!\"/>
<div>
A new version of Vector is available. Refresh your browser.
</div>
var sdk = require('matrix-react-sdk');
import Modal from 'matrix-react-sdk/lib/Modal';

export default function NewVersionBar(props) {
const onChangelogClicked = () => {
const ChangelogDialog = sdk.getComponent('dialogs.ChangelogDialog');
console.log(props);
Modal.createDialog(ChangelogDialog, {
version: props.version,
newVersion: props.newVersion,
onFinished: (update) => {
if(update) {
window.location.reload();
}
}
});
};

return (
<div className="mx_MatrixToolbar">
<img className="mx_MatrixToolbar_warning" src="img/warning.svg" width="24" height="23" alt="/!\"/>
<div style={{flex: 1}}>
A new version of Vector is available. Refresh your browser.
</div>
);
}
});

<button style={{marginRight: 16}} onClick={onChangelogClicked}>Changelog</button>
</div>
);
}

NewVersionBar.propTypes = {
version: React.PropTypes.string.isRequired,
newVersion: React.PropTypes.string.isRequired,
};
20 changes: 20 additions & 0 deletions src/skins/vector/css/vector-web/views/dialogs/ChangelogDialog.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2016 Aviral Dasgupta
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

.mx_ChangelogDialog_content {
max-height: 300px;
overflow: auto;
}

0 comments on commit 145d2da

Please sign in to comment.