Auto eslint fix
This commit is contained in:
@ -1,31 +1,31 @@
|
||||
|
||||
export function set(data){
|
||||
return {
|
||||
type: 'GOOGLE_SET',
|
||||
data: data
|
||||
}
|
||||
export function set(data) {
|
||||
return {
|
||||
type: 'GOOGLE_SET',
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
export function getLibraryArtists(){
|
||||
return {
|
||||
type: 'GOOGLE_GET_LIBRARY_ARTISTS'
|
||||
}
|
||||
export function getLibraryArtists() {
|
||||
return {
|
||||
type: 'GOOGLE_GET_LIBRARY_ARTISTS',
|
||||
};
|
||||
}
|
||||
|
||||
export function clearLibraryArtists(){
|
||||
return {
|
||||
type: 'GOOGLE_CLEAR_LIBRARY_ARTISTS'
|
||||
}
|
||||
export function clearLibraryArtists() {
|
||||
return {
|
||||
type: 'GOOGLE_CLEAR_LIBRARY_ARTISTS',
|
||||
};
|
||||
}
|
||||
|
||||
export function getLibraryAlbums(){
|
||||
return {
|
||||
'type': 'GOOGLE_GET_LIBRARY_ALBUMS'
|
||||
}
|
||||
export function getLibraryAlbums() {
|
||||
return {
|
||||
type: 'GOOGLE_GET_LIBRARY_ALBUMS',
|
||||
};
|
||||
}
|
||||
|
||||
export function clearLibraryAlbums(){
|
||||
return {
|
||||
type: 'GOOGLE_CLEAR_LIBRARY_ALBUMS'
|
||||
}
|
||||
}
|
||||
export function clearLibraryAlbums() {
|
||||
return {
|
||||
type: 'GOOGLE_CLEAR_LIBRARY_ALBUMS',
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,145 +1,140 @@
|
||||
|
||||
import ReactGA from 'react-ga'
|
||||
import ReactGA from 'react-ga';
|
||||
|
||||
var helpers = require('../../helpers');
|
||||
var coreActions = require('../core/actions');
|
||||
var mopidyActions = require('../mopidy/actions');
|
||||
var uiActions = require('../ui/actions');
|
||||
const helpers = require('../../helpers');
|
||||
const coreActions = require('../core/actions');
|
||||
const mopidyActions = require('../mopidy/actions');
|
||||
const uiActions = require('../ui/actions');
|
||||
|
||||
const GoogleMiddleware = (function(){
|
||||
|
||||
// A Google request is an alias of the Mopidy request
|
||||
const request = (store, method, params = null, response_callback = null, error_callback = null) => {
|
||||
store.dispatch(
|
||||
const GoogleMiddleware = (function () {
|
||||
// A Google request is an alias of the Mopidy request
|
||||
const request = (store, method, params = null, response_callback = null, error_callback = null) => {
|
||||
store.dispatch(
|
||||
mopidyActions.request(
|
||||
method,
|
||||
params,
|
||||
response_callback,
|
||||
error_callback
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
error_callback,
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
return store => next => action => {
|
||||
var google = store.getState().google;
|
||||
return (store) => (next) => (action) => {
|
||||
const { google } = store.getState();
|
||||
|
||||
switch(action.type){
|
||||
case 'GOOGLE_GET_LIBRARY_ALBUMS':
|
||||
var last_run = store.getState().ui.processes.GOOGLE_LIBRARY_ALBUMS_PROCESSOR
|
||||
switch (action.type) {
|
||||
case 'GOOGLE_GET_LIBRARY_ALBUMS':
|
||||
var last_run = store.getState().ui.processes.GOOGLE_LIBRARY_ALBUMS_PROCESSOR;
|
||||
|
||||
if (!last_run){
|
||||
request(
|
||||
store,
|
||||
'library.browse',
|
||||
{
|
||||
uri: 'gmusic:album'
|
||||
},
|
||||
response => {
|
||||
if (response.length <= 0){
|
||||
return;
|
||||
}
|
||||
if (!last_run) {
|
||||
request(
|
||||
store,
|
||||
'library.browse',
|
||||
{
|
||||
uri: 'gmusic:album',
|
||||
},
|
||||
(response) => {
|
||||
if (response.length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var uris = helpers.arrayOf('uri',response);
|
||||
store.dispatch({
|
||||
type: 'GOOGLE_LIBRARY_ALBUMS_LOADED',
|
||||
uris: uris
|
||||
});
|
||||
const uris = helpers.arrayOf('uri', response);
|
||||
store.dispatch({
|
||||
type: 'GOOGLE_LIBRARY_ALBUMS_LOADED',
|
||||
uris,
|
||||
});
|
||||
|
||||
// Start our process to load the full album objects
|
||||
store.dispatch(uiActions.startProcess(
|
||||
'GOOGLE_LIBRARY_ALBUMS_PROCESSOR',
|
||||
'Loading '+uris.length+' Google albums',
|
||||
{
|
||||
uris: uris,
|
||||
total: uris.length,
|
||||
remaining: uris.length
|
||||
}
|
||||
));
|
||||
}
|
||||
);
|
||||
|
||||
} else if (last_run.status == 'cancelled'){
|
||||
store.dispatch(uiActions.resumeProcess('GOOGLE_LIBRARY_ALBUMS_PROCESSOR'))
|
||||
} else if (last_run.status == 'finished'){
|
||||
// TODO: do we want to force a refresh?
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'GOOGLE_LIBRARY_ALBUMS_PROCESSOR':
|
||||
if (store.getState().ui.processes['GOOGLE_LIBRARY_ALBUMS_PROCESSOR'] !== undefined){
|
||||
var processor = store.getState().ui.processes['GOOGLE_LIBRARY_ALBUMS_PROCESSOR']
|
||||
|
||||
if (processor.status == 'cancelling'){
|
||||
store.dispatch(uiActions.processCancelled('GOOGLE_LIBRARY_ALBUMS_PROCESSOR'))
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
var uris = Object.assign([], action.data.uris);
|
||||
var uris_to_load = uris.splice(0,50);
|
||||
|
||||
if (uris_to_load.length > 0){
|
||||
store.dispatch(uiActions.updateProcess(
|
||||
'GOOGLE_LIBRARY_ALBUMS_PROCESSOR',
|
||||
'Loading '+uris.length+' Google albums',
|
||||
{
|
||||
uris: uris,
|
||||
remaining: uris.length
|
||||
}
|
||||
));
|
||||
store.dispatch(mopidyActions.getAlbums(uris_to_load, {name: 'GOOGLE_LIBRARY_ALBUMS_PROCESSOR', data: {uris: uris}}))
|
||||
} else {
|
||||
store.dispatch(uiActions.processFinishing('GOOGLE_LIBRARY_ALBUMS_PROCESSOR'));
|
||||
}
|
||||
|
||||
break
|
||||
|
||||
case 'GOOGLE_GET_LIBRARY_ARTISTS':
|
||||
request(
|
||||
store,
|
||||
'library.browse',
|
||||
{
|
||||
uri: 'gmusic:artist'
|
||||
},
|
||||
response => {
|
||||
if (response.length <= 0){
|
||||
return
|
||||
}
|
||||
|
||||
var uris = [];
|
||||
for (var i = 0; i < response.length; i++){
|
||||
|
||||
// Convert local URI to actual artist URI
|
||||
// See https://github.com/mopidy/mopidy-local-sqlite/issues/39
|
||||
response[i].uri = response[i].uri.replace('local:directory?albumartist=','');
|
||||
uris.push(response[i].uri);
|
||||
}
|
||||
|
||||
store.dispatch(coreActions.artistsLoaded(response));
|
||||
|
||||
store.dispatch({
|
||||
type: 'GOOGLE_LIBRARY_ARTISTS_LOADED',
|
||||
uris: uris
|
||||
});
|
||||
},
|
||||
error => {
|
||||
store.dispatch(coreActions.handleException(
|
||||
'Could not load Google artists',
|
||||
error
|
||||
));
|
||||
}
|
||||
);
|
||||
break;
|
||||
|
||||
|
||||
// This action is irrelevant to us, pass it on to the next middleware
|
||||
default:
|
||||
return next(action);
|
||||
// Start our process to load the full album objects
|
||||
store.dispatch(uiActions.startProcess(
|
||||
'GOOGLE_LIBRARY_ALBUMS_PROCESSOR',
|
||||
`Loading ${uris.length} Google albums`,
|
||||
{
|
||||
uris,
|
||||
total: uris.length,
|
||||
remaining: uris.length,
|
||||
},
|
||||
));
|
||||
},
|
||||
);
|
||||
} else if (last_run.status == 'cancelled') {
|
||||
store.dispatch(uiActions.resumeProcess('GOOGLE_LIBRARY_ALBUMS_PROCESSOR'));
|
||||
} else if (last_run.status == 'finished') {
|
||||
// TODO: do we want to force a refresh?
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'GOOGLE_LIBRARY_ALBUMS_PROCESSOR':
|
||||
if (store.getState().ui.processes.GOOGLE_LIBRARY_ALBUMS_PROCESSOR !== undefined) {
|
||||
const processor = store.getState().ui.processes.GOOGLE_LIBRARY_ALBUMS_PROCESSOR;
|
||||
|
||||
if (processor.status == 'cancelling') {
|
||||
store.dispatch(uiActions.processCancelled('GOOGLE_LIBRARY_ALBUMS_PROCESSOR'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var uris = Object.assign([], action.data.uris);
|
||||
var uris_to_load = uris.splice(0, 50);
|
||||
|
||||
if (uris_to_load.length > 0) {
|
||||
store.dispatch(uiActions.updateProcess(
|
||||
'GOOGLE_LIBRARY_ALBUMS_PROCESSOR',
|
||||
`Loading ${uris.length} Google albums`,
|
||||
{
|
||||
uris,
|
||||
remaining: uris.length,
|
||||
},
|
||||
));
|
||||
store.dispatch(mopidyActions.getAlbums(uris_to_load, { name: 'GOOGLE_LIBRARY_ALBUMS_PROCESSOR', data: { uris } }));
|
||||
} else {
|
||||
store.dispatch(uiActions.processFinishing('GOOGLE_LIBRARY_ALBUMS_PROCESSOR'));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'GOOGLE_GET_LIBRARY_ARTISTS':
|
||||
request(
|
||||
store,
|
||||
'library.browse',
|
||||
{
|
||||
uri: 'gmusic:artist',
|
||||
},
|
||||
(response) => {
|
||||
if (response.length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const uris = [];
|
||||
for (let i = 0; i < response.length; i++) {
|
||||
// Convert local URI to actual artist URI
|
||||
// See https://github.com/mopidy/mopidy-local-sqlite/issues/39
|
||||
response[i].uri = response[i].uri.replace('local:directory?albumartist=', '');
|
||||
uris.push(response[i].uri);
|
||||
}
|
||||
|
||||
store.dispatch(coreActions.artistsLoaded(response));
|
||||
|
||||
store.dispatch({
|
||||
type: 'GOOGLE_LIBRARY_ARTISTS_LOADED',
|
||||
uris,
|
||||
});
|
||||
},
|
||||
(error) => {
|
||||
store.dispatch(coreActions.handleException(
|
||||
'Could not load Google artists',
|
||||
error,
|
||||
));
|
||||
},
|
||||
);
|
||||
break;
|
||||
|
||||
|
||||
// This action is irrelevant to us, pass it on to the next middleware
|
||||
default:
|
||||
return next(action);
|
||||
}
|
||||
};
|
||||
}());
|
||||
|
||||
})();
|
||||
|
||||
export default GoogleMiddleware
|
||||
export default GoogleMiddleware;
|
||||
|
||||
@ -1,38 +1,34 @@
|
||||
|
||||
import * as helpers from '../../helpers';
|
||||
|
||||
export default function reducer(google = {}, action){
|
||||
switch (action.type){
|
||||
export default function reducer(google = {}, action) {
|
||||
switch (action.type) {
|
||||
case 'GOOGLE_SET':
|
||||
return { ...google, ...action.data };
|
||||
|
||||
case 'GOOGLE_SET':
|
||||
return Object.assign({}, google, action.data);
|
||||
case 'GOOGLE_LIBRARY_ARTISTS_LOADED':
|
||||
if (google.library_artists) {
|
||||
var uris = [...google.library_artists, ...action.uris];
|
||||
} else {
|
||||
var { uris } = action;
|
||||
}
|
||||
return { ...google, library_artists: helpers.removeDuplicates(uris) };
|
||||
|
||||
case 'GOOGLE_LIBRARY_ARTISTS_LOADED':
|
||||
if (google.library_artists){
|
||||
var uris = [...google.library_artists,...action.uris];
|
||||
} else {
|
||||
var uris = action.uris;
|
||||
}
|
||||
return Object.assign({}, google, { library_artists: helpers.removeDuplicates(uris) });
|
||||
case 'GOOGLE_CLEAR_LIBRARY_ARTISTS':
|
||||
return { ...google, library_artists: null };
|
||||
|
||||
case 'GOOGLE_CLEAR_LIBRARY_ARTISTS':
|
||||
return Object.assign({}, google, { library_artists: null });
|
||||
case 'GOOGLE_LIBRARY_ALBUMS_LOADED':
|
||||
if (google.library_albums) {
|
||||
var uris = [...google.library_albums, ...action.uris];
|
||||
} else {
|
||||
var { uris } = action;
|
||||
}
|
||||
return { ...google, library_albums: helpers.removeDuplicates(uris) };
|
||||
|
||||
case 'GOOGLE_LIBRARY_ALBUMS_LOADED':
|
||||
if (google.library_albums){
|
||||
var uris = [...google.library_albums,...action.uris];
|
||||
} else {
|
||||
var uris = action.uris;
|
||||
}
|
||||
return Object.assign({}, google, { library_albums: helpers.removeDuplicates(uris) });
|
||||
case 'GOOGLE_CLEAR_LIBRARY_ALBUMS':
|
||||
return { ...google, library_albums: null };
|
||||
|
||||
case 'GOOGLE_CLEAR_LIBRARY_ALBUMS':
|
||||
return Object.assign({}, google, { library_albums: null });
|
||||
|
||||
default:
|
||||
return google
|
||||
}
|
||||
default:
|
||||
return google;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user