mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Add RealtimeNotification
This commit is contained in:
54
browser/components/RealtimeNotification.js
Normal file
54
browser/components/RealtimeNotification.js
Normal file
@@ -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
browser/components/RealtimeNotification.styl
Normal file
2
browser/components/RealtimeNotification.styl
Normal file
@@ -0,0 +1,2 @@
|
||||
.realtime-notification
|
||||
font-size 1em
|
||||
@@ -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
|
||||
@@ -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'>
|
||||
|
||||
Reference in New Issue
Block a user