Show URL when hovering over links

This commit is contained in:
Yuya Ochiai 2016-11-26 00:37:32 +09:00
parent e4f961f2f0
commit e4e40ec7c0
3 changed files with 47 additions and 1 deletions

View file

@ -0,0 +1,32 @@
const React = require('react');
const divStyle = {
backgroundColor: 'whitesmoke',
position: 'absolute',
bottom: 0,
paddingLeft: 4,
paddingRight: 16,
borderTopRightRadius: 4
};
const spanStyle = {
color: 'gray'
};
class HoveringURL extends React.Component {
render() {
return (
<div style={divStyle}>
<span style={spanStyle}>
{this.props.targetURL}
</span>
</div>
);
}
}
HoveringURL.propTypes = {
targetURL: React.PropTypes.string
};
module.exports = HoveringURL;

View file

@ -7,6 +7,7 @@ const url = require('url');
const LoginModal = require('./LoginModal.jsx');
const MattermostView = require('./MattermostView.jsx');
const TabBar = require('./TabBar.jsx');
const HoveringURL = require('./HoveringURL.jsx');
const MainPage = React.createClass({
propTypes: {
@ -22,7 +23,8 @@ const MainPage = React.createClass({
mentionCounts: new Array(this.props.teams.length),
unreadAtActive: new Array(this.props.teams.length),
mentionAtActiveCounts: new Array(this.props.teams.length),
loginQueue: []
loginQueue: [],
targetURL: ''
};
},
componentDidMount() {
@ -196,6 +198,9 @@ const MainPage = React.createClass({
loginQueue.shift();
this.setState({loginQueue});
},
handleTargetURLChange(targetURL) {
this.setState({targetURL});
},
render() {
var self = this;
@ -234,6 +239,7 @@ const MainPage = React.createClass({
src={team.url}
name={team.name}
disablewebsecurity={this.props.disablewebsecurity}
onTargetURLChange={self.handleTargetURLChange}
onUnreadCountChange={handleUnreadCountChange}
onNotificationClick={handleNotificationClick}
ref={id}
@ -268,6 +274,7 @@ const MainPage = React.createClass({
{ tabsRow }
{ viewsRow }
</Grid>
<HoveringURL targetURL={this.state.targetURL}/>
</div>
);
}

View file

@ -13,6 +13,7 @@ const MattermostView = React.createClass({
disablewebsecurity: React.PropTypes.bool,
name: React.PropTypes.string,
id: React.PropTypes.string,
onTargetURLChange: React.PropTypes.func,
onUnreadCountChange: React.PropTypes.func,
src: React.PropTypes.string,
style: React.PropTypes.object
@ -108,6 +109,12 @@ const MattermostView = React.createClass({
});
});
webview.addEventListener('update-target-url', (event) => {
if (self.props.onTargetURLChange) {
self.props.onTargetURLChange(event.url);
}
});
webview.addEventListener('ipc-message', (event) => {
switch (event.channel) {
case 'onUnreadCountChange':