Splitting out helpers into separate files
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
|
||||
import * as helpers from '../../helpers';
|
||||
import { createRange } from '../../util/arrays';
|
||||
import { uriSource } from '../../util/helpers';
|
||||
|
||||
const spotifyActions = require('../../services/spotify/actions');
|
||||
const mopidyActions = require('../../services/mopidy/actions');
|
||||
@ -247,8 +248,8 @@ export function removeFromIndex(index_name, key, new_key = null) {
|
||||
* */
|
||||
|
||||
export function reorderPlaylistTracks(uri, indexes, insert_before, snapshot_id = false) {
|
||||
const range = helpers.createRange(indexes);
|
||||
switch (helpers.uriSource(uri)) {
|
||||
const range = createRange(indexes);
|
||||
switch (uriSource(uri)) {
|
||||
case 'spotify':
|
||||
return {
|
||||
type: 'SPOTIFY_REORDER_PLAYLIST_TRACKS',
|
||||
@ -271,7 +272,7 @@ export function reorderPlaylistTracks(uri, indexes, insert_before, snapshot_id =
|
||||
}
|
||||
|
||||
export function savePlaylist(uri, name, description = '', is_public = false, is_collaborative = false, image = null) {
|
||||
switch (helpers.uriSource(uri)) {
|
||||
switch (uriSource(uri)) {
|
||||
case 'spotify':
|
||||
return {
|
||||
type: 'SPOTIFY_SAVE_PLAYLIST',
|
||||
@ -308,7 +309,7 @@ export function createPlaylist(scheme, name, description = '', is_public = false
|
||||
}
|
||||
|
||||
export function deletePlaylist(uri) {
|
||||
switch (helpers.uriSource(uri)) {
|
||||
switch (uriSource(uri)) {
|
||||
case 'spotify':
|
||||
return spotifyActions.following(uri, 'DELETE');
|
||||
|
||||
@ -319,7 +320,7 @@ export function deletePlaylist(uri) {
|
||||
}
|
||||
|
||||
export function removeTracksFromPlaylist(uri, tracks_indexes) {
|
||||
switch (helpers.uriSource(uri)) {
|
||||
switch (uriSource(uri)) {
|
||||
case 'spotify':
|
||||
return {
|
||||
type: 'SPOTIFY_REMOVE_PLAYLIST_TRACKS',
|
||||
@ -337,7 +338,7 @@ export function removeTracksFromPlaylist(uri, tracks_indexes) {
|
||||
}
|
||||
|
||||
export function addTracksToPlaylist(uri, tracks_uris) {
|
||||
switch (helpers.uriSource(uri)) {
|
||||
switch (uriSource(uri)) {
|
||||
case 'spotify':
|
||||
return {
|
||||
type: 'SPOTIFY_ADD_PLAYLIST_TRACKS',
|
||||
|
||||
@ -1,13 +1,21 @@
|
||||
|
||||
import ReactGA from 'react-ga';
|
||||
import { arrayOf } from '../../util/arrays';
|
||||
import { uriSource, upgradeSpotifyPlaylistUris } from '../../util/helpers';
|
||||
import {
|
||||
formatTracks,
|
||||
formatTrack,
|
||||
formatSimpleObject,
|
||||
formatAlbum,
|
||||
formatArtist,
|
||||
formatPlaylist,
|
||||
formatUser,
|
||||
} from '../../util/format';
|
||||
|
||||
const coreActions = require('./actions.js');
|
||||
const uiActions = require('../ui/actions.js');
|
||||
const pusherActions = require('../pusher/actions.js');
|
||||
const mopidyActions = require('../mopidy/actions.js');
|
||||
const spotifyActions = require('../spotify/actions.js');
|
||||
const lastfmActions = require('../lastfm/actions.js');
|
||||
const helpers = require('../../helpers.js');
|
||||
|
||||
const CoreMiddleware = (function () {
|
||||
/**
|
||||
@ -215,8 +223,8 @@ const CoreMiddleware = (function () {
|
||||
* */
|
||||
|
||||
case 'PLAYLIST_TRACKS':
|
||||
var tracks = helpers.formatTracks(action.tracks);
|
||||
action.tracks_uris = helpers.arrayOf('uri', tracks);
|
||||
var tracks = formatTracks(action.tracks);
|
||||
action.tracks_uris = arrayOf('uri', tracks);
|
||||
|
||||
store.dispatch({
|
||||
type: 'TRACKS_LOADED',
|
||||
@ -228,7 +236,7 @@ const CoreMiddleware = (function () {
|
||||
|
||||
case 'PLAYLIST_TRACKS_ADDED':
|
||||
store.dispatch(uiActions.createNotification({ level: 'warning', content: `Added ${action.tracks_uris.length} tracks to playlist` }));
|
||||
switch (helpers.uriSource(action.key)) {
|
||||
switch (uriSource(action.key)) {
|
||||
case 'spotify':
|
||||
store.dispatch(spotifyActions.getPlaylist(action.key));
|
||||
break;
|
||||
@ -318,7 +326,7 @@ const CoreMiddleware = (function () {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (helpers.uriSource(action.uri)) {
|
||||
switch (uriSource(action.uri)) {
|
||||
case 'spotify':
|
||||
store.dispatch(spotifyActions.getTrack(action.uri));
|
||||
|
||||
@ -346,7 +354,7 @@ const CoreMiddleware = (function () {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (helpers.uriSource(action.uri)) {
|
||||
switch (uriSource(action.uri)) {
|
||||
case 'spotify':
|
||||
store.dispatch(spotifyActions.getAlbum(action.uri));
|
||||
|
||||
@ -375,7 +383,7 @@ const CoreMiddleware = (function () {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (helpers.uriSource(action.uri)) {
|
||||
switch (uriSource(action.uri)) {
|
||||
case 'spotify':
|
||||
store.dispatch(spotifyActions.getArtist(action.uri, true));
|
||||
|
||||
@ -403,7 +411,7 @@ const CoreMiddleware = (function () {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (helpers.uriSource(action.uri)) {
|
||||
switch (uriSource(action.uri)) {
|
||||
case 'spotify':
|
||||
store.dispatch(spotifyActions.getPlaylist(action.uri));
|
||||
|
||||
@ -431,7 +439,7 @@ const CoreMiddleware = (function () {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (helpers.uriSource(action.uri)) {
|
||||
switch (uriSource(action.uri)) {
|
||||
case 'spotify':
|
||||
store.dispatch(spotifyActions.getUser(action.uri));
|
||||
|
||||
@ -457,7 +465,7 @@ const CoreMiddleware = (function () {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (helpers.uriSource(action.uri)) {
|
||||
switch (uriSource(action.uri)) {
|
||||
case 'spotify':
|
||||
store.dispatch(spotifyActions.getUserPlaylists(action.uri));
|
||||
break;
|
||||
@ -478,13 +486,13 @@ const CoreMiddleware = (function () {
|
||||
|
||||
case 'CURRENT_TRACK_LOADED':
|
||||
store.dispatch(coreActions.trackLoaded(action.track));
|
||||
action.track = helpers.formatTrack(action.track);
|
||||
action.track = formatTrack(action.track);
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'QUEUE_LOADED':
|
||||
store.dispatch(coreActions.tracksLoaded(action.tracks));
|
||||
action.tracks = helpers.formatTracks(action.tracks);
|
||||
action.tracks = formatTracks(action.tracks);
|
||||
next(action);
|
||||
break;
|
||||
|
||||
@ -497,31 +505,25 @@ const CoreMiddleware = (function () {
|
||||
var albums_loaded = [];
|
||||
|
||||
for (const raw_track of action.tracks) {
|
||||
var track = helpers.formatTrack(raw_track);
|
||||
var track = formatTrack(raw_track);
|
||||
|
||||
if (tracks_index[track.uri] !== undefined) {
|
||||
track = { ...tracks_index[track.uri], ...track };
|
||||
}
|
||||
|
||||
if (raw_track.album) {
|
||||
track.album = helpers.formatSimpleObject(raw_track.album);
|
||||
track.album = formatSimpleObject(raw_track.album);
|
||||
|
||||
if (!albums_index[raw_track.album.uri]) {
|
||||
albums_loaded.push(raw_track.album);
|
||||
}
|
||||
|
||||
// Copy the images to the track
|
||||
/*
|
||||
if (raw_track.album.images){
|
||||
track.images = helpers.digestMopidyImages(store.getState().mopidy, raw_track.album.images);
|
||||
} */
|
||||
}
|
||||
|
||||
if (raw_track.artists && raw_track.artists.length > 0) {
|
||||
track.artists = [];
|
||||
|
||||
for (var artist of raw_track.artists) {
|
||||
track.artists.push(helpers.formatSimpleObject(artist));
|
||||
track.artists.push(formatSimpleObject(artist));
|
||||
|
||||
// Not already in our index, so let's add it
|
||||
if (!artists_index[artist.uri]) {
|
||||
@ -552,22 +554,18 @@ const CoreMiddleware = (function () {
|
||||
var tracks_loaded = [];
|
||||
|
||||
for (const raw_album of action.albums) {
|
||||
let album = helpers.formatAlbum(raw_album);
|
||||
let album = formatAlbum(raw_album);
|
||||
|
||||
if (albums_index[album.uri]) {
|
||||
album = { ...albums_index[album.uri], ...album };
|
||||
}
|
||||
/*
|
||||
if (raw_album.images && raw_album.images.length > 0){
|
||||
album.images = helpers.digestMopidyImages(store.getState().mopidy, raw_album.images);
|
||||
} */
|
||||
|
||||
if (raw_album.tracks) {
|
||||
album.tracks_uris = [];
|
||||
|
||||
for (var track of raw_album.tracks) {
|
||||
if (!track.album) {
|
||||
track.album = helpers.formatSimpleObject(album);
|
||||
track.album = formatSimpleObject(album);
|
||||
}
|
||||
album.tracks_uris.push(track.uri);
|
||||
tracks_loaded.push(track);
|
||||
@ -575,7 +573,7 @@ const CoreMiddleware = (function () {
|
||||
}
|
||||
|
||||
if (raw_album.artists) {
|
||||
album.artists_uris = helpers.arrayOf('uri', raw_album.artists);
|
||||
album.artists_uris = arrayOf('uri', raw_album.artists);
|
||||
artists_loaded = [...artists_loaded, ...raw_album.artists];
|
||||
}
|
||||
|
||||
@ -600,7 +598,7 @@ const CoreMiddleware = (function () {
|
||||
var tracks_loaded = [];
|
||||
|
||||
for (const raw_artist of action.artists) {
|
||||
var artist = helpers.formatArtist(raw_artist);
|
||||
var artist = formatArtist(raw_artist);
|
||||
|
||||
// Already have an artist in the index
|
||||
if (artists_index[artist.uri]) {
|
||||
@ -631,8 +629,8 @@ const CoreMiddleware = (function () {
|
||||
|
||||
// Migrate nested tracks objects into references to our tracks index
|
||||
if (raw_artist.tracks) {
|
||||
var tracks = helpers.formatTracks(raw_artist.tracks);
|
||||
var tracks_uris = helpers.arrayOf('uri', tracks);
|
||||
var tracks = formatTracks(raw_artist.tracks);
|
||||
var tracks_uris = arrayOf('uri', tracks);
|
||||
artist.tracks_uris = tracks_uris;
|
||||
tracks_loaded = [...tracks_loaded, ...tracks];
|
||||
}
|
||||
@ -655,10 +653,10 @@ const CoreMiddleware = (function () {
|
||||
var tracks_loaded = [];
|
||||
|
||||
for (var playlist of action.playlists) {
|
||||
playlist = helpers.formatPlaylist(playlist);
|
||||
playlist = formatPlaylist(playlist);
|
||||
|
||||
// Detect editability
|
||||
switch (helpers.uriSource(playlist.uri)) {
|
||||
switch (uriSource(playlist.uri)) {
|
||||
case 'm3u':
|
||||
playlist.can_edit = true;
|
||||
break;
|
||||
@ -681,8 +679,8 @@ const CoreMiddleware = (function () {
|
||||
|
||||
// Load our tracks
|
||||
if (playlist.tracks) {
|
||||
var tracks = helpers.formatTracks(playlist.tracks);
|
||||
var tracks_uris = helpers.arrayOf('uri', tracks);
|
||||
var tracks = formatTracks(playlist.tracks);
|
||||
var tracks_uris = arrayOf('uri', tracks);
|
||||
playlist.tracks_uris = tracks_uris;
|
||||
delete playlist.tracks;
|
||||
tracks_loaded = [...tracks_loaded, ...tracks];
|
||||
@ -706,7 +704,7 @@ const CoreMiddleware = (function () {
|
||||
var users_loaded = [];
|
||||
|
||||
for (let user of action.users) {
|
||||
user = helpers.formatUser(user);
|
||||
user = formatUser(user);
|
||||
|
||||
if (users_index[user.uri]) {
|
||||
user = { ...users_index[user.uri], ...user };
|
||||
@ -753,12 +751,12 @@ const CoreMiddleware = (function () {
|
||||
// Pre-emptively format tracks
|
||||
// Providers give us tracks in all kinds of structures, so this cleans things first
|
||||
if (action.records_type == 'track') {
|
||||
records = helpers.formatTracks(records);
|
||||
records = formatTracks(records);
|
||||
}
|
||||
|
||||
var records_type_plural = `${action.records_type}s`;
|
||||
var records_index = {};
|
||||
var records_uris = helpers.arrayOf('uri', records);
|
||||
var records_uris = arrayOf('uri', records);
|
||||
|
||||
// Merge any extra data (eg more_track's albums)
|
||||
if (action.extra_data) {
|
||||
@ -768,7 +766,7 @@ const CoreMiddleware = (function () {
|
||||
// If we're a list of playlists, we need to manually filter Spotify's new URI structure
|
||||
// Really poor form because they haven't updated it everywhere, yet
|
||||
if (action.records_type == 'playlist') {
|
||||
records_uris = helpers.upgradeSpotifyPlaylistUris(records_uris);
|
||||
records_uris = upgradeSpotifyPlaylistUris(records_uris);
|
||||
}
|
||||
|
||||
// Append our parent object's reference to these records
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
|
||||
import * as helpers from '../../helpers';
|
||||
import { removeDuplicates, arrayOf } from '../../util/arrays';
|
||||
import { formatTracks } from '../../util/format';
|
||||
|
||||
export default function reducer(core = {}, action) {
|
||||
switch (action.type) {
|
||||
@ -126,7 +127,7 @@ export default function reducer(core = {}, action) {
|
||||
existing_playlists_uris = users[action.uri].playlists_uris;
|
||||
}
|
||||
|
||||
var playlists_uris = [...existing_playlists_uris, ...helpers.arrayOf('uri', action.playlists)];
|
||||
var playlists_uris = [...existing_playlists_uris, ...arrayOf('uri', action.playlists)];
|
||||
|
||||
var user = {
|
||||
|
||||
@ -181,7 +182,7 @@ export default function reducer(core = {}, action) {
|
||||
var library_playlists = action.uris;
|
||||
}
|
||||
|
||||
library_playlists = helpers.removeDuplicates(library_playlists);
|
||||
library_playlists = removeDuplicates(library_playlists);
|
||||
|
||||
return {
|
||||
...core,
|
||||
@ -263,7 +264,7 @@ export default function reducer(core = {}, action) {
|
||||
} else {
|
||||
var tracks = [];
|
||||
}
|
||||
if (action.tracks) tracks = [...tracks, ...helpers.formatTracks(action.tracks)];
|
||||
if (action.tracks) tracks = [...tracks, ...formatTracks(action.tracks)];
|
||||
|
||||
// more tracks
|
||||
if (typeof (action.tracks_more) !== 'undefined') var { tracks_more } = action;
|
||||
@ -274,11 +275,11 @@ export default function reducer(core = {}, action) {
|
||||
...core,
|
||||
search_results: {
|
||||
artists_more,
|
||||
artists_uris: helpers.removeDuplicates(artists_uris),
|
||||
artists_uris: removeDuplicates(artists_uris),
|
||||
albums_more,
|
||||
albums_uris: helpers.removeDuplicates(albums_uris),
|
||||
albums_uris: removeDuplicates(albums_uris),
|
||||
playlists_more,
|
||||
playlists_uris: helpers.removeDuplicates(playlists_uris),
|
||||
playlists_uris: removeDuplicates(playlists_uris),
|
||||
tracks,
|
||||
tracks_more,
|
||||
},
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
|
||||
import { generateGuid } from '../../util/helpers';
|
||||
|
||||
const coreActions = require('../core/actions');
|
||||
const uiActions = require('../ui/actions');
|
||||
const helpers = require('../../helpers');
|
||||
|
||||
/**
|
||||
* Send an ajax request to the LastFM API
|
||||
@ -16,7 +17,7 @@ const sendRequest = (dispatch, getState, endpoint, params) => new Promise((resol
|
||||
const secret = 'KiEUfwKpebxRnEHlKoXnYIftJxeuqjTK';
|
||||
const url = `https://api.discogs.com/${endpoint}?${params}`;
|
||||
|
||||
const loader_key = helpers.generateGuid();
|
||||
const loader_key = generateGuid();
|
||||
dispatch(uiActions.startLoading(loader_key, `discogs_${endpoint}`));
|
||||
|
||||
const config = {
|
||||
@ -56,7 +57,7 @@ export function getArtistImages(uri, artist) {
|
||||
.then(
|
||||
(response) => {
|
||||
if (response) {
|
||||
if (response.results.length > 0 && response.results[0].cover_image !== undefined) {
|
||||
if (response.results.length > 0 && response.results[0].cover_image !== undefined) {
|
||||
const updated_artist = {
|
||||
uri,
|
||||
images: [response.results[0].cover_image],
|
||||
@ -84,7 +85,7 @@ export function getArtistImages(uri, artist) {
|
||||
helpers.cache.set(`discogs_${artist.name}`, cover_image);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const cached = helpers.cache.get(`discogs_${artist.name}`);
|
||||
if (cached) {
|
||||
finalise(cached);
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
|
||||
import { generateGuid } from '../../util/helpers';
|
||||
|
||||
const coreActions = require('../core/actions');
|
||||
const uiActions = require('../ui/actions');
|
||||
const helpers = require('../../helpers');
|
||||
|
||||
export function set(data) {
|
||||
return {
|
||||
@ -52,7 +53,7 @@ const sendRequest = (dispatch, getState, endpoint, method = 'GET', data = false)
|
||||
}
|
||||
|
||||
// add reference to loader queue
|
||||
const loader_key = helpers.generateGuid();
|
||||
const loader_key = generateGuid();
|
||||
dispatch(uiActions.startLoading(loader_key, `genius_${endpoint}`));
|
||||
|
||||
function status(response) {
|
||||
@ -159,7 +160,7 @@ export function getTrackLyrics(uri, path) {
|
||||
};
|
||||
|
||||
// add reference to loader queue
|
||||
const loader_key = helpers.generateGuid();
|
||||
const loader_key = generateGuid();
|
||||
dispatch(uiActions.startLoading(loader_key, 'genius_get_lyrics'));
|
||||
|
||||
function status(response) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
const helpers = require('./../../helpers');
|
||||
import { formatUser } from '../../util/format';
|
||||
const coreActions = require('../core/actions');
|
||||
const geniusActions = require('./actions');
|
||||
|
||||
@ -7,9 +7,9 @@ const GeniusMiddleware = (function () {
|
||||
return (store) => (next) => (action) => {
|
||||
const state = store.getState();
|
||||
|
||||
switch (action.type) {
|
||||
switch (action.type) {
|
||||
case 'GENIUS_ME_LOADED':
|
||||
var me = helpers.formatUser(action.me);
|
||||
var me = formatUser(action.me);
|
||||
Object.assign(
|
||||
me,
|
||||
{
|
||||
@ -26,7 +26,7 @@ const GeniusMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'GENIUS_USER_LOADED':
|
||||
var user = helpers.formatUser(action.user);
|
||||
var user = formatUser(action.user);
|
||||
Object.assign(
|
||||
user,
|
||||
{
|
||||
@ -55,4 +55,4 @@ const GeniusMiddleware = (function () {
|
||||
};
|
||||
}());
|
||||
|
||||
export default GeniusMiddleware;
|
||||
export default GeniusMiddleware;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
|
||||
import ReactGA from 'react-ga';
|
||||
import { arrayOf } from '../../util/arrays';
|
||||
|
||||
const helpers = require('../../helpers');
|
||||
const coreActions = require('../core/actions');
|
||||
const mopidyActions = require('../mopidy/actions');
|
||||
const uiActions = require('../ui/actions');
|
||||
@ -38,7 +38,7 @@ const GoogleMiddleware = (function () {
|
||||
return;
|
||||
}
|
||||
|
||||
const uris = helpers.arrayOf('uri', response);
|
||||
const uris = arrayOf('uri', response);
|
||||
store.dispatch({
|
||||
type: 'GOOGLE_LIBRARY_ALBUMS_LOADED',
|
||||
uris,
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
|
||||
import * as helpers from '../../helpers';
|
||||
import { removeDuplicates } from '../../util/arrays';
|
||||
|
||||
export default function reducer(google = {}, action) {
|
||||
switch (action.type) {
|
||||
switch (action.type) {
|
||||
case 'GOOGLE_SET':
|
||||
return { ...google, ...action.data };
|
||||
|
||||
@ -12,7 +12,7 @@ export default function reducer(google = {}, action) {
|
||||
} else {
|
||||
var { uris } = action;
|
||||
}
|
||||
return { ...google, library_artists: helpers.removeDuplicates(uris) };
|
||||
return { ...google, library_artists: removeDuplicates(uris) };
|
||||
|
||||
case 'GOOGLE_CLEAR_LIBRARY_ARTISTS':
|
||||
return { ...google, library_artists: null };
|
||||
@ -23,7 +23,7 @@ export default function reducer(google = {}, action) {
|
||||
} else {
|
||||
var { uris } = action;
|
||||
}
|
||||
return { ...google, library_albums: helpers.removeDuplicates(uris) };
|
||||
return { ...google, library_albums: removeDuplicates(uris) };
|
||||
|
||||
case 'GOOGLE_CLEAR_LIBRARY_ALBUMS':
|
||||
return { ...google, library_albums: null };
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
|
||||
import { formatImages } from '../../util/format';
|
||||
import { generateGuid } from '../../util/helpers';
|
||||
|
||||
const coreActions = require('../core/actions');
|
||||
const uiActions = require('../ui/actions');
|
||||
const helpers = require('../../helpers');
|
||||
|
||||
export function set(data) {
|
||||
return {
|
||||
@ -36,7 +38,7 @@ const sendRequest = (dispatch, getState, params, signed = false) => new Promise(
|
||||
timeout: 30000,
|
||||
};
|
||||
|
||||
const loader_key = helpers.generateGuid();
|
||||
const loader_key = generateGuid();
|
||||
dispatch(uiActions.startLoading(loader_key, `lastfm_${method}`));
|
||||
|
||||
function status(response) {
|
||||
@ -76,7 +78,7 @@ const sendSignedRequest = (dispatch, getState, params) => new Promise((resolve,
|
||||
});
|
||||
}
|
||||
|
||||
const loader_key = helpers.generateGuid();
|
||||
const loader_key = generateGuid();
|
||||
let method = params.substring(params.indexOf('method=') + 7, params.length);
|
||||
method = method.substring(0, method.indexOf('&'));
|
||||
|
||||
@ -311,7 +313,7 @@ export function getImages(context, uri) {
|
||||
.then(
|
||||
(response) => {
|
||||
if (response.album) {
|
||||
const images = helpers.formatImages(response.album.image);
|
||||
const images = formatImages(response.album.image);
|
||||
dispatch(coreActions.trackLoaded({ uri, images }));
|
||||
}
|
||||
},
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
|
||||
const helpers = require('./../../helpers');
|
||||
import { formatUser } from '../../util/format';
|
||||
const coreActions = require('../core/actions');
|
||||
const lastfmActions = require('./actions');
|
||||
|
||||
const LastfmMiddleware = (function () {
|
||||
const LastfmMiddleware = (function () {
|
||||
return (store) => (next) => (action) => {
|
||||
switch (action.type) {
|
||||
switch (action.type) {
|
||||
case 'LASTFM_ME_LOADED':
|
||||
var me = helpers.formatUser(action.me);
|
||||
var me = formatUser(action.me);
|
||||
Object.assign(
|
||||
me,
|
||||
{
|
||||
@ -34,4 +34,4 @@ const LastfmMiddleware = (function () {
|
||||
};
|
||||
}());
|
||||
|
||||
export default LastfmMiddleware;
|
||||
export default LastfmMiddleware;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
const helpers = require('../../helpers.js');
|
||||
import storage from '../../util/storage';
|
||||
|
||||
const localstorageMiddleware = (function () {
|
||||
/**
|
||||
@ -28,7 +28,7 @@ const localstorageMiddleware = (function () {
|
||||
|
||||
switch (action.type) {
|
||||
case 'PUSHER_CONNECTED':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'pusher',
|
||||
{
|
||||
connection_id: action.connection_id,
|
||||
@ -37,7 +37,7 @@ const localstorageMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'PUSHER_SET_PORT':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'pusher',
|
||||
{
|
||||
port: action.port,
|
||||
@ -46,7 +46,7 @@ const localstorageMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'PUSHER_SET_USERNAME':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'pusher',
|
||||
{
|
||||
username: action.username,
|
||||
@ -55,7 +55,7 @@ const localstorageMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'MOPIDY_URISCHEMES_FILTERED':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'mopidy',
|
||||
{
|
||||
uri_schemes: action.data,
|
||||
@ -69,7 +69,7 @@ const localstorageMiddleware = (function () {
|
||||
} else if (action.data) {
|
||||
var authorization = action.data;
|
||||
}
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'spotify',
|
||||
{
|
||||
authorization,
|
||||
@ -81,7 +81,7 @@ const localstorageMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_IMPORT_AUTHORIZATION':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'spotify',
|
||||
{
|
||||
authorization: action.authorization,
|
||||
@ -94,7 +94,7 @@ const localstorageMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_AUTHORIZATION_REVOKED':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'spotify',
|
||||
{
|
||||
authorization: null,
|
||||
@ -107,7 +107,7 @@ const localstorageMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_TOKEN_REFRESHED':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'spotify',
|
||||
{
|
||||
access_token: action.data.access_token,
|
||||
@ -118,7 +118,7 @@ const localstorageMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_ME_LOADED':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'spotify',
|
||||
{
|
||||
me: action.me,
|
||||
@ -127,7 +127,7 @@ const localstorageMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'LASTFM_ME_LOADED':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'lastfm',
|
||||
{
|
||||
me: action.me,
|
||||
@ -136,7 +136,7 @@ const localstorageMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'LASTFM_AUTHORIZATION_GRANTED':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'lastfm',
|
||||
{
|
||||
authorization: action.data.session,
|
||||
@ -145,7 +145,7 @@ const localstorageMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'LASTFM_AUTHORIZATION_REVOKED':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'lastfm',
|
||||
{
|
||||
authorization: null,
|
||||
@ -155,7 +155,7 @@ const localstorageMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'LASTFM_IMPORT_AUTHORIZATION':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'lastfm',
|
||||
{
|
||||
authorization: action.authorization,
|
||||
@ -165,7 +165,7 @@ const localstorageMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'GENIUS_ME_LOADED':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'genius',
|
||||
{
|
||||
me: action.me,
|
||||
@ -174,7 +174,7 @@ const localstorageMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'GENIUS_AUTHORIZATION_GRANTED':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'genius',
|
||||
{
|
||||
authorization: action.data,
|
||||
@ -185,7 +185,7 @@ const localstorageMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'GENIUS_AUTHORIZATION_REVOKED':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'genius',
|
||||
{
|
||||
me: null,
|
||||
@ -197,7 +197,7 @@ const localstorageMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'GENIUS_IMPORT_AUTHORIZATION':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'genius',
|
||||
{
|
||||
authorization: action.authorization,
|
||||
@ -209,42 +209,42 @@ const localstorageMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'CORE_SET':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'core',
|
||||
action.data,
|
||||
);
|
||||
break;
|
||||
|
||||
case 'UI_SET':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'ui',
|
||||
action.data,
|
||||
);
|
||||
break;
|
||||
|
||||
case 'MOPIDY_SET':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'mopidy',
|
||||
action.data,
|
||||
);
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_SET':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'spotify',
|
||||
action.data,
|
||||
);
|
||||
break;
|
||||
|
||||
case 'SNAPCAST_SET':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'snapcast',
|
||||
action.data,
|
||||
);
|
||||
break;
|
||||
|
||||
case 'SNAPCAST_COMMANDS_UPDATED':
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'snapcast',
|
||||
{
|
||||
commands: action.commands,
|
||||
@ -253,7 +253,7 @@ const localstorageMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'SUPPRESS_BROADCAST':
|
||||
var ui = helpers.getStorage('ui');
|
||||
var ui = storage.get('ui');
|
||||
if (ui.suppressed_broadcasts !== undefined) {
|
||||
var { suppressed_broadcasts } = ui;
|
||||
} else {
|
||||
@ -262,7 +262,7 @@ const localstorageMiddleware = (function () {
|
||||
|
||||
suppressed_broadcasts.push(action.key);
|
||||
|
||||
helpers.setStorage(
|
||||
storage.set(
|
||||
'ui',
|
||||
{
|
||||
suppressed_broadcasts,
|
||||
@ -276,23 +276,23 @@ const localstorageMiddleware = (function () {
|
||||
* to use the IndexedDB engine instead for storing this quantity of data
|
||||
|
||||
case 'UPDATE_TRACKS_INDEX':
|
||||
helpers.setStorage('core', {tracks: action.tracks});
|
||||
storage.set('core', {tracks: action.tracks});
|
||||
next(action);
|
||||
break;
|
||||
case 'UPDATE_ALBUMS_INDEX':
|
||||
helpers.setStorage('core', {albums: action.albums});
|
||||
storage.set('core', {albums: action.albums});
|
||||
next(action);
|
||||
break;
|
||||
case 'UPDATE_ARTISTS_INDEX':
|
||||
helpers.setStorage('core', {artists: action.artists});
|
||||
storage.set('core', {artists: action.artists});
|
||||
next(action);
|
||||
break;
|
||||
case 'UPDATE_PLAYLISTS_INDEX':
|
||||
helpers.setStorage('core', {playlists: action.playlists});
|
||||
storage.set('core', {playlists: action.playlists});
|
||||
next(action);
|
||||
break;
|
||||
case 'UPDATE_USERS_INDEX':
|
||||
helpers.setStorage('core', {users: action.users});
|
||||
storage.set('core', {users: action.users});
|
||||
next(action);
|
||||
break;
|
||||
*/
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
import * as helpers from '../../helpers';
|
||||
import { createRange } from '../../util/arrays';
|
||||
|
||||
export function set(data) {
|
||||
return {
|
||||
@ -337,7 +337,7 @@ export function removeTracks(tlids) {
|
||||
}
|
||||
|
||||
export function reorderTracklist(indexes, insert_before) {
|
||||
const range = helpers.createRange(indexes);
|
||||
const range = createRange(indexes);
|
||||
if (insert_before > range.start) insert_before -= range.length;
|
||||
return {
|
||||
type: 'MOPIDY_REORDER_TRACKLIST',
|
||||
|
||||
@ -3,7 +3,24 @@ import ReactGA from 'react-ga';
|
||||
import Mopidy from 'mopidy';
|
||||
import { sha256 } from 'js-sha256';
|
||||
|
||||
import * as helpers from '../../helpers';
|
||||
import {
|
||||
generateGuid,
|
||||
uriSource,
|
||||
setFavicon,
|
||||
} from '../../util/helpers';
|
||||
import {
|
||||
digestMopidyImages,
|
||||
formatImages,
|
||||
formatTrack,
|
||||
formatTracks,
|
||||
getTrackIcon,
|
||||
} from '../../util/format';
|
||||
import {
|
||||
arrayOf,
|
||||
shuffle,
|
||||
removeDuplicates,
|
||||
applyFilter,
|
||||
} from '../../util/arrays';
|
||||
|
||||
const mopidyActions = require('./actions.js');
|
||||
const coreActions = require('../core/actions.js');
|
||||
@ -184,7 +201,7 @@ const MopidyMiddleware = (function () {
|
||||
reject(error);
|
||||
}
|
||||
|
||||
const loader_key = helpers.generateGuid();
|
||||
const loader_key = generateGuid();
|
||||
store.dispatch(uiActions.startLoading(loader_key, `mopidy_${property}`));
|
||||
|
||||
// Start our 15 second timeout
|
||||
@ -256,7 +273,7 @@ const MopidyMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'MOPIDY_DISCONNECTED':
|
||||
helpers.setFavicon('favicon_error.png');
|
||||
setFavicon('favicon_error.png');
|
||||
break;
|
||||
|
||||
case 'MOPIDY_DEBUG':
|
||||
@ -325,9 +342,9 @@ const MopidyMiddleware = (function () {
|
||||
store.dispatch(uiActions.setWindowTitle(null, action.play_state));
|
||||
|
||||
if (action.play_state == 'playing') {
|
||||
helpers.setFavicon('favicon.png');
|
||||
setFavicon('favicon.png');
|
||||
} else {
|
||||
helpers.setFavicon('favicon_paused.png');
|
||||
setFavicon('favicon_paused.png');
|
||||
}
|
||||
next(action);
|
||||
break;
|
||||
@ -360,7 +377,7 @@ const MopidyMiddleware = (function () {
|
||||
{
|
||||
notification: {
|
||||
content: `${store.getState().pusher.username + (store.getState().mopidy.play_state == 'paused' ? ' resumed' : ' started')} playback`,
|
||||
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().core) : false),
|
||||
icon: (store.getState().core.current_track ? getTrackIcon(store.getState().core.current_track, store.getState().core) : false),
|
||||
},
|
||||
},
|
||||
));
|
||||
@ -378,7 +395,7 @@ const MopidyMiddleware = (function () {
|
||||
{
|
||||
notification: {
|
||||
content: `${store.getState().pusher.username} paused playback`,
|
||||
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().core) : false),
|
||||
icon: (store.getState().core.current_track ? getTrackIcon(store.getState().core.current_track, store.getState().core) : false),
|
||||
},
|
||||
},
|
||||
));
|
||||
@ -406,7 +423,7 @@ const MopidyMiddleware = (function () {
|
||||
{
|
||||
notification: {
|
||||
content: `${store.getState().pusher.username} skipped "${store.getState().core.current_track.name}"`,
|
||||
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().core) : false),
|
||||
icon: (store.getState().core.current_track ? getTrackIcon(store.getState().core.current_track, store.getState().core) : false),
|
||||
},
|
||||
},
|
||||
));
|
||||
@ -424,7 +441,7 @@ const MopidyMiddleware = (function () {
|
||||
{
|
||||
notification: {
|
||||
content: `${store.getState().pusher.username} stopped playback`,
|
||||
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().core) : false),
|
||||
icon: (store.getState().core.current_track ? getTrackIcon(store.getState().core.current_track, store.getState().core) : false),
|
||||
},
|
||||
},
|
||||
));
|
||||
@ -628,7 +645,7 @@ const MopidyMiddleware = (function () {
|
||||
}
|
||||
|
||||
// It's a Spotify playlist that we haven't loaded yet, so Spotify HTTP API needs to go get it
|
||||
} else if (helpers.uriSource(action.uri) == 'spotify' && store.getState().spotify.enabled) {
|
||||
} else if (uriSource(action.uri) == 'spotify' && store.getState().spotify.enabled) {
|
||||
store.dispatch(spotifyActions.getAllPlaylistTracks(action.uri, action.shuffle, 'play'));
|
||||
break;
|
||||
}
|
||||
@ -641,9 +658,9 @@ const MopidyMiddleware = (function () {
|
||||
if (!response || response.tracks === undefined || !response.tracks) {
|
||||
store.dispatch(uiActions.createNotification({ content: 'Failed to load playlist tracks', level: 'error' }));
|
||||
} else {
|
||||
let tracks_uris = helpers.arrayOf('uri', response.tracks);
|
||||
let tracks_uris = arrayOf('uri', response.tracks);
|
||||
if (action.shuffle) {
|
||||
tracks_uris = helpers.shuffle(tracks_uris);
|
||||
tracks_uris = shuffle(tracks_uris);
|
||||
}
|
||||
store.dispatch(mopidyActions.playURIs(tracks_uris, action.uri));
|
||||
}
|
||||
@ -667,7 +684,7 @@ const MopidyMiddleware = (function () {
|
||||
if (playlist.tracks_total == playlist.tracks_uris.length) {
|
||||
let tracks_uris = Object.assign([], playlist.tracks_uris);
|
||||
if (action.shuffle) {
|
||||
tracks_uris = helpers.shuffle(tracks_uris);
|
||||
tracks_uris = shuffle(tracks_uris);
|
||||
}
|
||||
store.dispatch(mopidyActions.enqueueURIs(tracks_uris, action.uri, action.play_next, action.at_position, action.offset));
|
||||
break;
|
||||
@ -680,7 +697,7 @@ const MopidyMiddleware = (function () {
|
||||
}
|
||||
|
||||
// It's a Spotify playlist that we haven't loaded yet, so Spotify HTTP API needs to go get it
|
||||
} else if (helpers.uriSource(action.uri) == 'spotify' && store.getState().spotify.enabled) {
|
||||
} else if (uriSource(action.uri) == 'spotify' && store.getState().spotify.enabled) {
|
||||
store.dispatch(spotifyActions.getAllPlaylistTracks(action.uri, action.shuffle, 'enqueue', action.play_next));
|
||||
break;
|
||||
}
|
||||
@ -693,9 +710,9 @@ const MopidyMiddleware = (function () {
|
||||
if (response.tracks === undefined) {
|
||||
store.dispatch(uiActions.createNotification({ content: 'Failed to load playlist tracks', level: 'error' }));
|
||||
} else {
|
||||
let tracks_uris = helpers.arrayOf('uri', response.tracks);
|
||||
let tracks_uris = arrayOf('uri', response.tracks);
|
||||
if (action.shuffle) {
|
||||
tracks_uris = helpers.shuffle(tracks_uris);
|
||||
tracks_uris = shuffle(tracks_uris);
|
||||
}
|
||||
store.dispatch(mopidyActions.enqueueURIs(tracks_uris, action.uri, action.play_next, action.at_position, action.offset));
|
||||
}
|
||||
@ -721,7 +738,7 @@ const MopidyMiddleware = (function () {
|
||||
{
|
||||
notification: {
|
||||
content: `${store.getState().pusher.username} is adding ${action.uris.length} URIs to queue`,
|
||||
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().core) : false),
|
||||
icon: (store.getState().core.current_track ? getTrackIcon(store.getState().core.current_track, store.getState().core) : false),
|
||||
},
|
||||
},
|
||||
));
|
||||
@ -860,7 +877,7 @@ const MopidyMiddleware = (function () {
|
||||
}
|
||||
|
||||
if (action.shuffle) {
|
||||
urisToPlay = helpers.shuffle(urisToPlay);
|
||||
urisToPlay = shuffle(urisToPlay);
|
||||
}
|
||||
|
||||
// Stop the radio
|
||||
@ -1079,8 +1096,8 @@ const MopidyMiddleware = (function () {
|
||||
}
|
||||
}
|
||||
|
||||
let albums_uris = helpers.arrayOf('uri', albums);
|
||||
albums_uris = helpers.removeDuplicates(albums_uris);
|
||||
let albums_uris = arrayOf('uri', albums);
|
||||
albums_uris = removeDuplicates(albums_uris);
|
||||
|
||||
store.dispatch(coreActions.albumsLoaded(albums));
|
||||
|
||||
@ -1160,7 +1177,7 @@ const MopidyMiddleware = (function () {
|
||||
}
|
||||
}
|
||||
|
||||
artists_uris = helpers.removeDuplicates(artists_uris);
|
||||
artists_uris = removeDuplicates(artists_uris);
|
||||
|
||||
// load each artist
|
||||
for (var i = 0; i < artists_uris.length; i++) {
|
||||
@ -1215,7 +1232,7 @@ const MopidyMiddleware = (function () {
|
||||
|
||||
for (var i = 0; i < response.length; i++) {
|
||||
const playlist = response[i];
|
||||
if (playlist.name.includes(action.data.query) && action.data.uri_schemes.includes(`${helpers.uriSource(playlist.uri)}:`)) {
|
||||
if (playlist.name.includes(action.data.query) && action.data.uri_schemes.includes(`${uriSource(playlist.uri)}:`)) {
|
||||
playlists_uris.push(playlist.uri);
|
||||
}
|
||||
}
|
||||
@ -1283,7 +1300,7 @@ const MopidyMiddleware = (function () {
|
||||
type: 'MOPIDY_SEARCH_RESULTS_LOADED',
|
||||
query: action.data.query,
|
||||
context: action.data.context,
|
||||
results: helpers.formatTracks(tracks),
|
||||
results: formatTracks(tracks),
|
||||
});
|
||||
}
|
||||
continue_process();
|
||||
@ -1328,7 +1345,7 @@ const MopidyMiddleware = (function () {
|
||||
type: 'MOPIDY_SEARCH_RESULTS_LOADED',
|
||||
query: action.data.query,
|
||||
context: 'tracks',
|
||||
results: helpers.formatTracks(tracks),
|
||||
results: formatTracks(tracks),
|
||||
});
|
||||
}
|
||||
|
||||
@ -1379,8 +1396,8 @@ const MopidyMiddleware = (function () {
|
||||
}
|
||||
}
|
||||
|
||||
let albums_uris = helpers.arrayOf('uri', albums);
|
||||
albums_uris = helpers.removeDuplicates(albums_uris);
|
||||
let albums_uris = arrayOf('uri', albums);
|
||||
albums_uris = removeDuplicates(albums_uris);
|
||||
|
||||
store.dispatch(coreActions.albumsLoaded(albums));
|
||||
|
||||
@ -1447,7 +1464,7 @@ const MopidyMiddleware = (function () {
|
||||
}
|
||||
}
|
||||
|
||||
artists_uris = helpers.removeDuplicates(artists_uris);
|
||||
artists_uris = removeDuplicates(artists_uris);
|
||||
|
||||
// load each artist
|
||||
for (var i = 0; i < artists_uris.length; i++) {
|
||||
@ -1497,7 +1514,7 @@ const MopidyMiddleware = (function () {
|
||||
let playlists_uris = [];
|
||||
for (var i = 0; i < response.length; i++) {
|
||||
const playlist = response[i];
|
||||
if (playlist.name.includes(action.data.query) && action.data.uri_schemes.includes(`${helpers.uriSource(playlist.uri)}:`)) {
|
||||
if (playlist.name.includes(action.data.query) && action.data.uri_schemes.includes(`${uriSource(playlist.uri)}:`)) {
|
||||
playlists_uris.push(playlist.uri);
|
||||
}
|
||||
}
|
||||
@ -1565,12 +1582,12 @@ const MopidyMiddleware = (function () {
|
||||
request(socket, store, 'playlists.asList')
|
||||
.then((response) => {
|
||||
// drop in our URI list
|
||||
const playlist_uris = helpers.arrayOf('uri', response);
|
||||
const playlist_uris = arrayOf('uri', response);
|
||||
const playlist_uris_filtered = [];
|
||||
|
||||
// Remove any Spotify playlists. These will be handled by our Spotify API
|
||||
for (var i = 0; i < playlist_uris.length; i++) {
|
||||
if (helpers.uriSource(playlist_uris[i]) != 'spotify') {
|
||||
if (uriSource(playlist_uris[i]) != 'spotify') {
|
||||
playlist_uris_filtered.push(playlist_uris[i]);
|
||||
}
|
||||
}
|
||||
@ -1582,7 +1599,7 @@ const MopidyMiddleware = (function () {
|
||||
for (var i = 0; i < playlist_uris_filtered.length; i++) {
|
||||
request(socket, store, 'playlists.lookup', { uri: playlist_uris_filtered[i] })
|
||||
.then((response) => {
|
||||
const source = helpers.uriSource(response.uri);
|
||||
const source = uriSource(response.uri);
|
||||
const playlist = {
|
||||
|
||||
type: 'playlist',
|
||||
@ -1629,7 +1646,7 @@ const MopidyMiddleware = (function () {
|
||||
|
||||
case 'MOPIDY_RESOLVE_PLAYLIST_TRACKS':
|
||||
var tracks = Object.assign([], action.tracks);
|
||||
var uris = helpers.arrayOf('uri', tracks);
|
||||
var uris = arrayOf('uri', tracks);
|
||||
|
||||
request(socket, store, 'library.lookup', { uris })
|
||||
.then((response) => {
|
||||
@ -1828,7 +1845,7 @@ const MopidyMiddleware = (function () {
|
||||
.then((response) => {
|
||||
if (response.length <= 0) return;
|
||||
|
||||
const uris = helpers.arrayOf('uri', response);
|
||||
const uris = arrayOf('uri', response);
|
||||
store.dispatch({
|
||||
type: 'MOPIDY_LIBRARY_ALBUMS_LOADED',
|
||||
uris,
|
||||
@ -1918,7 +1935,7 @@ const MopidyMiddleware = (function () {
|
||||
}
|
||||
}
|
||||
|
||||
store.dispatch(mopidyActions.getImages('albums', helpers.arrayOf('uri', albums_loaded)));
|
||||
store.dispatch(mopidyActions.getImages('albums', arrayOf('uri', albums_loaded)));
|
||||
store.dispatch(coreActions.albumsLoaded(albums_loaded));
|
||||
store.dispatch(coreActions.artistsLoaded(artists_loaded));
|
||||
store.dispatch(coreActions.tracksLoaded(tracks_loaded));
|
||||
@ -1954,8 +1971,8 @@ const MopidyMiddleware = (function () {
|
||||
const album = {
|
||||
...response[0].album,
|
||||
source: 'local',
|
||||
artists_uris: helpers.arrayOf('uri', artists),
|
||||
tracks_uris: helpers.arrayOf('uri', response),
|
||||
artists_uris: arrayOf('uri', artists),
|
||||
tracks_uris: arrayOf('uri', response),
|
||||
tracks_total: response.length,
|
||||
};
|
||||
|
||||
@ -2024,7 +2041,7 @@ const MopidyMiddleware = (function () {
|
||||
.then(response => {
|
||||
if (response.length <= 0) return;
|
||||
|
||||
var uris = helpers.arrayOf('uri',response);
|
||||
var uris = arrayOf('uri',response);
|
||||
|
||||
store.dispatch({
|
||||
type: 'MOPIDY_LIBRARY_ARTISTS_LOADED',
|
||||
@ -2111,7 +2128,7 @@ const MopidyMiddleware = (function () {
|
||||
}
|
||||
|
||||
// Add our tracks and albums
|
||||
artist.albums_uris = helpers.arrayOf('uri', albums),
|
||||
artist.albums_uris = arrayOf('uri', albums),
|
||||
artist.tracks = response;
|
||||
|
||||
store.dispatch(coreActions.artistLoaded(artist));
|
||||
@ -2220,7 +2237,7 @@ const MopidyMiddleware = (function () {
|
||||
// Let the UI know we're finished transition
|
||||
store.dispatch(uiActions.setCurrentTrackTransition(false));
|
||||
|
||||
var track = helpers.formatTrack(action.tl_track);
|
||||
var track = formatTrack(action.tl_track);
|
||||
if (track.uri) {
|
||||
// Deliver the data we've got already
|
||||
store.dispatch({
|
||||
@ -2232,7 +2249,7 @@ const MopidyMiddleware = (function () {
|
||||
// Now attempt to get supporting images
|
||||
if (store.getState().core.tracks[track.uri] === undefined || store.getState().core.tracks[track.uri].images === undefined) {
|
||||
// We've got Spotify running, and it's a spotify track - go straight to the source!
|
||||
if (store.getState().spotify.enabled && helpers.uriSource(track.uri) == 'spotify') {
|
||||
if (store.getState().spotify.enabled && uriSource(track.uri) == 'spotify') {
|
||||
store.dispatch(spotifyActions.getTrack(track.uri));
|
||||
|
||||
// Some other source, rely on Mopidy backends to do their work
|
||||
@ -2250,7 +2267,7 @@ const MopidyMiddleware = (function () {
|
||||
if (response && response >= 0) {
|
||||
// Get the full track object from our tracklist
|
||||
// We know it will be here, as the tlid refers to an item in this list
|
||||
const track = helpers.applyFilter('tlid', response, store.getState().core.queue, true);
|
||||
const track = applyFilter('tlid', response, store.getState().core.queue, true);
|
||||
|
||||
if (track && track.uri) {
|
||||
store.dispatch({
|
||||
@ -2261,7 +2278,7 @@ const MopidyMiddleware = (function () {
|
||||
// We don't have the track (including images) already in our index
|
||||
if (store.getState().core.tracks[track.uri] === undefined || store.getState().core.tracks[track.uri].images === undefined) {
|
||||
// We've got Spotify running, and it's a spotify track - go straight to the source!
|
||||
if (store.getState().spotify.enabled && helpers.uriSource(track.uri) == 'spotify') {
|
||||
if (store.getState().spotify.enabled && uriSource(track.uri) == 'spotify') {
|
||||
store.dispatch(spotifyActions.getTrack(track.uri));
|
||||
|
||||
// Some other source, rely on Mopidy backends to do their work
|
||||
@ -2310,7 +2327,7 @@ const MopidyMiddleware = (function () {
|
||||
for (const uri in response) {
|
||||
if (response.hasOwnProperty(uri)) {
|
||||
let images = response[uri];
|
||||
images = helpers.formatImages(helpers.digestMopidyImages(store.getState().mopidy, images));
|
||||
images = formatImages(digestMopidyImages(store.getState().mopidy, images));
|
||||
|
||||
if (images && images.length > 0) {
|
||||
records.push({
|
||||
@ -2359,13 +2376,13 @@ const MopidyMiddleware = (function () {
|
||||
}
|
||||
|
||||
if (subdirectories.length > 0) {
|
||||
request(socket, store, 'library.getImages', { uris: helpers.arrayOf('uri', subdirectories) })
|
||||
request(socket, store, 'library.getImages', { uris: arrayOf('uri', subdirectories) })
|
||||
.then((response) => {
|
||||
|
||||
const subdirectories_with_images = subdirectories.map((subdir) => {
|
||||
let images = response[subdir.uri] || undefined;
|
||||
if (images) {
|
||||
images = helpers.formatImages(helpers.digestMopidyImages(store.getState().mopidy, images));
|
||||
images = formatImages(digestMopidyImages(store.getState().mopidy, images));
|
||||
}
|
||||
return {
|
||||
...subdir,
|
||||
@ -2393,7 +2410,7 @@ const MopidyMiddleware = (function () {
|
||||
|
||||
for (const uri in response) {
|
||||
if (response.hasOwnProperty(uri) && response[uri].length > 0) {
|
||||
tracks.push(helpers.formatTrack(response[uri][0]));
|
||||
tracks.push(formatTrack(response[uri][0]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,33 +1,33 @@
|
||||
|
||||
import * as helpers from '../../helpers';
|
||||
import { removeDuplicates } from '../../util/arrays';
|
||||
|
||||
export default function reducer(mopidy = {}, action) {
|
||||
switch (action.type) {
|
||||
switch (action.type) {
|
||||
case 'MOPIDY_SET':
|
||||
return { ...mopidy, ...action.data };
|
||||
|
||||
case 'MOPIDY_CONNECT':
|
||||
case 'MOPIDY_CONNECTING':
|
||||
return {
|
||||
...mopidy,
|
||||
return {
|
||||
...mopidy,
|
||||
connected: false,
|
||||
connecting: true,
|
||||
connecting: true,
|
||||
};
|
||||
|
||||
case 'MOPIDY_CONNECTED':
|
||||
return {
|
||||
...mopidy,
|
||||
return {
|
||||
...mopidy,
|
||||
connected: true,
|
||||
connecting: false,
|
||||
restart_running: false,
|
||||
upgrade_running: false,
|
||||
upgrade_running: false,
|
||||
};
|
||||
|
||||
case 'MOPIDY_DISCONNECTED':
|
||||
return {
|
||||
...mopidy,
|
||||
return {
|
||||
...mopidy,
|
||||
connected: false,
|
||||
connecting: false,
|
||||
connecting: false,
|
||||
};
|
||||
|
||||
case 'MOPIDY_CHANGE_TRACK':
|
||||
@ -114,7 +114,7 @@ export default function reducer(mopidy = {}, action) {
|
||||
} else {
|
||||
var { uris } = action;
|
||||
}
|
||||
return { ...mopidy, library_playlists: helpers.removeDuplicates(uris) };
|
||||
return { ...mopidy, library_playlists: removeDuplicates(uris) };
|
||||
|
||||
case 'MOPIDY_LIBRARY_PLAYLISTS_LOADED_ALL':
|
||||
return { ...mopidy, library_playlists_loaded_all: true };
|
||||
@ -141,7 +141,7 @@ export default function reducer(mopidy = {}, action) {
|
||||
} else {
|
||||
var { uris } = action;
|
||||
}
|
||||
return { ...mopidy, library_artists: helpers.removeDuplicates(uris) };
|
||||
return { ...mopidy, library_artists: removeDuplicates(uris) };
|
||||
|
||||
case 'MOPIDY_CLEAR_LIBRARY_ARTISTS':
|
||||
return { ...mopidy, library_artists: null };
|
||||
@ -152,7 +152,7 @@ export default function reducer(mopidy = {}, action) {
|
||||
} else {
|
||||
var { uris } = action;
|
||||
}
|
||||
return { ...mopidy, library_albums: helpers.removeDuplicates(uris) };
|
||||
return { ...mopidy, library_albums: removeDuplicates(uris) };
|
||||
|
||||
case 'MOPIDY_CLEAR_LIBRARY_ALBUMS':
|
||||
return { ...mopidy, library_albums: null };
|
||||
|
||||
@ -1,15 +1,13 @@
|
||||
|
||||
import ReactGA from 'react-ga';
|
||||
import { uriType, generateGuid } from '../../util/helpers';
|
||||
|
||||
const helpers = require('../../helpers');
|
||||
const coreActions = require('../core/actions');
|
||||
const uiActions = require('../ui/actions');
|
||||
const mopidyActions = require('../mopidy/actions');
|
||||
const pusherActions = require('./actions');
|
||||
const lastfmActions = require('../lastfm/actions');
|
||||
const geniusActions = require('../genius/actions');
|
||||
const spotifyActions = require('../spotify/actions');
|
||||
const snapcastActions = require('../snapcast/actions');
|
||||
|
||||
const PusherMiddleware = (function () {
|
||||
|
||||
@ -204,7 +202,7 @@ const PusherMiddleware = (function () {
|
||||
};
|
||||
|
||||
const request = (store, method, params = null) => new Promise((resolve, reject) => {
|
||||
const id = helpers.generateGuid();
|
||||
const id = generateGuid();
|
||||
const message = {
|
||||
jsonrpc: '2.0',
|
||||
id,
|
||||
@ -611,7 +609,7 @@ const PusherMiddleware = (function () {
|
||||
};
|
||||
|
||||
for (let i = 0; i < action.uris.length; i++) {
|
||||
switch (helpers.uriType(action.uris[i])) {
|
||||
switch (uriType(action.uris[i])) {
|
||||
case 'artist':
|
||||
data.seed_artists.push(action.uris[i]);
|
||||
break;
|
||||
|
||||
@ -1,8 +1,17 @@
|
||||
|
||||
import ReactGA from 'react-ga';
|
||||
import { sha256 } from 'js-sha256';
|
||||
import {
|
||||
generateGuid,
|
||||
} from '../../util/helpers';
|
||||
import {
|
||||
arrayOf,
|
||||
} from '../../util/arrays';
|
||||
import {
|
||||
formatGroup,
|
||||
formatClient,
|
||||
} from '../../util/format';
|
||||
|
||||
const helpers = require('../../helpers');
|
||||
const coreActions = require('../core/actions');
|
||||
const uiActions = require('../ui/actions');
|
||||
const pusherActions = require('../pusher/actions');
|
||||
@ -95,7 +104,7 @@ const SnapcastMiddleware = (function () {
|
||||
};
|
||||
|
||||
const request = (store, method, params = null) => new Promise((resolve, reject) => {
|
||||
const id = helpers.generateGuid(8);
|
||||
const id = generateGuid(8);
|
||||
const message = {
|
||||
jsonrpc: '2.0',
|
||||
id,
|
||||
@ -285,14 +294,14 @@ const SnapcastMiddleware = (function () {
|
||||
var clients_loaded = [];
|
||||
|
||||
const groups_loaded = action.groups.map(raw_group => {
|
||||
let group = helpers.formatGroup(raw_group);
|
||||
let group = formatGroup(raw_group);
|
||||
|
||||
if (groups_index[group.id]) {
|
||||
group = { ...groups_index[group.id], ...group };
|
||||
}
|
||||
|
||||
if (raw_group.clients) {
|
||||
group.clients_ids = helpers.arrayOf('id', raw_group.clients);
|
||||
group.clients_ids = arrayOf('id', raw_group.clients);
|
||||
clients_loaded = [...clients_loaded, ...raw_group.clients];
|
||||
store.dispatch(snapcastActions.calculateGroupVolume(group.id, raw_group.clients));
|
||||
}
|
||||
@ -316,7 +325,7 @@ const SnapcastMiddleware = (function () {
|
||||
|
||||
case 'SNAPCAST_CALCULATE_GROUP_VOLUME':
|
||||
const totalVolume = action.clients.reduce((accumulator, client) => {
|
||||
return accumulator += helpers.formatClient(client).volume;
|
||||
return accumulator += formatClient(client).volume;
|
||||
}, 0);
|
||||
|
||||
store.dispatch(snapcastActions.groupLoaded({
|
||||
@ -330,7 +339,7 @@ const SnapcastMiddleware = (function () {
|
||||
var clients_loaded = [];
|
||||
|
||||
for (const raw_client of action.clients) {
|
||||
var client = helpers.formatClient(raw_client);
|
||||
var client = formatClient(raw_client);
|
||||
|
||||
if (clients_index[client.id]) {
|
||||
client = { ...clients_index[client.id], ...client };
|
||||
|
||||
@ -1,10 +1,25 @@
|
||||
import { exception } from 'react-ga';
|
||||
|
||||
import {
|
||||
arrayOf,
|
||||
shuffle,
|
||||
} from '../../util/arrays';
|
||||
import {
|
||||
generateGuid,
|
||||
getFromUri,
|
||||
uriType,
|
||||
upgradeSpotifyPlaylistUris,
|
||||
} from '../../util/helpers';
|
||||
import {
|
||||
formatTracks,
|
||||
formatPlaylist,
|
||||
formatUser,
|
||||
formatAlbum,
|
||||
} from '../../util/format';
|
||||
|
||||
const coreActions = require('../../services/core/actions');
|
||||
const uiActions = require('../../services/ui/actions');
|
||||
const mopidyActions = require('../../services/mopidy/actions');
|
||||
const lastfmActions = require('../../services/lastfm/actions');
|
||||
const helpers = require('../../helpers');
|
||||
|
||||
/**
|
||||
* Send an ajax request to the Spotify API
|
||||
@ -21,7 +36,7 @@ const request = (dispatch, getState, endpoint, method = 'GET', data = false, cac
|
||||
// Add reference to loader queue
|
||||
// We do this straight away so that even if we're refreshing the token, it still registers as
|
||||
// loading said endpoint
|
||||
const loader_key = helpers.generateGuid();
|
||||
const loader_key = generateGuid();
|
||||
dispatch(uiActions.startLoading(loader_key, `spotify_${endpoint}`));
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -137,7 +152,7 @@ function getToken(dispatch, getState) {
|
||||
function refreshToken(dispatch, getState) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// add reference to loader queue
|
||||
const loader_key = helpers.generateGuid();
|
||||
const loader_key = generateGuid();
|
||||
dispatch(uiActions.startLoading(loader_key, 'spotify_refresh_token'));
|
||||
|
||||
// Fully-authorized, so we can use the local Spotify credentials
|
||||
@ -304,7 +319,7 @@ export function getMe() {
|
||||
* */
|
||||
export function getTrack(uri) {
|
||||
return (dispatch, getState) => {
|
||||
request(dispatch, getState, `tracks/${helpers.getFromUri('trackid', uri)}`)
|
||||
request(dispatch, getState, `tracks/${getFromUri('trackid', uri)}`)
|
||||
.then(
|
||||
(response) => {
|
||||
dispatch(coreActions.trackLoaded(response));
|
||||
@ -382,7 +397,7 @@ export function getFeaturedPlaylists() {
|
||||
type: 'SPOTIFY_FEATURED_PLAYLISTS_LOADED',
|
||||
data: {
|
||||
message: response.message,
|
||||
playlists: helpers.upgradeSpotifyPlaylistUris(helpers.arrayOf('uri', response.playlists.items)),
|
||||
playlists: upgradeSpotifyPlaylistUris(arrayOf('uri', response.playlists.items)),
|
||||
},
|
||||
});
|
||||
},
|
||||
@ -563,7 +578,7 @@ export function getSearchResults(type, query, limit = 50, offset = 0) {
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
context: 'tracks',
|
||||
query,
|
||||
results: helpers.formatTracks(response.tracks.items),
|
||||
results: formatTracks(response.tracks.items),
|
||||
more: response.tracks.next,
|
||||
});
|
||||
}
|
||||
@ -577,7 +592,7 @@ export function getSearchResults(type, query, limit = 50, offset = 0) {
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
context: 'artists',
|
||||
query,
|
||||
results: helpers.arrayOf('uri', response.artists.items),
|
||||
results: arrayOf('uri', response.artists.items),
|
||||
more: response.artists.next,
|
||||
});
|
||||
}
|
||||
@ -591,7 +606,7 @@ export function getSearchResults(type, query, limit = 50, offset = 0) {
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
context: 'albums',
|
||||
query,
|
||||
results: helpers.arrayOf('uri', response.albums.items),
|
||||
results: arrayOf('uri', response.albums.items),
|
||||
more: response.albums.next,
|
||||
});
|
||||
}
|
||||
@ -601,7 +616,7 @@ export function getSearchResults(type, query, limit = 50, offset = 0) {
|
||||
for (const playlist of response.playlists.items) {
|
||||
playlists.push({
|
||||
|
||||
...helpers.formatPlaylist(playlist),
|
||||
...formatPlaylist(playlist),
|
||||
can_edit: (getState().spotify.me && playlist.owner.id == getState().spotify.me.id),
|
||||
tracks_total: playlist.tracks.total,
|
||||
});
|
||||
@ -615,7 +630,7 @@ export function getSearchResults(type, query, limit = 50, offset = 0) {
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
context: 'playlists',
|
||||
query,
|
||||
results: helpers.arrayOf('uri', playlists),
|
||||
results: arrayOf('uri', playlists),
|
||||
more: response.playlists.next,
|
||||
});
|
||||
}
|
||||
@ -712,7 +727,7 @@ export function clearAutocompleteResults(field_id = null) {
|
||||
|
||||
export function following(uri, method = 'GET') {
|
||||
return (dispatch, getState) => {
|
||||
const asset_name = helpers.uriType(uri);
|
||||
const asset_name = uriType(uri);
|
||||
let endpoint;
|
||||
let data;
|
||||
let is_following = null;
|
||||
@ -726,39 +741,39 @@ export function following(uri, method = 'GET') {
|
||||
switch (asset_name) {
|
||||
case 'track':
|
||||
if (method == 'GET') {
|
||||
endpoint = `me/tracks/contains?ids=${helpers.getFromUri('trackid', uri)}`;
|
||||
endpoint = `me/tracks/contains?ids=${getFromUri('trackid', uri)}`;
|
||||
} else {
|
||||
endpoint = `me/tracks?ids=${helpers.getFromUri('trackid', uri)}`;
|
||||
endpoint = `me/tracks?ids=${getFromUri('trackid', uri)}`;
|
||||
}
|
||||
break;
|
||||
case 'album':
|
||||
if (method == 'GET') {
|
||||
endpoint = `me/albums/contains?ids=${helpers.getFromUri('albumid', uri)}`;
|
||||
endpoint = `me/albums/contains?ids=${getFromUri('albumid', uri)}`;
|
||||
} else {
|
||||
endpoint = `me/albums?ids=${helpers.getFromUri('albumid', uri)}`;
|
||||
endpoint = `me/albums?ids=${getFromUri('albumid', uri)}`;
|
||||
}
|
||||
break;
|
||||
case 'artist':
|
||||
if (method == 'GET') {
|
||||
endpoint = `me/following/contains?type=artist&ids=${helpers.getFromUri('artistid', uri)}`;
|
||||
endpoint = `me/following/contains?type=artist&ids=${getFromUri('artistid', uri)}`;
|
||||
} else {
|
||||
endpoint = `me/following?type=artist&ids=${helpers.getFromUri('artistid', uri)}`;
|
||||
endpoint = `me/following?type=artist&ids=${getFromUri('artistid', uri)}`;
|
||||
data = {};
|
||||
}
|
||||
break;
|
||||
case 'user':
|
||||
if (method == 'GET') {
|
||||
endpoint = `me/following/contains?type=user&ids=${helpers.getFromUri('userid', uri)}`;
|
||||
endpoint = `me/following/contains?type=user&ids=${getFromUri('userid', uri)}`;
|
||||
} else {
|
||||
endpoint = `me/following?type=user&ids=${helpers.getFromUri('userid', uri)}`;
|
||||
endpoint = `me/following?type=user&ids=${getFromUri('userid', uri)}`;
|
||||
data = {};
|
||||
}
|
||||
break;
|
||||
case 'playlist':
|
||||
if (method == 'GET') {
|
||||
endpoint = `playlists/${helpers.getFromUri('playlistid', uri)}/followers/contains?ids=${getState().spotify.me.id}`;
|
||||
endpoint = `playlists/${getFromUri('playlistid', uri)}/followers/contains?ids=${getState().spotify.me.id}`;
|
||||
} else {
|
||||
endpoint = `playlists/${helpers.getFromUri('playlistid', uri)}/followers?`;
|
||||
endpoint = `playlists/${getFromUri('playlistid', uri)}/followers?`;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -801,7 +816,7 @@ export function resolveRadioSeeds(radio) {
|
||||
let artist_ids = '';
|
||||
for (var i = 0; i < radio.seed_artists.length; i++) {
|
||||
if (i > 0) artist_ids += ',';
|
||||
artist_ids += helpers.getFromUri('artistid', radio.seed_artists[i]);
|
||||
artist_ids += getFromUri('artistid', radio.seed_artists[i]);
|
||||
}
|
||||
|
||||
request(dispatch, getState, `artists?ids=${artist_ids}`)
|
||||
@ -829,7 +844,7 @@ export function resolveRadioSeeds(radio) {
|
||||
let track_ids = '';
|
||||
for (var i = 0; i < radio.seed_tracks.length; i++) {
|
||||
if (i > 0) track_ids += ',';
|
||||
track_ids += helpers.getFromUri('trackid', radio.seed_tracks[i]);
|
||||
track_ids += getFromUri('trackid', radio.seed_tracks[i]);
|
||||
}
|
||||
|
||||
request(dispatch, getState, `tracks?ids=${track_ids}`)
|
||||
@ -908,17 +923,17 @@ export function getRecommendations(uris = [], limit = 20, tunabilities = null) {
|
||||
for (let i = 0; i < uris.length; i++) {
|
||||
const uri = uris[i];
|
||||
|
||||
switch (helpers.uriType(uri)) {
|
||||
switch (uriType(uri)) {
|
||||
case 'artist':
|
||||
artists_ids.push(helpers.getFromUri('artistid', uri));
|
||||
artists_ids.push(getFromUri('artistid', uri));
|
||||
break;
|
||||
|
||||
case 'track':
|
||||
tracks_ids.push(helpers.getFromUri('trackid', uri));
|
||||
tracks_ids.push(getFromUri('trackid', uri));
|
||||
break;
|
||||
|
||||
case 'genre':
|
||||
genres.push(helpers.getFromUri('genreid', uri));
|
||||
genres.push(getFromUri('genreid', uri));
|
||||
break;
|
||||
|
||||
case 'default':
|
||||
@ -992,9 +1007,9 @@ export function getRecommendations(uris = [], limit = 20, tunabilities = null) {
|
||||
dispatch({
|
||||
type: 'SPOTIFY_RECOMMENDATIONS_LOADED',
|
||||
seeds_uris: uris,
|
||||
tracks_uris: helpers.arrayOf('uri', tracks),
|
||||
tracks_uris: arrayOf('uri', tracks),
|
||||
artists_uris,
|
||||
albums_uris: helpers.arrayOf('uri', albums),
|
||||
albums_uris: arrayOf('uri', albums),
|
||||
});
|
||||
},
|
||||
(error) => {
|
||||
@ -1053,7 +1068,7 @@ export function getArtist(uri, full = false) {
|
||||
|
||||
// We need our artist, obviously
|
||||
const requests = [
|
||||
request(dispatch, getState, `artists/${helpers.getFromUri('artistid', uri)}`, 'GET', false, true)
|
||||
request(dispatch, getState, `artists/${getFromUri('artistid', uri)}`, 'GET', false, true)
|
||||
.then(
|
||||
(response) => {
|
||||
Object.assign(artist, response);
|
||||
@ -1070,7 +1085,7 @@ export function getArtist(uri, full = false) {
|
||||
// Do we want a full artist, with all supporting material?
|
||||
if (full) {
|
||||
requests.push(
|
||||
request(dispatch, getState, `artists/${helpers.getFromUri('artistid', uri)}/top-tracks?country=${getState().spotify.country}`)
|
||||
request(dispatch, getState, `artists/${getFromUri('artistid', uri)}/top-tracks?country=${getState().spotify.country}`)
|
||||
.then(
|
||||
(response) => {
|
||||
Object.assign(artist, response);
|
||||
@ -1085,11 +1100,11 @@ export function getArtist(uri, full = false) {
|
||||
);
|
||||
|
||||
requests.push(
|
||||
request(dispatch, getState, `artists/${helpers.getFromUri('artistid', uri)}/related-artists`)
|
||||
request(dispatch, getState, `artists/${getFromUri('artistid', uri)}/related-artists`)
|
||||
.then(
|
||||
(response) => {
|
||||
dispatch(coreActions.artistsLoaded(response.artists));
|
||||
Object.assign(artist, { related_artists_uris: helpers.arrayOf('uri', response.artists) });
|
||||
Object.assign(artist, { related_artists_uris: arrayOf('uri', response.artists) });
|
||||
},
|
||||
(error) => {
|
||||
dispatch(coreActions.handleException(
|
||||
@ -1113,7 +1128,7 @@ export function getArtist(uri, full = false) {
|
||||
|
||||
// Now go get our artist albums
|
||||
if (full) {
|
||||
request(dispatch, getState, `artists/${helpers.getFromUri('artistid', uri)}/albums?market=${getState().spotify.country}`)
|
||||
request(dispatch, getState, `artists/${getFromUri('artistid', uri)}/albums?market=${getState().spotify.country}`)
|
||||
.then(
|
||||
(response) => {
|
||||
dispatch({
|
||||
@ -1140,7 +1155,7 @@ export function getArtists(uris) {
|
||||
let ids = '';
|
||||
for (let i = 0; i < uris.length; i++) {
|
||||
if (ids != '') ids += ',';
|
||||
ids += helpers.getFromUri('artistid', uris[i]);
|
||||
ids += getFromUri('artistid', uris[i]);
|
||||
}
|
||||
|
||||
request(dispatch, getState, `artists/?ids=${ids}`)
|
||||
@ -1154,7 +1169,7 @@ export function getArtists(uris) {
|
||||
album: artist.albums[i],
|
||||
});
|
||||
}
|
||||
artist.albums_uris = helpers.arrayOf('uri', artist.albums);
|
||||
artist.albums_uris = arrayOf('uri', artist.albums);
|
||||
artist.albums_more = artist.albums.next;
|
||||
dispatch(coreActions.artistLoaded(artist));
|
||||
}
|
||||
@ -1199,15 +1214,15 @@ export function playArtistTopTracks(uri) {
|
||||
|
||||
// Do we have this artist (and their tracks) in our index already?
|
||||
if (typeof (artists[uri]) !== 'undefined' && typeof (artists[uri].tracks) !== 'undefined') {
|
||||
const uris = helpers.arrayOf('uri', artists[uri].tracks);
|
||||
const uris = arrayOf('uri', artists[uri].tracks);
|
||||
dispatch(mopidyActions.playURIs(uris, uri));
|
||||
|
||||
// We need to load the artist's top tracks first
|
||||
} else {
|
||||
request(dispatch, getState, `artists/${helpers.getFromUri('artistid', uri)}/top-tracks?country=${getState().spotify.country}`)
|
||||
request(dispatch, getState, `artists/${getFromUri('artistid', uri)}/top-tracks?country=${getState().spotify.country}`)
|
||||
.then(
|
||||
(response) => {
|
||||
const uris = helpers.arrayOf('uri', response.tracks);
|
||||
const uris = arrayOf('uri', response.tracks);
|
||||
dispatch(mopidyActions.playURIs(uris, uri));
|
||||
},
|
||||
(error) => {
|
||||
@ -1229,10 +1244,10 @@ export function playArtistTopTracks(uri) {
|
||||
|
||||
export function getUser(uri) {
|
||||
return (dispatch, getState) => {
|
||||
request(dispatch, getState, `users/${helpers.getFromUri('userid', uri)}`)
|
||||
request(dispatch, getState, `users/${getFromUri('userid', uri)}`)
|
||||
.then(
|
||||
(response) => {
|
||||
dispatch(coreActions.userLoaded(helpers.formatUser(response)));
|
||||
dispatch(coreActions.userLoaded(formatUser(response)));
|
||||
},
|
||||
(error) => {
|
||||
dispatch(coreActions.handleException(
|
||||
@ -1247,7 +1262,7 @@ export function getUser(uri) {
|
||||
export function getUserPlaylists(uri) {
|
||||
return (dispatch, getState) => {
|
||||
// get the first page of playlists
|
||||
request(dispatch, getState, `users/${helpers.getFromUri('userid', uri)}/playlists?limit=40`)
|
||||
request(dispatch, getState, `users/${getFromUri('userid', uri)}/playlists?limit=40`)
|
||||
.then(
|
||||
(response) => {
|
||||
const playlists = [];
|
||||
@ -1259,7 +1274,7 @@ export function getUserPlaylists(uri) {
|
||||
|
||||
const playlist = {
|
||||
|
||||
...helpers.formatPlaylist(raw_playlist),
|
||||
...formatPlaylist(raw_playlist),
|
||||
can_edit,
|
||||
tracks_total: raw_playlist.tracks.total,
|
||||
};
|
||||
@ -1293,7 +1308,7 @@ export function getUserPlaylists(uri) {
|
||||
export function getAlbum(uri) {
|
||||
return (dispatch, getState) => {
|
||||
// get the album
|
||||
request(dispatch, getState, `albums/${helpers.getFromUri('albumid', uri)}`)
|
||||
request(dispatch, getState, `albums/${getFromUri('albumid', uri)}`)
|
||||
.then(
|
||||
(response) => {
|
||||
// dispatch our loaded artists (simple objects)
|
||||
@ -1302,9 +1317,9 @@ export function getAlbum(uri) {
|
||||
const tracks = Object.assign([], response.tracks.items);
|
||||
|
||||
const album = {
|
||||
...helpers.formatAlbum(response),
|
||||
artists_uris: helpers.arrayOf('uri', response.artists),
|
||||
tracks_uris: helpers.arrayOf('uri', tracks),
|
||||
...formatAlbum(response),
|
||||
artists_uris: arrayOf('uri', response.artists),
|
||||
tracks_uris: arrayOf('uri', tracks),
|
||||
tracks_more: response.tracks.next,
|
||||
tracks_total: response.tracks.total,
|
||||
};
|
||||
@ -1324,7 +1339,7 @@ export function getAlbum(uri) {
|
||||
// we do this to get the artist artwork
|
||||
const artist_ids = [];
|
||||
for (var i = 0; i < response.artists.length; i++) {
|
||||
artist_ids.push(helpers.getFromUri('artistid', response.artists[i].uri));
|
||||
artist_ids.push(getFromUri('artistid', response.artists[i].uri));
|
||||
}
|
||||
|
||||
// get all album artists as full objects
|
||||
@ -1410,7 +1425,7 @@ export function savePlaylist(uri, name, description, is_public, is_collaborative
|
||||
|
||||
// Update the playlist fields
|
||||
request(
|
||||
dispatch, getState, `users/${getState().spotify.me.id}/playlists/${helpers.getFromUri('playlistid', uri)}`, 'PUT', data,
|
||||
dispatch, getState, `users/${getState().spotify.me.id}/playlists/${getFromUri('playlistid', uri)}`, 'PUT', data,
|
||||
)
|
||||
.then(
|
||||
(response) => {
|
||||
@ -1418,7 +1433,7 @@ export function savePlaylist(uri, name, description, is_public, is_collaborative
|
||||
|
||||
// Save the image
|
||||
if (image) {
|
||||
request(dispatch, getState, `users/${getState().spotify.me.id}/playlists/${helpers.getFromUri('playlistid', uri)}/images`, 'PUT', image)
|
||||
request(dispatch, getState, `users/${getState().spotify.me.id}/playlists/${getFromUri('playlistid', uri)}/images`, 'PUT', image)
|
||||
.then(
|
||||
|
||||
(response) => {
|
||||
@ -1468,7 +1483,7 @@ export function savePlaylist(uri, name, description, is_public, is_collaborative
|
||||
export function getPlaylist(uri) {
|
||||
return (dispatch, getState) => {
|
||||
// get the main playlist object
|
||||
request(dispatch, getState, `playlists/${helpers.getFromUri('playlistid', uri)}?market=${getState().spotify.country}`)
|
||||
request(dispatch, getState, `playlists/${getFromUri('playlistid', uri)}?market=${getState().spotify.country}`)
|
||||
.then(
|
||||
(response) => {
|
||||
// convert links in description
|
||||
@ -1480,20 +1495,20 @@ export function getPlaylist(uri) {
|
||||
description = description.split('<a href="spotify:user:').join('<a href="#' + '/user/spotify:user:');
|
||||
}
|
||||
|
||||
const tracks = helpers.formatTracks(response.tracks.items);
|
||||
const tracks = formatTracks(response.tracks.items);
|
||||
|
||||
const playlist = {
|
||||
|
||||
...helpers.formatPlaylist(response),
|
||||
...formatPlaylist(response),
|
||||
is_completely_loaded: true,
|
||||
user_uri: response.owner.uri,
|
||||
tracks_uris: tracks ? helpers.arrayOf('uri', tracks) : null,
|
||||
tracks_uris: tracks ? arrayOf('uri', tracks) : null,
|
||||
tracks_more: response.tracks.next,
|
||||
tracks_total: response.tracks.total,
|
||||
description,
|
||||
};
|
||||
|
||||
dispatch(coreActions.userLoaded(helpers.formatUser(response.owner)));
|
||||
dispatch(coreActions.userLoaded(formatUser(response.owner)));
|
||||
dispatch(coreActions.tracksLoaded(tracks));
|
||||
dispatch(coreActions.playlistLoaded(playlist));
|
||||
},
|
||||
@ -1599,7 +1614,7 @@ export function getAllPlaylistTracks(uri, shuffle = false, callback_action = nul
|
||||
'Loading playlist tracks',
|
||||
{
|
||||
uri,
|
||||
next: `playlists/${helpers.getFromUri('playlistid', uri)}/tracks?market=${getState().spotify.country}`,
|
||||
next: `playlists/${getFromUri('playlistid', uri)}/tracks?market=${getState().spotify.country}`,
|
||||
shuffle,
|
||||
play_next,
|
||||
at_position,
|
||||
@ -1663,7 +1678,7 @@ export function getAllPlaylistTracksProcessor(data) {
|
||||
));
|
||||
} else {
|
||||
if (data.shuffle) {
|
||||
uris = helpers.shuffle(uris);
|
||||
uris = shuffle(uris);
|
||||
}
|
||||
|
||||
// We don't bother "finishing", we just want it "finished" immediately
|
||||
@ -1690,7 +1705,7 @@ export function getAllPlaylistTracksProcessor(data) {
|
||||
|
||||
export function addTracksToPlaylist(uri, tracks_uris) {
|
||||
return (dispatch, getState) => {
|
||||
request(dispatch, getState, `playlists/${helpers.getFromUri('playlistid', uri)}/tracks`, 'POST', { uris: tracks_uris })
|
||||
request(dispatch, getState, `playlists/${getFromUri('playlistid', uri)}/tracks`, 'POST', { uris: tracks_uris })
|
||||
.then(
|
||||
(response) => {
|
||||
dispatch({
|
||||
@ -1712,7 +1727,7 @@ export function addTracksToPlaylist(uri, tracks_uris) {
|
||||
|
||||
export function deleteTracksFromPlaylist(uri, snapshot_id, tracks_indexes) {
|
||||
return (dispatch, getState) => {
|
||||
request(dispatch, getState, `playlists/${helpers.getFromUri('playlistid', uri)}/tracks`, 'DELETE', { snapshot_id, positions: tracks_indexes })
|
||||
request(dispatch, getState, `playlists/${getFromUri('playlistid', uri)}/tracks`, 'DELETE', { snapshot_id, positions: tracks_indexes })
|
||||
.then(
|
||||
(response) => {
|
||||
dispatch({
|
||||
@ -1734,7 +1749,7 @@ export function deleteTracksFromPlaylist(uri, snapshot_id, tracks_indexes) {
|
||||
|
||||
export function reorderPlaylistTracks(uri, range_start, range_length, insert_before, snapshot_id) {
|
||||
return (dispatch, getState) => {
|
||||
request(dispatch, getState, `playlists/${helpers.getFromUri('playlistid', uri)}/tracks`, 'PUT', {
|
||||
request(dispatch, getState, `playlists/${getFromUri('playlistid', uri)}/tracks`, 'PUT', {
|
||||
uri, range_start, range_length, insert_before, snapshot_id,
|
||||
})
|
||||
.then(
|
||||
|
||||
@ -2,17 +2,22 @@
|
||||
import ReactGA from 'react-ga';
|
||||
import { sha256 } from 'js-sha256';
|
||||
|
||||
const helpers = require('./../../helpers');
|
||||
import { arrayOf } from '../../util/arrays';
|
||||
import { upgradeSpotifyPlaylistUris } from '../../util/helpers';
|
||||
import {
|
||||
formatTracks,
|
||||
formatImages,
|
||||
formatUser,
|
||||
} from '../../util/format';
|
||||
const coreActions = require('../core/actions');
|
||||
const spotifyActions = require('./actions');
|
||||
const uiActions = require('../ui/actions');
|
||||
const pusherActions = require('../pusher/actions');
|
||||
|
||||
const SpotifyMiddleware = (function () {
|
||||
return (store) => (next) => (action) => {
|
||||
const { spotify } = store.getState();
|
||||
|
||||
switch (action.type) {
|
||||
switch (action.type) {
|
||||
case 'SPOTIFY_AUTHORIZATION_GRANTED':
|
||||
if (store.getState().ui.allow_reporting) {
|
||||
ReactGA.event({ category: 'Spotify', action: 'Authorization granted' });
|
||||
@ -94,7 +99,7 @@ const SpotifyMiddleware = (function () {
|
||||
});
|
||||
|
||||
// Collate result into the three key values we want
|
||||
action.uris = helpers.arrayOf('uri', action.data.albums.items);
|
||||
action.uris = arrayOf('uri', action.data.albums.items);
|
||||
action.more = action.data.albums.next;
|
||||
action.total = action.data.albums.total;
|
||||
|
||||
@ -107,7 +112,7 @@ const SpotifyMiddleware = (function () {
|
||||
store.dispatch({
|
||||
type: 'ARTIST_ALBUMS_LOADED',
|
||||
artist_uri: action.artist_uri,
|
||||
albums_uris: helpers.arrayOf('uri', action.data.items),
|
||||
albums_uris: arrayOf('uri', action.data.items),
|
||||
more: action.data.next,
|
||||
total: action.data.total,
|
||||
});
|
||||
@ -136,7 +141,7 @@ const SpotifyMiddleware = (function () {
|
||||
store.dispatch({
|
||||
type: 'USER_PLAYLISTS_LOADED',
|
||||
key: action.key,
|
||||
uris: helpers.arrayOf('uri', playlists),
|
||||
uris: arrayOf('uri', playlists),
|
||||
more: action.data.next,
|
||||
total: action.data.total,
|
||||
});
|
||||
@ -169,7 +174,7 @@ const SpotifyMiddleware = (function () {
|
||||
store.dispatch({
|
||||
type: 'CATEGORY_PLAYLISTS_LOADED',
|
||||
key: action.key,
|
||||
uris: helpers.arrayOf('uri',playlists),
|
||||
uris: arrayOf('uri',playlists),
|
||||
more: action.data.playlists.next,
|
||||
total: action.data.playlists.total
|
||||
});
|
||||
@ -179,13 +184,13 @@ const SpotifyMiddleware = (function () {
|
||||
case 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED':
|
||||
store.dispatch(coreActions.playlistsLoaded(action.playlists.items));
|
||||
|
||||
action.uris = helpers.arrayOf('uri', action.playlists.items);
|
||||
action.uris = arrayOf('uri', action.playlists.items);
|
||||
action.more = action.playlists.next;
|
||||
action.total = action.playlists.total;
|
||||
delete action.playlists;
|
||||
|
||||
// Upgrade our URIs
|
||||
action.uris = helpers.upgradeSpotifyPlaylistUris(action.uris);
|
||||
action.uris = upgradeSpotifyPlaylistUris(action.uris);
|
||||
|
||||
next(action);
|
||||
break;
|
||||
@ -221,7 +226,7 @@ const SpotifyMiddleware = (function () {
|
||||
}
|
||||
|
||||
if (category.icons) {
|
||||
category.icons = helpers.formatImages(category.icons);
|
||||
category.icons = formatImages(category.icons);
|
||||
}
|
||||
|
||||
categories_loaded.push(category);
|
||||
@ -261,7 +266,7 @@ const SpotifyMiddleware = (function () {
|
||||
});
|
||||
|
||||
// Append our action with the uris. This gets handed down to subsequent middleware and our reducer.
|
||||
action.uris = helpers.arrayOf('uri', playlists);
|
||||
action.uris = arrayOf('uri', playlists);
|
||||
next(action);
|
||||
break;
|
||||
|
||||
@ -288,7 +293,7 @@ const SpotifyMiddleware = (function () {
|
||||
});
|
||||
|
||||
// Append our action with the uris. This gets handed down to subsequent middleware and our reducer.
|
||||
action.uris = helpers.arrayOf('uri', artists);
|
||||
action.uris = arrayOf('uri', artists);
|
||||
next(action);
|
||||
break;
|
||||
|
||||
@ -327,7 +332,7 @@ const SpotifyMiddleware = (function () {
|
||||
});
|
||||
|
||||
// Append our action with the uris. This gets handed down to subsequent middleware and our reducer.
|
||||
action.uris = helpers.arrayOf('uri', albums);
|
||||
action.uris = arrayOf('uri', albums);
|
||||
next(action);
|
||||
break;
|
||||
|
||||
@ -337,14 +342,14 @@ const SpotifyMiddleware = (function () {
|
||||
type: 'ARTISTS_LOADED',
|
||||
artists: action.artists,
|
||||
});
|
||||
action.artists_uris = helpers.arrayOf('uri', action.artists);
|
||||
action.artists_uris = arrayOf('uri', action.artists);
|
||||
}
|
||||
if (action.tracks.length > 0) {
|
||||
store.dispatch({
|
||||
type: 'TRACKS_LOADED',
|
||||
tracks: action.tracks,
|
||||
});
|
||||
action.tracks_uris = helpers.arrayOf('uri', action.tracks);
|
||||
action.tracks_uris = arrayOf('uri', action.tracks);
|
||||
}
|
||||
next(action);
|
||||
break;
|
||||
@ -385,7 +390,7 @@ const SpotifyMiddleware = (function () {
|
||||
store.dispatch({
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
context: 'tracks',
|
||||
results: helpers.formatTracks(action.data.tracks.items),
|
||||
results: formatTracks(action.data.tracks.items),
|
||||
more: action.data.tracks.next,
|
||||
});
|
||||
break;
|
||||
@ -400,7 +405,7 @@ const SpotifyMiddleware = (function () {
|
||||
store.dispatch({
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
context: 'artists',
|
||||
results: helpers.arrayOf('uri', action.data.playlists.items),
|
||||
results: arrayOf('uri', action.data.playlists.items),
|
||||
more: action.data.playlists.next,
|
||||
});
|
||||
break;
|
||||
@ -415,7 +420,7 @@ const SpotifyMiddleware = (function () {
|
||||
store.dispatch({
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
context: 'playlists',
|
||||
results: helpers.arrayOf('uri', action.data.albums.items),
|
||||
results: arrayOf('uri', action.data.albums.items),
|
||||
more: action.data.albums.next,
|
||||
});
|
||||
break;
|
||||
@ -439,14 +444,14 @@ const SpotifyMiddleware = (function () {
|
||||
store.dispatch({
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
context: 'playlists',
|
||||
results: helpers.arrayOf('uri', action.data.playlists.items),
|
||||
results: arrayOf('uri', action.data.playlists.items),
|
||||
more: action.data.playlists.next,
|
||||
});
|
||||
break;
|
||||
|
||||
|
||||
case 'SPOTIFY_ME_LOADED':
|
||||
var me = { ...helpers.formatUser(action.me) };
|
||||
var me = { ...formatUser(action.me) };
|
||||
|
||||
// We are Anonymous currently so use 'me' name as my Pusher username
|
||||
if (store.getState().pusher.username == 'Anonymous') {
|
||||
@ -468,7 +473,7 @@ const SpotifyMiddleware = (function () {
|
||||
default:
|
||||
return next(action);
|
||||
}
|
||||
};
|
||||
};
|
||||
}());
|
||||
|
||||
export default SpotifyMiddleware;
|
||||
export default SpotifyMiddleware;
|
||||
|
||||
@ -1,70 +1,71 @@
|
||||
|
||||
import * as helpers from '../../helpers';
|
||||
import { removeDuplicates, arrayOf } from '../../util/arrays';
|
||||
import { formatTracks } from '../../util/format';
|
||||
|
||||
export default function reducer(spotify = {}, action) {
|
||||
switch (action.type) {
|
||||
switch (action.type) {
|
||||
case 'SPOTIFY_SET':
|
||||
return { ...spotify, ...action.data };
|
||||
|
||||
case 'PUSHER_SPOTIFY_TOKEN':
|
||||
if (spotify.authorization) return spotify;
|
||||
return {
|
||||
...spotify,
|
||||
return {
|
||||
...spotify,
|
||||
authorizing: false,
|
||||
authorization: false,
|
||||
access_token: action.data.access_token,
|
||||
token_expiry: action.data.token_expiry,
|
||||
token_expiry: action.data.token_expiry,
|
||||
};
|
||||
|
||||
case 'SPOTIFY_AUTHORIZATION_GRANTED':
|
||||
return {
|
||||
...spotify,
|
||||
return {
|
||||
...spotify,
|
||||
enabled: true,
|
||||
authorizing: false,
|
||||
authorization: action.data,
|
||||
access_token: action.data.access_token,
|
||||
refresh_token: action.data.refresh_token,
|
||||
token_expiry: action.data.token_expiry,
|
||||
token_expiry: action.data.token_expiry,
|
||||
};
|
||||
|
||||
case 'SPOTIFY_AUTHORIZATION_REVOKED':
|
||||
return {
|
||||
...spotify,
|
||||
return {
|
||||
...spotify,
|
||||
authorizing: false,
|
||||
authorization: false,
|
||||
access_token: false,
|
||||
refresh_token: false,
|
||||
token_expiry: 0,
|
||||
me: false,
|
||||
me: false,
|
||||
};
|
||||
|
||||
case 'SPOTIFY_IMPORT_AUTHORIZATION':
|
||||
return {
|
||||
...spotify,
|
||||
return {
|
||||
...spotify,
|
||||
authorizing: false,
|
||||
authorization: action.authorization,
|
||||
access_token: action.authorization.access_token,
|
||||
refresh_token: action.authorization.refresh_token,
|
||||
token_expiry: action.authorization.token_expiry,
|
||||
me: action.me,
|
||||
me: action.me,
|
||||
};
|
||||
|
||||
case 'SPOTIFY_TOKEN_REFRESHING':
|
||||
return { ...spotify, refreshing_token: true };
|
||||
|
||||
case 'SPOTIFY_TOKEN_REFRESHED':
|
||||
return {
|
||||
...spotify,
|
||||
return {
|
||||
...spotify,
|
||||
refreshing_token: false,
|
||||
access_token: action.data.access_token,
|
||||
token_expiry: action.data.token_expiry,
|
||||
token_expiry: action.data.token_expiry,
|
||||
};
|
||||
|
||||
case 'SPOTIFY_TOKEN_CHANGED':
|
||||
return {
|
||||
...spotify,
|
||||
return {
|
||||
...spotify,
|
||||
access_token: action.spotify_token.access_token,
|
||||
token_expiry: action.spotify_token.token_expiry,
|
||||
token_expiry: action.spotify_token.token_expiry,
|
||||
};
|
||||
|
||||
case 'SPOTIFY_ME_LOADED':
|
||||
@ -79,11 +80,11 @@ export default function reducer(spotify = {}, action) {
|
||||
if (spotify.new_releases) {
|
||||
new_releases = Object.assign([], spotify.new_releases);
|
||||
}
|
||||
return {
|
||||
...spotify,
|
||||
new_releases: helpers.removeDuplicates([...new_releases, ...action.uris]),
|
||||
return {
|
||||
...spotify,
|
||||
new_releases: removeDuplicates([...new_releases, ...action.uris]),
|
||||
new_releases_more: action.more,
|
||||
new_releases_total: action.total,
|
||||
new_releases_total: action.total,
|
||||
};
|
||||
|
||||
case 'SPOTIFY_DISCOVER_LOADED':
|
||||
@ -111,7 +112,7 @@ export default function reducer(spotify = {}, action) {
|
||||
artists_uris: action.artists_uris,
|
||||
albums_uris: action.albums_uris,
|
||||
tracks_uris: action.tracks_uris,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
case 'SPOTIFY_FAVORITES_LOADED':
|
||||
@ -119,7 +120,7 @@ export default function reducer(spotify = {}, action) {
|
||||
|
||||
...spotify,
|
||||
favorite_artists: action.artists_uris,
|
||||
favorite_tracks: action.tracks_uris,
|
||||
favorite_tracks: action.tracks_uris,
|
||||
};
|
||||
|
||||
case 'SPOTIFY_AUTOCOMPLETE_LOADING':
|
||||
@ -128,7 +129,7 @@ export default function reducer(spotify = {}, action) {
|
||||
return {
|
||||
|
||||
...spotify,
|
||||
autocomplete_results,
|
||||
autocomplete_results,
|
||||
};
|
||||
|
||||
case 'SPOTIFY_AUTOCOMPLETE_LOADED':
|
||||
@ -138,7 +139,7 @@ export default function reducer(spotify = {}, action) {
|
||||
return {
|
||||
|
||||
...spotify,
|
||||
autocomplete_results,
|
||||
autocomplete_results,
|
||||
};
|
||||
|
||||
case 'SPOTIFY_AUTOCOMPLETE_CLEAR':
|
||||
@ -149,14 +150,14 @@ export default function reducer(spotify = {}, action) {
|
||||
return {
|
||||
|
||||
...spotify,
|
||||
autocomplete_results,
|
||||
autocomplete_results,
|
||||
};
|
||||
|
||||
case 'SPOTIFY_GENRES_LOADED':
|
||||
return {
|
||||
|
||||
...spotify,
|
||||
genres: action.genres,
|
||||
genres: action.genres,
|
||||
};
|
||||
|
||||
|
||||
@ -218,7 +219,7 @@ export default function reducer(spotify = {}, action) {
|
||||
} else {
|
||||
var { uris } = action;
|
||||
}
|
||||
return { ...spotify, library_playlists: helpers.removeDuplicates(uris) };
|
||||
return { ...spotify, library_playlists: removeDuplicates(uris) };
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ARTISTS_LOADED':
|
||||
if (spotify.library_artists) {
|
||||
@ -226,7 +227,7 @@ export default function reducer(spotify = {}, action) {
|
||||
} else {
|
||||
var { uris } = action;
|
||||
}
|
||||
return { ...spotify, library_artists: helpers.removeDuplicates(uris) };
|
||||
return { ...spotify, library_artists: removeDuplicates(uris) };
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ALBUMS_LOADED':
|
||||
if (spotify.library_albums) {
|
||||
@ -234,7 +235,7 @@ export default function reducer(spotify = {}, action) {
|
||||
} else {
|
||||
var { uris } = action;
|
||||
}
|
||||
return { ...spotify, library_albums: helpers.removeDuplicates(uris) };
|
||||
return { ...spotify, library_albums: removeDuplicates(uris) };
|
||||
|
||||
case 'SPOTIFY_LIBRARY_TRACKS_LOADED':
|
||||
case 'SPOTIFY_LIBRARY_TRACKS_LOADED_MORE':
|
||||
@ -242,17 +243,17 @@ export default function reducer(spotify = {}, action) {
|
||||
var uris = [];
|
||||
|
||||
if (tracks) {
|
||||
tracks = helpers.formatTracks(tracks);
|
||||
uris = helpers.arrayOf('uri', tracks);
|
||||
tracks = formatTracks(tracks);
|
||||
uris = arrayOf('uri', tracks);
|
||||
if (spotify.library_tracks) {
|
||||
uris = [...spotify.library_tracks, ...uris];
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...spotify,
|
||||
library_tracks: helpers.removeDuplicates(uris),
|
||||
library_tracks_more: action.data.next,
|
||||
return {
|
||||
...spotify,
|
||||
library_tracks: removeDuplicates(uris),
|
||||
library_tracks_more: action.data.next,
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
import * as helpers from '../../helpers';
|
||||
import { generateGuid } from '../../util/helpers';
|
||||
|
||||
export function setWindowTitle(title = null, play_state = null) {
|
||||
return {
|
||||
@ -179,7 +179,7 @@ export function createNotification(data) {
|
||||
return {
|
||||
type: 'CREATE_NOTIFICATION',
|
||||
notification: {
|
||||
key: helpers.generateGuid(),
|
||||
key: generateGuid(),
|
||||
duration: 5,
|
||||
type: 'default',
|
||||
title: null,
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
|
||||
import ReactGA from 'react-ga';
|
||||
import * as helpers from '../../helpers';
|
||||
|
||||
const uiActions = require('./actions.js');
|
||||
const mopidyActions = require('../mopidy/actions.js');
|
||||
|
||||
const UIMiddleware = (function () {
|
||||
/**
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
|
||||
import * as helpers from '../../helpers';
|
||||
|
||||
export default function reducer(ui = {}, action) {
|
||||
switch (action.type) {
|
||||
case 'LAZY_LOADING':
|
||||
|
||||
Reference in New Issue
Block a user