Async support (webpack); Selector for SearchResults
This commit is contained in:
@ -467,8 +467,12 @@ const CoreMiddleware = (function () {
|
||||
|
||||
if (artist.albums_uris) {
|
||||
const promises = artist.albums_uris.map((albumUri) => localForage.getItem(albumUri));
|
||||
console.time('restoring')
|
||||
Promise.all(promises).then(
|
||||
(albums) => store.dispatch(coreActions.restoreItemsFromColdStore(compact(albums))),
|
||||
(albums) => {
|
||||
store.dispatch(coreActions.restoreItemsFromColdStore(compact(albums)));
|
||||
console.timeEnd('restoring')
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@ -742,18 +746,14 @@ const CoreMiddleware = (function () {
|
||||
|
||||
case 'ITEMS_LOADED':
|
||||
const mergedItems = [];
|
||||
|
||||
console.time('TIMER')
|
||||
// THE FOLLOWING LINES ARE THE CULPRIT
|
||||
action.items.forEach((item) => {
|
||||
mergedItems.push({
|
||||
...core.items[item.uri] || {},
|
||||
...item,
|
||||
});
|
||||
store.dispatch(uiActions.stopLoading(item.uri));
|
||||
});
|
||||
// ABOVE
|
||||
|
||||
|
||||
store.dispatch(uiActions.stopLoading(arrayOf('uri', action.items)));
|
||||
store.dispatch(coreActions.updateColdStore(mergedItems));
|
||||
next({
|
||||
...action,
|
||||
@ -767,16 +767,6 @@ const CoreMiddleware = (function () {
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'RESTORE_ITEMS_FROM_COLD_STORE':
|
||||
action.items.forEach((item) => store.dispatch(uiActions.stopLoading(item.uri)));
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'RESTORE_LIBRARY_FROM_COLD_STORE':
|
||||
store.dispatch(uiActions.stopLoading(action.library.uri));
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'ARTISTS_LOADED':
|
||||
var artists_index = { ...core.artists };
|
||||
var artists_loaded = [];
|
||||
@ -984,6 +974,16 @@ const CoreMiddleware = (function () {
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'RESTORE_ITEMS_FROM_COLD_STORE':
|
||||
store.dispatch(uiActions.stopLoading(action.items));
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'RESTORE_LIBRARY_FROM_COLD_STORE':
|
||||
store.dispatch(uiActions.stopLoading(action.library.uri));
|
||||
next(action);
|
||||
break;
|
||||
|
||||
// TODO: Relocate this
|
||||
case 'UPDATE_COLD_STORE':
|
||||
if (action.items) {
|
||||
|
||||
@ -213,14 +213,14 @@ export function getTrack(uri) {
|
||||
};
|
||||
}
|
||||
|
||||
export function getArtist(uri, artist, mbid = false) {
|
||||
export function getArtist(uri, name, mbid = false) {
|
||||
return (dispatch, getState) => {
|
||||
if (mbid) {
|
||||
var params = `method=artist.getInfo&mbid=${mbid}`;
|
||||
} else {
|
||||
artist = artist.replace('&', 'and');
|
||||
artist = encodeURIComponent(artist);
|
||||
var params = `method=artist.getInfo&artist=${artist}`;
|
||||
name = name.replace('&', 'and');
|
||||
name = encodeURIComponent(name);
|
||||
var params = `method=artist.getInfo&artist=${name}`;
|
||||
}
|
||||
sendRequest(dispatch, getState, params)
|
||||
.then(
|
||||
|
||||
@ -12,6 +12,7 @@ import {
|
||||
import {
|
||||
digestMopidyImages,
|
||||
formatImages,
|
||||
formatAlbum,
|
||||
formatAlbums,
|
||||
formatTrack,
|
||||
formatTracks,
|
||||
@ -1797,7 +1798,6 @@ const MopidyMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'MOPIDY_GET_ARTIST':
|
||||
console.log(action);
|
||||
request(store, 'library.lookup', { uris: [action.uri] })
|
||||
.then((_response) => {
|
||||
if (!_response) return;
|
||||
@ -1826,23 +1826,17 @@ const MopidyMiddleware = (function () {
|
||||
store.dispatch(coreActions.itemsLoaded(albums));
|
||||
}
|
||||
|
||||
let artist = {
|
||||
uri: action.uri,
|
||||
provider: 'mopidy',
|
||||
};
|
||||
|
||||
// Get the artist object from the track. This is a bit ugly because it's a simplified
|
||||
// (Mopidy) artist object but gives us enough to fetch their name and artwork.
|
||||
for (const raw_artist of response[0].artists) {
|
||||
// We're only interested in the artist we asked for
|
||||
if (raw_artist.uri === artist.uri) {
|
||||
artist = { ...formatArtist(raw_artist) };
|
||||
}
|
||||
}
|
||||
const raw_artist = response[0].artists.find((item) => item.uri === action.uri);
|
||||
|
||||
// Add our tracks and albums
|
||||
artist.albums_uris = arrayOf('uri', albums);
|
||||
artist.tracks = formatTracks(response);
|
||||
const artist = {
|
||||
uri: action.uri,
|
||||
provider: 'mopidy',
|
||||
albums_uris: arrayOf('uri', albums),
|
||||
tracks: formatTracks(response),
|
||||
...(raw_artist ? formatArtist(raw_artist) : {}),
|
||||
};
|
||||
|
||||
store.dispatch(coreActions.itemLoaded(artist));
|
||||
store.dispatch(lastfmActions.getArtist(artist.uri, artist.name, artist.musicbrainz_id));
|
||||
@ -2218,10 +2212,10 @@ const MopidyMiddleware = (function () {
|
||||
request(store, 'library.lookup', { uris })
|
||||
.then((response) => {
|
||||
const libraryAlbums = indexToArray(response).map((tracks) => ({
|
||||
artists: tracks[0].artists || null,
|
||||
tracks,
|
||||
artists: tracks[0].artists ? formatArtists(tracks[0].artists) : null,
|
||||
tracks: formatTracks(tracks),
|
||||
last_modified: tracks[0].last_modified,
|
||||
...tracks[0].album,
|
||||
...formatAlbum(tracks[0].album),
|
||||
}));
|
||||
|
||||
store.dispatch(coreActions.itemsLoaded(libraryAlbums));
|
||||
|
||||
@ -618,7 +618,7 @@ export function getSearchResults(type, term, limit = 50, offset = 0) {
|
||||
}
|
||||
|
||||
if (response.albums !== undefined) {
|
||||
//dispatch(coreActions.itemsLoaded(formatAlbums(response.albums.items)));
|
||||
dispatch(coreActions.itemsLoaded(formatAlbums(response.albums.items)));
|
||||
dispatch({
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
context: 'albums',
|
||||
@ -634,7 +634,7 @@ export function getSearchResults(type, term, limit = 50, offset = 0) {
|
||||
can_edit: (getState().spotify.me && item.owner.id === getState().spotify.me.id),
|
||||
tracks_total: item.tracks.total,
|
||||
}));
|
||||
//dispatch(coreActions.itemsLoaded(playlists));
|
||||
dispatch(coreActions.itemsLoaded(playlists));
|
||||
|
||||
dispatch({
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
|
||||
@ -268,10 +268,10 @@ export function startLoading(key, source) {
|
||||
};
|
||||
}
|
||||
|
||||
export function stopLoading(key) {
|
||||
export function stopLoading(keys) {
|
||||
return {
|
||||
type: 'STOP_LOADING',
|
||||
key,
|
||||
keys: Array.isArray(keys) ? keys : [keys],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { omit } from 'lodash';
|
||||
|
||||
export default function reducer(ui = {}, action) {
|
||||
switch (action.type) {
|
||||
@ -128,11 +129,10 @@ export default function reducer(ui = {}, action) {
|
||||
return { ...ui, load_queue };
|
||||
|
||||
case 'STOP_LOADING':
|
||||
var load_queue = { ...(ui.load_queue ? ui.load_queue : {}) };
|
||||
if (load_queue[action.key]) {
|
||||
delete load_queue[action.key];
|
||||
}
|
||||
return { ...ui, load_queue };
|
||||
return {
|
||||
...ui,
|
||||
load_queue: omit(load_queue, action.keys),
|
||||
};
|
||||
|
||||
case 'START_PROCESS':
|
||||
case 'UPDATE_PROCESS':
|
||||
|
||||
Reference in New Issue
Block a user