Adding generic loadItem (refactor elsewhere); Adding foundation for Add Random

This commit is contained in:
James Barnsley
2020-08-03 07:08:16 +12:00
parent 8824d7a5d6
commit e398949a06
14 changed files with 690 additions and 460 deletions

View File

@ -115,6 +115,14 @@ export function cachebustHttpStream() {
* relevant service to load the record - all from one neat package.
* */
export function loadItem(uri, force_reload = false) {
return {
type: 'LOAD_ITEM',
uri,
force_reload,
};
}
export function loadTrack(uri, force_reload = false) {
return {
type: 'LOAD_TRACK',
@ -249,6 +257,14 @@ export function removeFromIndex(index_name, key, new_key = null) {
};
}
export function viewDataLoaded(name, data) {
return {
type: 'VIEW_DATA_LOADED',
name,
data,
};
}
/**
* Playlist manipulation

View File

@ -3,7 +3,7 @@ import React from 'react';
import ReactGA from 'react-ga';
import { arrayOf } from '../../util/arrays';
import URILink from '../../components/URILink';
import { uriSource, upgradeSpotifyPlaylistUris } from '../../util/helpers';
import { uriSource, upgradeSpotifyPlaylistUris, uriType, titleCase } from '../../util/helpers';
import {
formatTracks,
formatTrack,
@ -315,12 +315,18 @@ const CoreMiddleware = (function () {
break;
/**
* Asset Load commands
*
* These are called from views and other middleware to load
* assets. This is where we can return already indexed records
* where appropriate
* */
* Asset Load commands
*
* These are called from views and other middleware to load
* assets. This is where we can return already indexed records
* where appropriate
* */
case 'LOAD_ITEM':
store.dispatch(coreActions[`load${titleCase(uriType(action.uri))}`](
action.uri,
action.force_reload,
));
break;
case 'LOAD_TRACK':
if (

View File

@ -198,6 +198,16 @@ export default function reducer(core = {}, action) {
case 'SPOTIFY_GENRES_LOADED':
return { ...core, genres: action.genres };
case 'VIEW_DATA_LOADED':
console.log(action);
return {
...core,
view: {
...(core.view ? core.view : {}),
[action.name]: action.data,
},
};
/**
* Search results

View File

@ -530,6 +530,13 @@ export function cancelProcessor(processor) {
};
}
export function addToQueue_getRandomTracks(limit = 100) {
return {
type: 'ADD_TO_QUEUE__GET_RANDOM_TRACKS',
limit,
};
}
/**
* Searching

View File

@ -2330,6 +2330,18 @@ const MopidyMiddleware = (function () {
);
break;
case 'ADD_TO_QUEUE__GET_RANDOM_TRACKS':
request(socket, store, 'library.browse', { uri: 'local:directory?type=track' })
.then(
(_response) => {
if (!_response || !_response.length) return;
store.dispatch(
coreActions.viewDataLoaded('random_tracks', _response.slice(0, action.limit)),
);
},
);
break;
/**
* =============================================================== IMAGES ===============