Auto eslint fix
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
|
||||
import * as helpers from '../../helpers'
|
||||
import * as helpers from '../../helpers';
|
||||
|
||||
export function setWindowTitle(title = null, play_state = null){
|
||||
return {
|
||||
type: 'SET_WINDOW_TITLE',
|
||||
title: title,
|
||||
play_state: play_state
|
||||
}
|
||||
export function setWindowTitle(title = null, play_state = null) {
|
||||
return {
|
||||
type: 'SET_WINDOW_TITLE',
|
||||
title,
|
||||
play_state,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -14,282 +14,276 @@ export function setWindowTitle(title = null, play_state = null){
|
||||
* we're pending transition to a new/next track
|
||||
*
|
||||
* @param transitioning Boolean
|
||||
**/
|
||||
export function setCurrentTrackTransition(current_track_transition){
|
||||
return {
|
||||
type: 'SET_CURRENT_TRACK_TRANSITION',
|
||||
current_track_transition: current_track_transition
|
||||
}
|
||||
* */
|
||||
export function setCurrentTrackTransition(current_track_transition) {
|
||||
return {
|
||||
type: 'SET_CURRENT_TRACK_TRANSITION',
|
||||
current_track_transition,
|
||||
};
|
||||
}
|
||||
|
||||
export function setSelectedTracks(keys = []){
|
||||
if (typeof(keys) === 'string'){
|
||||
keys = [keys]
|
||||
}
|
||||
return {
|
||||
type: 'SET_SELECTED_TRACKS',
|
||||
keys: keys
|
||||
}
|
||||
export function setSelectedTracks(keys = []) {
|
||||
if (typeof (keys) === 'string') {
|
||||
keys = [keys];
|
||||
}
|
||||
return {
|
||||
type: 'SET_SELECTED_TRACKS',
|
||||
keys,
|
||||
};
|
||||
}
|
||||
|
||||
export function showContextMenu(data){
|
||||
|
||||
// Touchend
|
||||
if (data.e.changedTouches){
|
||||
data.position_x = data.e.changedTouches[0].clientX;
|
||||
data.position_y = data.e.changedTouches[0].clientY;
|
||||
export function showContextMenu(data) {
|
||||
// Touchend
|
||||
if (data.e.changedTouches) {
|
||||
data.position_x = data.e.changedTouches[0].clientX;
|
||||
data.position_y = data.e.changedTouches[0].clientY;
|
||||
|
||||
// Touchstart
|
||||
} else if (data.e.touches){
|
||||
data.position_x = data.e.touches[0].clientX;
|
||||
data.position_y = data.e.touches[0].clientY;
|
||||
} else if (data.e.touches) {
|
||||
data.position_x = data.e.touches[0].clientX;
|
||||
data.position_y = data.e.touches[0].clientY;
|
||||
|
||||
// Click/mousedown/mouseup/etc
|
||||
} else {
|
||||
data.position_x = data.e.clientX;
|
||||
data.position_y = data.e.clientY;
|
||||
}
|
||||
} else {
|
||||
data.position_x = data.e.clientX;
|
||||
data.position_y = data.e.clientY;
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'SHOW_CONTEXT_MENU',
|
||||
data: data
|
||||
}
|
||||
return {
|
||||
type: 'SHOW_CONTEXT_MENU',
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
export function setSlimMode(slim_mode){
|
||||
return {
|
||||
type: 'SET_SLIM_MODE',
|
||||
slim_mode: slim_mode
|
||||
}
|
||||
export function setSlimMode(slim_mode) {
|
||||
return {
|
||||
type: 'SET_SLIM_MODE',
|
||||
slim_mode,
|
||||
};
|
||||
}
|
||||
|
||||
export function setWindowFocus(window_focus){
|
||||
return {
|
||||
type: 'SET_WINDOW_FOCUS',
|
||||
window_focus: window_focus
|
||||
}
|
||||
export function setWindowFocus(window_focus) {
|
||||
return {
|
||||
type: 'SET_WINDOW_FOCUS',
|
||||
window_focus,
|
||||
};
|
||||
}
|
||||
|
||||
export function hideContextMenu(){
|
||||
return {
|
||||
type: 'HIDE_CONTEXT_MENU'
|
||||
}
|
||||
export function hideContextMenu() {
|
||||
return {
|
||||
type: 'HIDE_CONTEXT_MENU',
|
||||
};
|
||||
}
|
||||
|
||||
export function removeContextMenu(){
|
||||
return {
|
||||
type: 'REMOVE_CONTEXT_MENU'
|
||||
}
|
||||
export function removeContextMenu() {
|
||||
return {
|
||||
type: 'REMOVE_CONTEXT_MENU',
|
||||
};
|
||||
}
|
||||
|
||||
export function showTouchContextMenu(data){
|
||||
return {
|
||||
type: 'SHOW_TOUCH_CONTEXT_MENU',
|
||||
data: data
|
||||
}
|
||||
export function showTouchContextMenu(data) {
|
||||
return {
|
||||
type: 'SHOW_TOUCH_CONTEXT_MENU',
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
export function hideTouchContextMenu(){
|
||||
return {
|
||||
type: 'HIDE_TOUCH_CONTEXT_MENU'
|
||||
}
|
||||
export function hideTouchContextMenu() {
|
||||
return {
|
||||
type: 'HIDE_TOUCH_CONTEXT_MENU',
|
||||
};
|
||||
}
|
||||
|
||||
export function removeTouchContextMenu(){
|
||||
return {
|
||||
type: 'REMOVE_TOUCH_CONTEXT_MENU'
|
||||
}
|
||||
export function removeTouchContextMenu() {
|
||||
return {
|
||||
type: 'REMOVE_TOUCH_CONTEXT_MENU',
|
||||
};
|
||||
}
|
||||
|
||||
export function lazyLoading(start){
|
||||
return {
|
||||
type: 'LAZY_LOADING',
|
||||
start: start
|
||||
}
|
||||
export function lazyLoading(start) {
|
||||
return {
|
||||
type: 'LAZY_LOADING',
|
||||
start,
|
||||
};
|
||||
}
|
||||
|
||||
export function toggleSidebar(new_state = 'toggle'){
|
||||
var action = {
|
||||
type: 'TOGGLE_SIDEBAR'
|
||||
}
|
||||
if (new_state != 'toggle'){
|
||||
action.new_state = new_state
|
||||
}
|
||||
return action
|
||||
export function toggleSidebar(new_state = 'toggle') {
|
||||
const action = {
|
||||
type: 'TOGGLE_SIDEBAR',
|
||||
};
|
||||
if (new_state != 'toggle') {
|
||||
action.new_state = new_state;
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
export function dragStart(e, context, from_uri = null, victims, victims_indexes = null){
|
||||
return {
|
||||
type: 'DRAG_START',
|
||||
context: context,
|
||||
from_uri: from_uri,
|
||||
victims: victims,
|
||||
victims_indexes: victims_indexes,
|
||||
start_x: e.clientX,
|
||||
start_y: e.clientY
|
||||
}
|
||||
export function dragStart(e, context, from_uri = null, victims, victims_indexes = null) {
|
||||
return {
|
||||
type: 'DRAG_START',
|
||||
context,
|
||||
from_uri,
|
||||
victims,
|
||||
victims_indexes,
|
||||
start_x: e.clientX,
|
||||
start_y: e.clientY,
|
||||
};
|
||||
}
|
||||
|
||||
export function dragActive(){
|
||||
return { type: 'DRAG_ACTIVE' }
|
||||
export function dragActive() {
|
||||
return { type: 'DRAG_ACTIVE' };
|
||||
}
|
||||
|
||||
export function dragEnd(){
|
||||
return { type: 'DRAG_END' }
|
||||
export function dragEnd() {
|
||||
return { type: 'DRAG_END' };
|
||||
}
|
||||
|
||||
export function set(data){
|
||||
return {
|
||||
type: 'UI_SET',
|
||||
data: data
|
||||
}
|
||||
export function set(data) {
|
||||
return {
|
||||
type: 'UI_SET',
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
export function installPrompt(event){
|
||||
return {
|
||||
type: 'INSTALL_PROMPT',
|
||||
event: event
|
||||
}
|
||||
export function installPrompt(event) {
|
||||
return {
|
||||
type: 'INSTALL_PROMPT',
|
||||
event,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notifications
|
||||
*
|
||||
* Subtle info/tooltip messages
|
||||
**/
|
||||
* */
|
||||
|
||||
export function createBrowserNotification(data){
|
||||
return {
|
||||
type: 'BROWSER_NOTIFICATION',
|
||||
data: data
|
||||
}
|
||||
export function createBrowserNotification(data) {
|
||||
return {
|
||||
type: 'BROWSER_NOTIFICATION',
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
export function createNotification(data){
|
||||
export function createNotification(data) {
|
||||
// Allow 'message' as an alias of our content
|
||||
if (data.message) {
|
||||
data.content = data.message;
|
||||
}
|
||||
|
||||
// Allow 'message' as an alias of our content
|
||||
if (data.message){
|
||||
data.content = data.message;
|
||||
}
|
||||
|
||||
// Shortcut notifications are short and sweet
|
||||
if (data.type == 'shortcut'){
|
||||
data.duration = 0.4;
|
||||
}
|
||||
// Shortcut notifications are short and sweet
|
||||
if (data.type == 'shortcut') {
|
||||
data.duration = 0.4;
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'CREATE_NOTIFICATION',
|
||||
notification: Object.assign(
|
||||
{
|
||||
key: helpers.generateGuid(),
|
||||
duration: 5,
|
||||
type: 'default',
|
||||
title: null,
|
||||
content: null,
|
||||
description: null,
|
||||
sticky: false,
|
||||
closing: false,
|
||||
render_content: false
|
||||
},
|
||||
data
|
||||
)
|
||||
}
|
||||
return {
|
||||
type: 'CREATE_NOTIFICATION',
|
||||
notification: {
|
||||
key: helpers.generateGuid(),
|
||||
duration: 5,
|
||||
type: 'default',
|
||||
title: null,
|
||||
content: null,
|
||||
description: null,
|
||||
sticky: false,
|
||||
closing: false,
|
||||
render_content: false,
|
||||
...data,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function closeNotification(key){
|
||||
return {
|
||||
type: 'CLOSE_NOTIFICATION',
|
||||
key: key
|
||||
}
|
||||
export function closeNotification(key) {
|
||||
return {
|
||||
type: 'CLOSE_NOTIFICATION',
|
||||
key,
|
||||
};
|
||||
}
|
||||
|
||||
export function removeNotification(key, manual = false){
|
||||
return {
|
||||
type: 'REMOVE_NOTIFICATION',
|
||||
key: key,
|
||||
manual: manual
|
||||
}
|
||||
export function removeNotification(key, manual = false) {
|
||||
return {
|
||||
type: 'REMOVE_NOTIFICATION',
|
||||
key,
|
||||
manual,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Loaders
|
||||
**/
|
||||
* */
|
||||
|
||||
export function startLoading(key,source){
|
||||
return {
|
||||
type: 'START_LOADING',
|
||||
source: source,
|
||||
key: key
|
||||
}
|
||||
export function startLoading(key, source) {
|
||||
return {
|
||||
type: 'START_LOADING',
|
||||
source,
|
||||
key,
|
||||
};
|
||||
}
|
||||
|
||||
export function stopLoading(key){
|
||||
return {
|
||||
type: 'STOP_LOADING',
|
||||
key: key
|
||||
}
|
||||
export function stopLoading(key) {
|
||||
return {
|
||||
type: 'STOP_LOADING',
|
||||
key,
|
||||
};
|
||||
}
|
||||
|
||||
export function startProcess(key,message,data = {}){
|
||||
return {
|
||||
type: 'START_PROCESS',
|
||||
key: key,
|
||||
message: message,
|
||||
data: data
|
||||
}
|
||||
export function startProcess(key, message, data = {}) {
|
||||
return {
|
||||
type: 'START_PROCESS',
|
||||
key,
|
||||
message,
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
export function resumeProcess(key,message,data = {}){
|
||||
return {
|
||||
type: 'RESUME_PROCESS',
|
||||
key: key
|
||||
}
|
||||
export function resumeProcess(key, message, data = {}) {
|
||||
return {
|
||||
type: 'RESUME_PROCESS',
|
||||
key,
|
||||
};
|
||||
}
|
||||
|
||||
export function updateProcess(key,message,data = {}){
|
||||
return {
|
||||
type: 'UPDATE_PROCESS',
|
||||
key: key,
|
||||
message: message,
|
||||
data: data
|
||||
}
|
||||
export function updateProcess(key, message, data = {}) {
|
||||
return {
|
||||
type: 'UPDATE_PROCESS',
|
||||
key,
|
||||
message,
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
export function runProcess(key,data = {}){
|
||||
return {
|
||||
type: key,
|
||||
data: data
|
||||
}
|
||||
export function runProcess(key, data = {}) {
|
||||
return {
|
||||
type: key,
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
export function cancelProcess(key){
|
||||
return {
|
||||
type: 'CANCEL_PROCESS',
|
||||
key: key
|
||||
}
|
||||
export function cancelProcess(key) {
|
||||
return {
|
||||
type: 'CANCEL_PROCESS',
|
||||
key,
|
||||
};
|
||||
}
|
||||
|
||||
export function processCancelled(key){
|
||||
return {
|
||||
type: 'PROCESS_CANCELLED',
|
||||
key: key
|
||||
}
|
||||
export function processCancelled(key) {
|
||||
return {
|
||||
type: 'PROCESS_CANCELLED',
|
||||
key,
|
||||
};
|
||||
}
|
||||
|
||||
export function processFinishing(key){
|
||||
return {
|
||||
type: 'PROCESS_FINISHING',
|
||||
key: key
|
||||
}
|
||||
export function processFinishing(key) {
|
||||
return {
|
||||
type: 'PROCESS_FINISHING',
|
||||
key,
|
||||
};
|
||||
}
|
||||
|
||||
export function processFinished(key){
|
||||
return {
|
||||
type: 'PROCESS_FINISHED',
|
||||
key: key
|
||||
}
|
||||
export function processFinished(key) {
|
||||
return {
|
||||
type: 'PROCESS_FINISHED',
|
||||
key,
|
||||
};
|
||||
}
|
||||
|
||||
@ -2,247 +2,244 @@
|
||||
import ReactGA from 'react-ga';
|
||||
import * as helpers from '../../helpers';
|
||||
|
||||
var uiActions = require('./actions.js')
|
||||
var mopidyActions = require('../mopidy/actions.js')
|
||||
const uiActions = require('./actions.js');
|
||||
const mopidyActions = require('../mopidy/actions.js');
|
||||
|
||||
const UIMiddleware = (function(){
|
||||
|
||||
/**
|
||||
const UIMiddleware = (function () {
|
||||
/**
|
||||
* The actual middleware inteceptor
|
||||
**/
|
||||
return store => next => action => {
|
||||
switch(action.type){
|
||||
* */
|
||||
return (store) => (next) => (action) => {
|
||||
switch (action.type) {
|
||||
case 'MOPIDY_STATE':
|
||||
|
||||
case 'MOPIDY_STATE':
|
||||
// Get the current track from our index
|
||||
var { tracks } = store.getState().core;
|
||||
var current_track_uri = store.getState().core.current_track;
|
||||
var current_track = null;
|
||||
if (tracks[current_track_uri] !== undefined) {
|
||||
current_track = tracks[current_track_uri];
|
||||
}
|
||||
next(action);
|
||||
break;
|
||||
|
||||
// Get the current track from our index
|
||||
var tracks = store.getState().core.tracks;
|
||||
var current_track_uri = store.getState().core.current_track;
|
||||
var current_track = null;
|
||||
if (tracks[current_track_uri] !== undefined){
|
||||
current_track = tracks[current_track_uri];
|
||||
}
|
||||
next(action);
|
||||
break
|
||||
case 'SET_WINDOW_TITLE':
|
||||
|
||||
case 'SET_WINDOW_TITLE':
|
||||
var window_title = '';
|
||||
|
||||
var window_title = "";
|
||||
if (action.play_state) {
|
||||
var { play_state } = action;
|
||||
} else {
|
||||
var { play_state } = store.getState().mopidy;
|
||||
}
|
||||
|
||||
if (action.play_state){
|
||||
var play_state = action.play_state;
|
||||
} else {
|
||||
var play_state = store.getState().mopidy.play_state;
|
||||
}
|
||||
if (action.title) {
|
||||
var { title } = action;
|
||||
} else {
|
||||
var title = store.getState().ui.window_title;
|
||||
}
|
||||
|
||||
if (action.title){
|
||||
var title = action.title;
|
||||
} else {
|
||||
var title = store.getState().ui.window_title;
|
||||
}
|
||||
|
||||
document.title = window_title+' '+title;
|
||||
document.title = `${window_title} ${title}`;
|
||||
|
||||
next(action);
|
||||
break;
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'OPEN_MODAL':
|
||||
if (store.getState().ui.allow_reporting){
|
||||
case 'OPEN_MODAL':
|
||||
if (store.getState().ui.allow_reporting) {
|
||||
ReactGA.event({ category: 'Modal', action: 'Opened', label: action.modal.name });
|
||||
}
|
||||
$('body').addClass('modal-open')
|
||||
store.dispatch(uiActions.hideContextMenu())
|
||||
store.dispatch(uiActions.hideTouchContextMenu())
|
||||
next(action)
|
||||
break
|
||||
$('body').addClass('modal-open');
|
||||
store.dispatch(uiActions.hideContextMenu());
|
||||
store.dispatch(uiActions.hideTouchContextMenu());
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'CLOSE_MODAL':
|
||||
if (store.getState().ui.allow_reporting){
|
||||
ReactGA.event({ category: 'Modal', action: 'Closed', label: null });
|
||||
}
|
||||
$('body').removeClass('modal-open')
|
||||
next(action)
|
||||
break
|
||||
|
||||
case 'HIDE_CONTEXT_MENU':
|
||||
if (store.getState().ui.context_menu){
|
||||
setTimeout(
|
||||
() => {
|
||||
store.dispatch(uiActions.removeContextMenu())
|
||||
},
|
||||
200
|
||||
);
|
||||
next(action);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'HIDE_TOUCH_CONTEXT_MENU':
|
||||
if (store.getState().ui.context_menu){
|
||||
setTimeout(
|
||||
() => {
|
||||
store.dispatch(uiActions.removeTouchContextMenu())
|
||||
},
|
||||
200
|
||||
);
|
||||
next(action);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'BROWSER_NOTIFICATION':
|
||||
|
||||
var notification = window.Notification || window.mozNotification || window.webkitNotification;
|
||||
if ('undefined' === typeof notification) return false;
|
||||
if ('undefined' !== typeof notification) notification.requestPermission(function(permission){});
|
||||
|
||||
// handle nested data objects
|
||||
var data = {}
|
||||
if (typeof(action.data) ) data = action.data
|
||||
if (typeof(data.data) ) data = Object.assign({}, data, data.data)
|
||||
|
||||
// construct our browser notification
|
||||
var title = '';
|
||||
var options = {
|
||||
body: '',
|
||||
dir: 'auto',
|
||||
lang: 'EN',
|
||||
tag: 'iris'
|
||||
};
|
||||
if (data.title ) title = data.title;
|
||||
if (data.body ) options.body = data.body;
|
||||
if (data.icon ) options.icon = data.icon;
|
||||
|
||||
// make it so
|
||||
var notification = new notification(title, options );
|
||||
break
|
||||
|
||||
case 'CREATE_NOTIFICATION':
|
||||
|
||||
// start a timeout to close this notification
|
||||
if (!action.notification.sticky){
|
||||
var timeout = setTimeout(
|
||||
function(){
|
||||
store.dispatch(uiActions.closeNotification(action.notification.key))
|
||||
},
|
||||
action.notification.duration * 1000
|
||||
)
|
||||
}
|
||||
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'CLOSE_NOTIFICATION':
|
||||
var notifications = Object.assign({}, store.getState().ui.notifications);
|
||||
|
||||
// start a timeout to remove this notification
|
||||
// This gives us time to animate out the notification before we remove the data
|
||||
var timeout = setTimeout(
|
||||
function(){
|
||||
store.dispatch(uiActions.removeNotification(action.key))
|
||||
},
|
||||
200
|
||||
)
|
||||
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'REMOVE_NOTIFICATION':
|
||||
|
||||
// Manual removal
|
||||
if (action.manual){
|
||||
var notifications = Object.assign({}, store.getState().ui.notifications);
|
||||
|
||||
// If a broadcast, add to suppressed_broadcasts
|
||||
if (notifications[action.key] && notifications[action.key].type == 'broadcast'){
|
||||
store.dispatch({
|
||||
type: 'SUPPRESS_BROADCAST',
|
||||
key: action.key
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'BROADCASTS_LOADED':
|
||||
var suppressed_broadcasts = []
|
||||
if (store.getState().ui.suppressed_broadcasts !== undefined){
|
||||
suppressed_broadcasts = store.getState().ui.suppressed_broadcasts
|
||||
}
|
||||
|
||||
for (var i = 0; i < action.broadcasts.length; i++){
|
||||
var broadcast = action.broadcasts[i]
|
||||
|
||||
if (!suppressed_broadcasts.includes(broadcast.key)){
|
||||
if (broadcast.message){
|
||||
var data = {
|
||||
key: (broadcast.key ? broadcast.key : null),
|
||||
title: (broadcast.title ? broadcast.title : null),
|
||||
content: (broadcast.message ? broadcast.message : null),
|
||||
links: (broadcast.links ? broadcast.links : null),
|
||||
type: 'broadcast',
|
||||
sticky: true
|
||||
}
|
||||
store.dispatch(uiActions.createNotification(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
next(action)
|
||||
break
|
||||
|
||||
case 'START_PROCESS':
|
||||
store.dispatch({
|
||||
type: action.key,
|
||||
data: action.data
|
||||
})
|
||||
store.dispatch({
|
||||
type: action.key+'_STARTED'
|
||||
})
|
||||
next(action)
|
||||
break
|
||||
|
||||
case 'RESUME_PROCESS':
|
||||
store.dispatch({
|
||||
type: action.key,
|
||||
data: store.getState().ui.processes[action.key].data
|
||||
})
|
||||
next(action)
|
||||
break
|
||||
|
||||
case 'PROCESS_CANCELLED':
|
||||
store.dispatch({
|
||||
type: action.key+'_CANCELLED'
|
||||
})
|
||||
next(action)
|
||||
break
|
||||
|
||||
case 'PROCESS_FINISHING':
|
||||
|
||||
// start a timeout to remove this notification
|
||||
// This gives us time to animate out the notification before we remove the data
|
||||
var timeout = setTimeout(
|
||||
function(){
|
||||
store.dispatch(uiActions.processFinished(action.key))
|
||||
},
|
||||
200
|
||||
)
|
||||
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'PROCESS_FINISHED':
|
||||
store.dispatch({
|
||||
type: action.key+'_FINISHED'
|
||||
});
|
||||
next(action);
|
||||
break;
|
||||
|
||||
// This action is irrelevant to us, pass it on to the next middleware
|
||||
default:
|
||||
return next(action)
|
||||
case 'CLOSE_MODAL':
|
||||
if (store.getState().ui.allow_reporting) {
|
||||
ReactGA.event({ category: 'Modal', action: 'Closed', label: null });
|
||||
}
|
||||
$('body').removeClass('modal-open');
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'HIDE_CONTEXT_MENU':
|
||||
if (store.getState().ui.context_menu) {
|
||||
setTimeout(
|
||||
() => {
|
||||
store.dispatch(uiActions.removeContextMenu());
|
||||
},
|
||||
200,
|
||||
);
|
||||
next(action);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'HIDE_TOUCH_CONTEXT_MENU':
|
||||
if (store.getState().ui.context_menu) {
|
||||
setTimeout(
|
||||
() => {
|
||||
store.dispatch(uiActions.removeTouchContextMenu());
|
||||
},
|
||||
200,
|
||||
);
|
||||
next(action);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'BROWSER_NOTIFICATION':
|
||||
|
||||
var notification = window.Notification || window.mozNotification || window.webkitNotification;
|
||||
if (typeof notification === 'undefined') return false;
|
||||
if (typeof notification !== 'undefined') notification.requestPermission((permission) => {});
|
||||
|
||||
// handle nested data objects
|
||||
var data = {};
|
||||
if (typeof (action.data)) data = action.data;
|
||||
if (typeof (data.data)) data = { ...data, ...data.data };
|
||||
|
||||
// construct our browser notification
|
||||
var title = '';
|
||||
var options = {
|
||||
body: '',
|
||||
dir: 'auto',
|
||||
lang: 'EN',
|
||||
tag: 'iris',
|
||||
};
|
||||
if (data.title) title = data.title;
|
||||
if (data.body) options.body = data.body;
|
||||
if (data.icon) options.icon = data.icon;
|
||||
|
||||
// make it so
|
||||
var notification = new notification(title, options);
|
||||
break;
|
||||
|
||||
case 'CREATE_NOTIFICATION':
|
||||
|
||||
// start a timeout to close this notification
|
||||
if (!action.notification.sticky) {
|
||||
var timeout = setTimeout(
|
||||
() => {
|
||||
store.dispatch(uiActions.closeNotification(action.notification.key));
|
||||
},
|
||||
action.notification.duration * 1000,
|
||||
);
|
||||
}
|
||||
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'CLOSE_NOTIFICATION':
|
||||
var notifications = { ...store.getState().ui.notifications };
|
||||
|
||||
// start a timeout to remove this notification
|
||||
// This gives us time to animate out the notification before we remove the data
|
||||
var timeout = setTimeout(
|
||||
() => {
|
||||
store.dispatch(uiActions.removeNotification(action.key));
|
||||
},
|
||||
200,
|
||||
);
|
||||
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'REMOVE_NOTIFICATION':
|
||||
|
||||
// Manual removal
|
||||
if (action.manual) {
|
||||
var notifications = { ...store.getState().ui.notifications };
|
||||
|
||||
// If a broadcast, add to suppressed_broadcasts
|
||||
if (notifications[action.key] && notifications[action.key].type == 'broadcast') {
|
||||
store.dispatch({
|
||||
type: 'SUPPRESS_BROADCAST',
|
||||
key: action.key,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'BROADCASTS_LOADED':
|
||||
var suppressed_broadcasts = [];
|
||||
if (store.getState().ui.suppressed_broadcasts !== undefined) {
|
||||
suppressed_broadcasts = store.getState().ui.suppressed_broadcasts;
|
||||
}
|
||||
|
||||
for (let i = 0; i < action.broadcasts.length; i++) {
|
||||
const broadcast = action.broadcasts[i];
|
||||
|
||||
if (!suppressed_broadcasts.includes(broadcast.key)) {
|
||||
if (broadcast.message) {
|
||||
var data = {
|
||||
key: (broadcast.key ? broadcast.key : null),
|
||||
title: (broadcast.title ? broadcast.title : null),
|
||||
content: (broadcast.message ? broadcast.message : null),
|
||||
links: (broadcast.links ? broadcast.links : null),
|
||||
type: 'broadcast',
|
||||
sticky: true,
|
||||
};
|
||||
store.dispatch(uiActions.createNotification(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'START_PROCESS':
|
||||
store.dispatch({
|
||||
type: action.key,
|
||||
data: action.data,
|
||||
});
|
||||
store.dispatch({
|
||||
type: `${action.key}_STARTED`,
|
||||
});
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'RESUME_PROCESS':
|
||||
store.dispatch({
|
||||
type: action.key,
|
||||
data: store.getState().ui.processes[action.key].data,
|
||||
});
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'PROCESS_CANCELLED':
|
||||
store.dispatch({
|
||||
type: `${action.key}_CANCELLED`,
|
||||
});
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'PROCESS_FINISHING':
|
||||
|
||||
// start a timeout to remove this notification
|
||||
// This gives us time to animate out the notification before we remove the data
|
||||
var timeout = setTimeout(
|
||||
() => {
|
||||
store.dispatch(uiActions.processFinished(action.key));
|
||||
},
|
||||
200,
|
||||
);
|
||||
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'PROCESS_FINISHED':
|
||||
store.dispatch({
|
||||
type: `${action.key}_FINISHED`,
|
||||
});
|
||||
next(action);
|
||||
break;
|
||||
|
||||
// This action is irrelevant to us, pass it on to the next middleware
|
||||
default:
|
||||
return next(action);
|
||||
}
|
||||
};
|
||||
}());
|
||||
|
||||
})();
|
||||
|
||||
export default UIMiddleware
|
||||
export default UIMiddleware;
|
||||
|
||||
@ -1,228 +1,210 @@
|
||||
|
||||
import * as helpers from '../../helpers'
|
||||
import * as helpers from '../../helpers';
|
||||
|
||||
export default function reducer(ui = {}, action){
|
||||
switch (action.type){
|
||||
export default function reducer(ui = {}, action) {
|
||||
switch (action.type) {
|
||||
case 'LAZY_LOADING':
|
||||
return { ...ui, lazy_loading: action.start };
|
||||
|
||||
case 'LAZY_LOADING':
|
||||
return Object.assign({}, ui, { lazy_loading: action.start });
|
||||
case 'SET_SLIM_MODE':
|
||||
return { ...ui, slim_mode: action.slim_mode };
|
||||
|
||||
case 'SET_SLIM_MODE':
|
||||
return Object.assign({}, ui, { slim_mode: action.slim_mode });
|
||||
case 'SET_WINDOW_FOCUS':
|
||||
return { ...ui, window_focus: action.window_focus };
|
||||
|
||||
case 'SET_WINDOW_FOCUS':
|
||||
return Object.assign({}, ui, { window_focus: action.window_focus });
|
||||
case 'DEBUG':
|
||||
return { ...ui, debug_response: action.response };
|
||||
|
||||
case 'DEBUG':
|
||||
return Object.assign({}, ui, { debug_response: action.response })
|
||||
case 'UI_SET':
|
||||
return { ...ui, ...action.data };
|
||||
|
||||
case 'UI_SET':
|
||||
return Object.assign({}, ui, action.data);
|
||||
|
||||
case 'SET_WINDOW_TITLE':
|
||||
if (action.title){
|
||||
return Object.assign({}, ui, { window_title: action.title });
|
||||
} else {
|
||||
return ui;
|
||||
}
|
||||
|
||||
case 'TOGGLE_SIDEBAR':
|
||||
var new_state = !ui.sidebar_open
|
||||
if (typeof(action.new_state) !== 'undefined' ) new_state = action.new_state
|
||||
return Object.assign({}, ui, { sidebar_open : new_state })
|
||||
|
||||
case 'SET_CURRENT_TRACK_TRANSITION':
|
||||
return Object.assign({}, ui, { current_track_transition : action.current_track_transition })
|
||||
|
||||
case 'SET_SELECTED_TRACKS':
|
||||
return Object.assign({}, ui, { selected_tracks : Object.assign([],action.keys) })
|
||||
|
||||
case 'ICON_LOADED':
|
||||
var icons = Object.assign({}, ui.icons);
|
||||
icons[action.key] = action.icon;
|
||||
return Object.assign({}, ui, {icons : icons});
|
||||
|
||||
case 'INSTALL_PROMPT':
|
||||
return Object.assign({}, ui, {install_prompt : action.event});
|
||||
case 'SET_WINDOW_TITLE':
|
||||
if (action.title) {
|
||||
return { ...ui, window_title: action.title };
|
||||
}
|
||||
return ui;
|
||||
|
||||
|
||||
/**
|
||||
case 'TOGGLE_SIDEBAR':
|
||||
var new_state = !ui.sidebar_open;
|
||||
if (typeof (action.new_state) !== 'undefined') new_state = action.new_state;
|
||||
return { ...ui, sidebar_open: new_state };
|
||||
|
||||
case 'SET_CURRENT_TRACK_TRANSITION':
|
||||
return { ...ui, current_track_transition: action.current_track_transition };
|
||||
|
||||
case 'SET_SELECTED_TRACKS':
|
||||
return { ...ui, selected_tracks: Object.assign([], action.keys) };
|
||||
|
||||
case 'ICON_LOADED':
|
||||
var icons = { ...ui.icons };
|
||||
icons[action.key] = action.icon;
|
||||
return { ...ui, icons };
|
||||
|
||||
case 'INSTALL_PROMPT':
|
||||
return { ...ui, install_prompt: action.event };
|
||||
|
||||
|
||||
/**
|
||||
* Context menu
|
||||
**/
|
||||
* */
|
||||
|
||||
case 'SHOW_CONTEXT_MENU':
|
||||
return Object.assign({}, ui, {
|
||||
context_menu: action.data
|
||||
});
|
||||
case 'SHOW_CONTEXT_MENU':
|
||||
return { ...ui, context_menu: action.data };
|
||||
|
||||
case 'HIDE_CONTEXT_MENU':
|
||||
return Object.assign(
|
||||
{},
|
||||
ui,
|
||||
{
|
||||
context_menu: Object.assign({}, ui.context_menu, {closing: true})
|
||||
}
|
||||
);
|
||||
case 'HIDE_CONTEXT_MENU':
|
||||
return {
|
||||
|
||||
case 'REMOVE_CONTEXT_MENU':
|
||||
return Object.assign({}, ui, {context_menu: null});
|
||||
...ui,
|
||||
context_menu: { ...ui.context_menu, closing: true },
|
||||
};
|
||||
|
||||
case 'SHOW_TOUCH_CONTEXT_MENU':
|
||||
return Object.assign({}, ui, {
|
||||
touch_context_menu: action.data
|
||||
});
|
||||
case 'REMOVE_CONTEXT_MENU':
|
||||
return { ...ui, context_menu: null };
|
||||
|
||||
case 'HIDE_TOUCH_CONTEXT_MENU':
|
||||
return Object.assign(
|
||||
{},
|
||||
ui,
|
||||
{
|
||||
touch_context_menu: Object.assign({}, ui.touch_context_menu, {closing: true})
|
||||
}
|
||||
);
|
||||
case 'SHOW_TOUCH_CONTEXT_MENU':
|
||||
return { ...ui, touch_context_menu: action.data };
|
||||
|
||||
case 'REMOVE_TOUCH_CONTEXT_MENU':
|
||||
return Object.assign({}, ui, {touch_context_menu: null});
|
||||
case 'HIDE_TOUCH_CONTEXT_MENU':
|
||||
return {
|
||||
|
||||
...ui,
|
||||
touch_context_menu: { ...ui.touch_context_menu, closing: true },
|
||||
};
|
||||
|
||||
case 'REMOVE_TOUCH_CONTEXT_MENU':
|
||||
return { ...ui, touch_context_menu: null };
|
||||
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Dragging
|
||||
**/
|
||||
* */
|
||||
|
||||
case 'DRAG_START':
|
||||
return Object.assign({}, ui, {
|
||||
dragger: {
|
||||
dragging: true,
|
||||
active: false,
|
||||
context: action.context,
|
||||
from_uri: action.from_uri,
|
||||
victims: action.victims,
|
||||
victims_indexes: action.victims_indexes,
|
||||
start_x: action.start_x,
|
||||
start_y: action.start_y
|
||||
}
|
||||
});
|
||||
case 'DRAG_START':
|
||||
return {
|
||||
...ui,
|
||||
dragger: {
|
||||
dragging: true,
|
||||
active: false,
|
||||
context: action.context,
|
||||
from_uri: action.from_uri,
|
||||
victims: action.victims,
|
||||
victims_indexes: action.victims_indexes,
|
||||
start_x: action.start_x,
|
||||
start_y: action.start_y,
|
||||
},
|
||||
};
|
||||
|
||||
case 'DRAG_ACTIVE':
|
||||
var dragger = Object.assign({}, ui.dragger, { active: true })
|
||||
return Object.assign({}, ui, { dragger: dragger });
|
||||
case 'DRAG_ACTIVE':
|
||||
var dragger = { ...ui.dragger, active: true };
|
||||
return { ...ui, dragger };
|
||||
|
||||
case 'DRAG_END':
|
||||
return Object.assign({}, ui, {
|
||||
dragger: false
|
||||
});
|
||||
case 'DRAG_END':
|
||||
return { ...ui, dragger: false };
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Modals
|
||||
**/
|
||||
* */
|
||||
|
||||
case 'OPEN_MODAL':
|
||||
return Object.assign({}, ui, { modal: action.modal })
|
||||
case 'OPEN_MODAL':
|
||||
return { ...ui, modal: action.modal };
|
||||
|
||||
case 'CLOSE_MODAL':
|
||||
return Object.assign({}, ui, { modal: false })
|
||||
case 'CLOSE_MODAL':
|
||||
return { ...ui, modal: false };
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Notifications
|
||||
**/
|
||||
* */
|
||||
|
||||
case 'CREATE_NOTIFICATION':
|
||||
var notifications = Object.assign({}, ui.notifications);
|
||||
notifications[action.notification.key] = action.notification;
|
||||
return Object.assign({}, ui, { notifications: notifications });
|
||||
case 'CREATE_NOTIFICATION':
|
||||
var notifications = { ...ui.notifications };
|
||||
notifications[action.notification.key] = action.notification;
|
||||
return { ...ui, notifications };
|
||||
|
||||
case 'CLOSE_NOTIFICATION':
|
||||
var notifications = Object.assign({}, ui.notifications);
|
||||
if (notifications[action.key]){
|
||||
notifications[action.key].closing = true;
|
||||
}
|
||||
return Object.assign({}, ui, { notifications: notifications });
|
||||
case 'CLOSE_NOTIFICATION':
|
||||
var notifications = { ...ui.notifications };
|
||||
if (notifications[action.key]) {
|
||||
notifications[action.key].closing = true;
|
||||
}
|
||||
return { ...ui, notifications };
|
||||
|
||||
case 'REMOVE_NOTIFICATION':
|
||||
var notifications = Object.assign({}, ui.notifications);
|
||||
delete notifications[action.key];
|
||||
return Object.assign({}, ui, {notifications: notifications});
|
||||
case 'REMOVE_NOTIFICATION':
|
||||
var notifications = { ...ui.notifications };
|
||||
delete notifications[action.key];
|
||||
return { ...ui, notifications };
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Loading and processes
|
||||
**/
|
||||
* */
|
||||
|
||||
case 'START_LOADING':
|
||||
var load_queue = Object.assign({}, (ui.load_queue ? ui.load_queue : {}))
|
||||
load_queue[action.key] = action.source
|
||||
return Object.assign({}, ui, {load_queue: load_queue})
|
||||
case 'START_LOADING':
|
||||
var load_queue = { ...(ui.load_queue ? ui.load_queue : {}) };
|
||||
load_queue[action.key] = action.source;
|
||||
return { ...ui, load_queue };
|
||||
|
||||
case 'STOP_LOADING':
|
||||
var load_queue = Object.assign({}, (ui.load_queue ? ui.load_queue : {}))
|
||||
if (load_queue[action.key]){
|
||||
delete load_queue[action.key]
|
||||
}
|
||||
return Object.assign({}, ui, {load_queue: load_queue})
|
||||
case 'STOP_LOADING':
|
||||
var load_queue = { ...(ui.load_queue ? ui.load_queue : {}) };
|
||||
if (load_queue[action.key]) {
|
||||
delete load_queue[action.key];
|
||||
}
|
||||
return { ...ui, load_queue };
|
||||
|
||||
case 'START_PROCESS':
|
||||
case 'UPDATE_PROCESS':
|
||||
var processes = Object.assign({}, (ui.processes ? ui.processes : []))
|
||||
if (processes[action.key]){
|
||||
var data = Object.assign({}, processes[action.key].data, action.data)
|
||||
} else {
|
||||
var data = action.data
|
||||
}
|
||||
processes[action.key] = {
|
||||
key: action.key,
|
||||
message: action.message,
|
||||
status: 'running',
|
||||
data: data
|
||||
}
|
||||
return Object.assign({}, ui, {processes: processes})
|
||||
case 'START_PROCESS':
|
||||
case 'UPDATE_PROCESS':
|
||||
var processes = { ...(ui.processes ? ui.processes : []) };
|
||||
if (processes[action.key]) {
|
||||
var data = { ...processes[action.key].data, ...action.data };
|
||||
} else {
|
||||
var { data } = action;
|
||||
}
|
||||
processes[action.key] = {
|
||||
key: action.key,
|
||||
message: action.message,
|
||||
status: 'running',
|
||||
data,
|
||||
};
|
||||
return { ...ui, processes };
|
||||
|
||||
case 'RESUME_PROCESS':
|
||||
var processes = Object.assign({}, (ui.processes ? ui.processes : {}))
|
||||
if (processes[action.key]){
|
||||
processes[action.key] = Object.assign({}, processes[action.key], {status: 'running'})
|
||||
}
|
||||
return Object.assign({}, ui, {processes: processes})
|
||||
case 'RESUME_PROCESS':
|
||||
var processes = { ...(ui.processes ? ui.processes : {}) };
|
||||
if (processes[action.key]) {
|
||||
processes[action.key] = { ...processes[action.key], status: 'running' };
|
||||
}
|
||||
return { ...ui, processes };
|
||||
|
||||
case 'CANCEL_PROCESS':
|
||||
var processes = Object.assign({}, (ui.processes ? ui.processes : {}))
|
||||
if (processes[action.key]){
|
||||
processes[action.key] = Object.assign({}, processes[action.key], {status: 'cancelling'})
|
||||
}
|
||||
return Object.assign({}, ui, {processes: processes})
|
||||
case 'CANCEL_PROCESS':
|
||||
var processes = { ...(ui.processes ? ui.processes : {}) };
|
||||
if (processes[action.key]) {
|
||||
processes[action.key] = { ...processes[action.key], status: 'cancelling' };
|
||||
}
|
||||
return { ...ui, processes };
|
||||
|
||||
case 'PROCESS_CANCELLED':
|
||||
var processes = Object.assign({}, (ui.processes ? ui.processes : {}))
|
||||
if (processes[action.key]){
|
||||
processes[action.key] = Object.assign({}, processes[action.key], {status: 'cancelled'})
|
||||
}
|
||||
return Object.assign({}, ui, {processes: processes})
|
||||
case 'PROCESS_CANCELLED':
|
||||
var processes = { ...(ui.processes ? ui.processes : {}) };
|
||||
if (processes[action.key]) {
|
||||
processes[action.key] = { ...processes[action.key], status: 'cancelled' };
|
||||
}
|
||||
return { ...ui, processes };
|
||||
|
||||
case 'PROCESS_FINISHING':
|
||||
var processes = Object.assign({}, (ui.processes ? ui.processes : {}))
|
||||
if (processes[action.key]){
|
||||
processes[action.key] = Object.assign({}, processes[action.key], {closing: true})
|
||||
}
|
||||
return Object.assign({}, ui, {processes: processes})
|
||||
case 'PROCESS_FINISHING':
|
||||
var processes = { ...(ui.processes ? ui.processes : {}) };
|
||||
if (processes[action.key]) {
|
||||
processes[action.key] = { ...processes[action.key], closing: true };
|
||||
}
|
||||
return { ...ui, processes };
|
||||
|
||||
case 'PROCESS_FINISHED':
|
||||
var processes = Object.assign({}, (ui.processes ? ui.processes : {}))
|
||||
if (processes[action.key]){
|
||||
processes[action.key] = Object.assign({}, processes[action.key], {status: 'finished', closing: false})
|
||||
}
|
||||
return Object.assign({}, ui, {processes: processes})
|
||||
case 'PROCESS_FINISHED':
|
||||
var processes = { ...(ui.processes ? ui.processes : {}) };
|
||||
if (processes[action.key]) {
|
||||
processes[action.key] = { ...processes[action.key], status: 'finished', closing: false };
|
||||
}
|
||||
return { ...ui, processes };
|
||||
|
||||
|
||||
default:
|
||||
return ui
|
||||
}
|
||||
default:
|
||||
return ui;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user