Skip to content

Commit c762b9a

Browse files
authored
Merge pull request #877 from asmsuechan/add-realtime-info
Add RealtimeNotification
2 parents cc667a6 + 964b7b6 commit c762b9a

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React, { PropTypes } from 'react'
2+
import CSSModules from 'browser/lib/CSSModules'
3+
import styles from './RealtimeNotification.styl'
4+
5+
const electron = require('electron')
6+
const { shell } = electron
7+
8+
class RealtimeNotification extends React.Component {
9+
constructor (props) {
10+
super(props)
11+
12+
this.state = {
13+
notifications: []
14+
}
15+
}
16+
17+
componentDidMount () {
18+
this.fetchNotifications()
19+
}
20+
21+
fetchNotifications () {
22+
const notificationsUrl = 'https://raw.githubusercontent.com/BoostIO/notification/master/notification.json'
23+
fetch(notificationsUrl)
24+
.then(response => {
25+
return response.json()
26+
})
27+
.then(json => {
28+
this.setState({notifications: json.notifications})
29+
})
30+
}
31+
32+
handleLinkClick (e) {
33+
shell.openExternal(e.currentTarget.href)
34+
e.preventDefault()
35+
}
36+
37+
render () {
38+
const { notifications } = this.state
39+
const link = notifications.length > 0
40+
? <a href={notifications[0].linkUrl}
41+
onClick={(e) => this.handleLinkClick(e)}
42+
>
43+
{notifications[0].text}
44+
</a>
45+
: ''
46+
47+
return (
48+
<div>{link}</div>
49+
)
50+
}
51+
}
52+
53+
RealtimeNotification.propTypes = {}
54+
55+
export default CSSModules(RealtimeNotification, styles)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.realtime-notification
2+
font-size 1em

browser/main/StatusBar/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { PropTypes } from 'react'
22
import CSSModules from 'browser/lib/CSSModules'
33
import styles from './StatusBar.styl'
44
import ZoomManager from 'browser/main/lib/ZoomManager'
5+
import RealtimeNotification from 'browser/components/RealtimeNotification'
56

67
const electron = require('electron')
78
const { remote, ipcRenderer } = electron
@@ -59,7 +60,9 @@ class StatusBar extends React.Component {
5960
{Math.floor(config.zoom * 100)}%
6061
</button>
6162

62-
<div styleName='blank' />
63+
<RealtimeNotification
64+
styleName='realtime-notification'
65+
/>
6366

6467
{status.updateReady
6568
? <button onClick={this.updateApp} styleName='update'>

0 commit comments

Comments
 (0)