Fully-functional proof-of-concept

This commit is contained in:
James Barnsley
2018-11-02 16:10:38 +13:00
parent 4c100a9527
commit acad6490f5
13 changed files with 453 additions and 356 deletions

View File

@ -30,18 +30,6 @@ export function connecting(){
}
}
export function upgrading(){
return {
type: 'MOPIDY_UPGRADING'
}
}
export function restarting(){
return {
type: 'MOPIDY_RESTARTING'
}
}
export function disconnect(){
return {
type: 'MOPIDY_DISCONNECT'
@ -56,6 +44,42 @@ export function debug(call, value){
}
}
export function restartStarted(){
return {
type: 'MOPIDY_RESTART_STARTED'
}
}
export function restartFinished(){
return {
type: 'MOPIDY_RESTART_FINISHED'
}
}
export function upgradeStarted(){
return {
type: 'MOPIDY_UPGRADE_STARTED'
}
}
export function upgradeFinished(){
return {
type: 'MOPIDY_UPGRADE_FINISHED'
}
}
export function localScanStarted(){
return {
type: 'MOPIDY_LOCAL_SCAN_STARTED'
}
}
export function localScanFinished(){
return {
type: 'MOPIDY_LOCAL_SCAN_FINISHED'
}
}
/**
* Core play actions
**/

View File

@ -4,21 +4,29 @@ import * as helpers from '../../helpers';
export default function reducer(mopidy = {}, action){
switch (action.type){
case 'MOPIDY_SET':
return Object.assign({}, mopidy, action.data);
case 'MOPIDY_CONNECT':
case 'MOPIDY_CONNECTING':
return Object.assign({}, mopidy, { connected: false, connecting: true });
case 'MOPIDY_RESTARTING':
return Object.assign({}, mopidy, { restarting: true });
case 'MOPIDY_UPGRADING':
return Object.assign({}, mopidy, { upgrading: true });
return Object.assign({}, mopidy, {
connected: false,
connecting: true
});
case 'MOPIDY_CONNECTED':
return Object.assign({}, mopidy, { connected: true, connecting: false, restarting: false, upgrading: false });
return Object.assign({}, mopidy, {
connected: true,
connecting: false,
restart_running: false,
upgrade_running: false
});
case 'MOPIDY_DISCONNECTED':
return Object.assign({}, mopidy, { connected: false, connecting: false });
return Object.assign({}, mopidy, {
connected: false,
connecting: false
});
case 'MOPIDY_CHANGE_TRACK':
return Object.assign({}, mopidy, {
@ -30,8 +38,23 @@ export default function reducer(mopidy = {}, action){
uri_schemes: action.uri_schemes
});
case 'MOPIDY_SET':
return Object.assign({}, mopidy, action.data);
case 'MOPIDY_RESTART_STARTED':
return Object.assign({}, mopidy, { restart_running: true });
case 'MOPIDY_RESTART_FINISHED':
return Object.assign({}, mopidy, { restart_running: false });
case 'MOPIDY_UPGRADE_STARTED':
return Object.assign({}, mopidy, { upgrade_running: true });
case 'MOPIDY_UPGRADE_FINISHED':
return Object.assign({}, mopidy, { upgrade_running: false });
case 'MOPIDY_LOCAL_SCAN_STARTED':
return Object.assign({}, mopidy, { local_scan_running: true });
case 'MOPIDY_LOCAL_SCAN_FINISHED':
return Object.assign({}, mopidy, { local_scan_running: false });
/**

View File

@ -48,9 +48,15 @@ export function restart(){
}
}
export function runLocalScan(){
export function localScan(){
return {
type: 'PUSHER_RUN_LOCAL_SCAN'
type: 'PUSHER_LOCAL_SCAN'
}
}
export function test(){
return {
type: 'PUSHER_TEST'
}
}

View File

@ -114,14 +114,13 @@ const PusherMiddleware = (function(){
case 'reload':
window.location.reload(true);
break;
case 'upgrading':
case 'upgrade_started':
store.dispatch(mopidyActions.upgrading());
store.dispatch(uiActions.createNotification({content: 'Upgrading...', type: 'info'}));
break;
case 'restarting':
store.dispatch(mopidyActions.restarting());
store.dispatch(uiActions.createNotification({content: 'Restarting...', type: 'info'}));
case 'update_process':
if (message.params.finished){
store.dispatch(uiActions.processFinished(message.params.key));
store.dispatch(uiActions.createNotification(message.params));
} else {
store.dispatch(uiActions.updateProcess(message.params.key, message.params.message));
}
break;
}
}
@ -649,15 +648,7 @@ const PusherMiddleware = (function(){
break
case 'PUSHER_RESTART':
request(store, 'restart')
.then(
response => {
store.dispatch(mopidyActions.restarting());
},
error => {
store.dispatch(uiActions.createNotification({content: error.message, description: (error.description ? error.description : null), type: 'bad'}));
}
);
request(store, 'restart');
next(action);
break
@ -665,30 +656,18 @@ const PusherMiddleware = (function(){
if (store.getState().ui.allow_reporting){
ReactGA.event({ category: 'Pusher', action: 'Upgrade', label: '' });
}
request(store, 'upgrade')
.then(
response => {
store.dispatch(mopidyActions.upgrading());
},
error => {
store.dispatch(uiActions.createNotification({content: error.message, description: (error.description ? error.description : null), type: 'bad'}));
}
);
request(store, 'upgrade');
break;
case 'PUSHER_RUN_LOCAL_SCAN':
case 'PUSHER_LOCAL_SCAN':
if (store.getState().ui.allow_reporting){
ReactGA.event({ category: 'Pusher', action: 'Run local scan', label: '' });
ReactGA.event({ category: 'Pusher', action: 'Local scan', label: '' });
}
request(store, 'run_local_scan')
.then(
response => {
store.dispatch(mopidyActions.localScanRunning());
},
error => {
store.dispatch(uiActions.createNotification({content: error.message, description: (error.description ? error.description : null), type: 'bad'}));
}
);
request(store, 'local_scan');
break;
case 'PUSHER_TEST':
request(store, 'test');
break;
case 'PUSHER_VERSION':

View File

@ -136,6 +136,12 @@ export function createBrowserNotification(data){
}
export function createNotification(data){
// Allow 'message' as an alias of our content
if (data.message){
data.content = data.message;
}
return {
type: 'CREATE_NOTIFICATION',
notification: Object.assign(