Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add RealtimeNotification
  • Loading branch information
asmsuechan committed Sep 9, 2017
commit e313b5e59dc871e1187b7165a71c434e88fa4278
54 changes: 54 additions & 0 deletions browser/components/RealtimeNotification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { PropTypes } from 'react'
import CSSModules from 'browser/lib/CSSModules'
import styles from './RealtimeNotification.styl'

const electron = require('electron')
const { shell } = electron

class RealtimeNotification extends React.Component {
constructor (props) {
super(props)

this.state = {
notifications: []
}
}

componentDidMount () {
this.fetchNotifications()
}

fetchNotifications () {
fetch('https://raw.githubusercontent.com/asmsuechan/notification/master/notification.json')
.then(response => {
return response.json()
})
.then(json => {
this.setState({notifications: json.notifications})
})
}

handleLinkClick (e) {
shell.openExternal(e.currentTarget.href)
e.preventDefault()
}

render () {
const { notifications } = this.state
const link = notifications.length > 0
? <a href={notifications[0].linkUrl}
onClick={(e) => this.handleLinkClick(e)}
>
{notifications[0].text}
</a>
: ''

return (
<div>{link}</div>
)
}
}

RealtimeNotification.propTypes = {}

export default CSSModules(RealtimeNotification, styles)
2 changes: 2 additions & 0 deletions browser/components/RealtimeNotification.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.realtime-notification
font-size 1em
5 changes: 4 additions & 1 deletion browser/main/StatusBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { PropTypes } from 'react'
import CSSModules from 'browser/lib/CSSModules'
import styles from './StatusBar.styl'
import ZoomManager from 'browser/main/lib/ZoomManager'
import RealtimeNotification from 'browser/components/RealtimeNotification'

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

<div styleName='blank' />
<RealtimeNotification
styleName='realtime-notification'
/>

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