2016-12-13 11:08:13 +13:00
|
|
|
|
2019-02-10 19:51:33 +13:00
|
|
|
import React from 'react';
|
2019-06-28 09:34:15 +12:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
|
|
|
|
|
|
import * as uiActions from '../services/ui/actions';
|
|
|
|
|
import * as spotifyActions from '../services/spotify/actions';
|
|
|
|
|
import * as lastfmActions from '../services/lastfm/actions';
|
|
|
|
|
import * as geniusActions from '../services/genius/actions';
|
|
|
|
|
import * as snapcastActions from '../services/snapcast/actions';
|
2019-01-09 16:56:35 +13:00
|
|
|
|
2018-05-20 20:42:20 +12:00
|
|
|
import Icon from './Icon';
|
2016-12-13 11:08:13 +13:00
|
|
|
|
2019-06-28 09:34:15 +12:00
|
|
|
class Notifications extends React.Component{
|
2016-12-13 11:08:13 +13:00
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
constructor(props){
|
2016-12-13 11:08:13 +13:00
|
|
|
super(props)
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-30 20:09:12 +13:00
|
|
|
importConfiguration(notification_key, configuration){
|
2018-10-01 21:51:46 +13:00
|
|
|
console.log("Importing configuration", configuration);
|
2018-09-30 20:09:12 +13:00
|
|
|
var configurations = "";
|
|
|
|
|
|
|
|
|
|
if (configuration.interface){
|
|
|
|
|
this.props.uiActions.set(configuration.interface);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-01 21:51:46 +13:00
|
|
|
if (configuration.spotify){
|
|
|
|
|
this.props.spotifyActions.importAuthorization(configuration.spotify.authorization, configuration.spotify.me);
|
2018-09-30 20:09:12 +13:00
|
|
|
}
|
|
|
|
|
|
2018-10-01 21:51:46 +13:00
|
|
|
if (configuration.lastfm){
|
|
|
|
|
this.props.lastfmActions.importAuthorization(configuration.lastfm.authorization, configuration.lastfm.me);
|
2018-09-30 20:09:12 +13:00
|
|
|
}
|
|
|
|
|
|
2018-10-01 21:51:46 +13:00
|
|
|
if (configuration.genius){
|
|
|
|
|
this.props.geniusActions.importAuthorization(configuration.genius.authorization, configuration.genius.me);
|
2018-09-30 20:09:12 +13:00
|
|
|
}
|
|
|
|
|
|
2018-07-13 16:48:41 +12:00
|
|
|
this.props.uiActions.removeNotification(notification_key, true);
|
2018-09-30 20:09:12 +13:00
|
|
|
this.props.uiActions.createNotification({type: 'info', content: 'Import successful'});
|
2018-07-13 16:48:41 +12:00
|
|
|
}
|
|
|
|
|
|
2017-04-03 20:58:47 +12:00
|
|
|
renderNotifications(){
|
|
|
|
|
if (!this.props.notifications || this.props.notifications.length <= 0) return null
|
2016-12-13 11:08:13 +13:00
|
|
|
|
2018-02-28 08:44:38 +13:00
|
|
|
var notifications = []
|
|
|
|
|
for (var key in this.props.notifications){
|
|
|
|
|
if (this.props.notifications.hasOwnProperty(key)){
|
|
|
|
|
notifications.push(this.props.notifications[key])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-05 09:01:20 +12:00
|
|
|
return (
|
|
|
|
|
<span>
|
|
|
|
|
{
|
2018-02-28 08:44:38 +13:00
|
|
|
notifications.map(notification => {
|
2017-04-05 09:01:20 +12:00
|
|
|
switch (notification.type){
|
|
|
|
|
case 'shortcut':
|
|
|
|
|
return (
|
2018-07-13 16:48:41 +12:00
|
|
|
<div className={"notification notification--shortcut"+(notification.closing ? ' closing' : '')} key={notification.key} data-duration={notification.duration}>
|
2019-04-18 09:03:38 +12:00
|
|
|
<Icon name={notification.content} />
|
2017-04-05 09:01:20 +12:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
|
2018-09-30 20:09:12 +13:00
|
|
|
case 'share-configuration-received':
|
2018-07-13 16:48:41 +12:00
|
|
|
return (
|
2018-07-24 20:07:21 +12:00
|
|
|
<div className={"notification notification--info"} key={notification.key} data-key={notification.key} data-duration={notification.duration}>
|
2019-02-05 22:35:52 +13:00
|
|
|
<Icon name="close" className="notification__close-button" onClick={ e => this.props.uiActions.removeNotification(notification.key, true) } />
|
2018-07-13 16:48:41 +12:00
|
|
|
|
2019-02-05 22:35:52 +13:00
|
|
|
<h4 className="notification__title">Configuration shared</h4>
|
|
|
|
|
<div className="notification__content">
|
2018-09-30 20:09:12 +13:00
|
|
|
<p>Another user has shared their configuration with you. This includes:</p>
|
|
|
|
|
<ul>
|
2018-10-01 21:51:46 +13:00
|
|
|
{notification.configuration.ui ? <li>User interface</li> : null}
|
|
|
|
|
{notification.configuration.spotify ? <li>Spotify</li> : null}
|
|
|
|
|
{notification.configuration.lastfm ? <li>LastFM</li> : null}
|
|
|
|
|
{notification.configuration.genius ? <li>Genius</li> : null}
|
2018-09-30 20:09:12 +13:00
|
|
|
</ul>
|
|
|
|
|
<p>Do you want to import this?</p>
|
|
|
|
|
</div>
|
2019-02-05 22:35:52 +13:00
|
|
|
<div className="notification__actions">
|
2019-02-06 14:07:17 +13:00
|
|
|
<a className="notification__actions__item button button--default" onClick={e => this.importConfiguration(notification.key, notification.configuration)}>Import</a>
|
2019-02-05 22:35:52 +13:00
|
|
|
</div>
|
2018-07-13 16:48:41 +12:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
|
2017-04-05 09:01:20 +12:00
|
|
|
default:
|
|
|
|
|
return (
|
2018-07-13 16:48:41 +12:00
|
|
|
<div className={"notification notification--"+notification.type+(notification.closing ? ' closing' : '')} key={notification.key} data-key={notification.key} data-duration={notification.duration}>
|
2019-02-05 22:35:52 +13:00
|
|
|
<Icon name="close" className="notification__close-button" onClick={ e => this.props.uiActions.removeNotification(notification.key, true) } />
|
|
|
|
|
{notification.title ? <h4 className="notification__title">{notification.title}</h4> : null}
|
|
|
|
|
{notification.content ? <div className="notification__content">{notification.content}</div> : null}
|
|
|
|
|
{notification.description ? <div className="notification__description">{notification.description}</div> : null }
|
|
|
|
|
{notification.links ? <div className="notification__actions">{notification.links.map((link, i) => {
|
|
|
|
|
return <a className="notification__actions__item button button--secondary" href={link.url} target={link.new_window ? "_blank" : "self"} key={i}>{link.text}</a>
|
|
|
|
|
})}</div> : null }
|
2017-04-05 09:01:20 +12:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</span>
|
|
|
|
|
)
|
2016-12-13 11:08:13 +13:00
|
|
|
}
|
|
|
|
|
|
2017-08-17 08:29:14 +12:00
|
|
|
renderProcess(process){
|
2017-09-05 21:13:43 +12:00
|
|
|
|
2017-09-08 14:32:44 +12:00
|
|
|
var progress = 0;
|
|
|
|
|
if (process.data.total && process.data.remaining){
|
|
|
|
|
progress = ((process.data.total - process.data.remaining) / process.data.total * 100).toFixed()
|
2017-09-07 11:16:04 +12:00
|
|
|
}
|
2017-09-05 21:13:43 +12:00
|
|
|
|
2017-08-17 08:29:14 +12:00
|
|
|
switch (process.status){
|
|
|
|
|
case 'running':
|
|
|
|
|
return(
|
2018-07-13 16:48:41 +12:00
|
|
|
<div className={"notification notification--process"+(process.closing ? ' closing' : '')} key={process.key}>
|
2017-09-07 11:16:04 +12:00
|
|
|
<div className="loader">
|
2017-09-08 07:57:48 +12:00
|
|
|
<div className="progress">
|
|
|
|
|
<div className="fill" style={{width: progress+'%'}}></div>
|
|
|
|
|
</div>
|
2017-09-07 11:16:04 +12:00
|
|
|
</div>
|
|
|
|
|
{process.message}
|
2019-02-06 14:07:17 +13:00
|
|
|
<Icon name="close" className="notification__close-button" onClick={e => {this.props.uiActions.cancelProcess(process.key)}} />
|
2017-08-17 08:29:14 +12:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
case 'cancelling':
|
|
|
|
|
return(
|
2018-07-13 16:48:41 +12:00
|
|
|
<div className={"notification notification--process cancelling"+(process.closing ? ' closing' : '')} key={process.key}>
|
2017-08-17 08:29:14 +12:00
|
|
|
<div className="loader"></div>
|
|
|
|
|
Cancelling
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
case 'cancelled':
|
|
|
|
|
case 'finished':
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-06 09:01:53 +12:00
|
|
|
renderProcesses(){
|
|
|
|
|
if (!this.props.processes || this.props.processes.length <= 0) return null
|
2017-08-17 08:29:14 +12:00
|
|
|
|
|
|
|
|
var processes = []
|
|
|
|
|
for (var key in this.props.processes){
|
|
|
|
|
if (this.props.processes.hasOwnProperty(key)){
|
|
|
|
|
processes.push(this.props.processes[key])
|
2017-04-06 09:01:53 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<span>
|
2017-08-17 08:29:14 +12:00
|
|
|
{processes.map(process => {
|
|
|
|
|
return this.renderProcess(process)
|
|
|
|
|
})}
|
2017-04-06 09:01:53 +12:00
|
|
|
</span>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-05 09:01:20 +12:00
|
|
|
// do we want the loading of everything to be displayed?
|
|
|
|
|
// not likely...
|
2017-04-03 20:58:47 +12:00
|
|
|
renderLoader(){
|
|
|
|
|
if (!this.props.load_queue){
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var load_queue = this.props.load_queue
|
2017-04-10 08:09:38 +12:00
|
|
|
var load_count = 0
|
2017-04-03 20:58:47 +12:00
|
|
|
for (var key in load_queue){
|
|
|
|
|
if (load_queue.hasOwnProperty(key)){
|
2017-04-10 08:09:38 +12:00
|
|
|
load_count++
|
2017-04-03 20:58:47 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 08:09:38 +12:00
|
|
|
if (load_count > 0){
|
|
|
|
|
var className = "loading "
|
|
|
|
|
if (load_count > 20){
|
|
|
|
|
className += 'high'
|
|
|
|
|
} else if (load_count > 5){
|
|
|
|
|
className += 'medium'
|
|
|
|
|
} else {
|
|
|
|
|
className += 'low'
|
|
|
|
|
}
|
2017-04-03 20:58:47 +12:00
|
|
|
return (
|
2017-04-10 08:09:38 +12:00
|
|
|
<div className={className}></div>
|
2017-04-03 20:58:47 +12:00
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
return null
|
|
|
|
|
}
|
2016-12-13 11:08:13 +13:00
|
|
|
}
|
|
|
|
|
|
2017-04-03 20:58:47 +12:00
|
|
|
render(){
|
|
|
|
|
return (
|
|
|
|
|
<div className="notifications">
|
2017-04-10 08:09:38 +12:00
|
|
|
{this.renderLoader()}
|
2017-04-03 20:58:47 +12:00
|
|
|
{this.renderNotifications()}
|
2017-04-06 09:01:53 +12:00
|
|
|
{this.renderProcesses()}
|
2017-04-03 20:58:47 +12:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
2019-06-28 09:34:15 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
return {
|
|
|
|
|
broadcasts: (state.ui.broadcasts ? state.ui.broadcasts : []),
|
|
|
|
|
notifications: (state.ui.notifications ? state.ui.notifications : []),
|
|
|
|
|
processes: (state.ui.processes ? state.ui.processes : {}),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
|
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch),
|
|
|
|
|
geniusActions: bindActionCreators(geniusActions, dispatch),
|
|
|
|
|
lastfmActions: bindActionCreators(lastfmActions, dispatch),
|
|
|
|
|
snapcastActions: bindActionCreators(snapcastActions, dispatch),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Notifications)
|