Removing remaining artistLoaded, albumLoaded, etc in favor of itemLoaded for consistent pipeline; Looking at search
This commit is contained in:
@ -315,7 +315,7 @@ const CoreMiddleware = (function () {
|
||||
* */
|
||||
case 'LOAD_ITEMS':
|
||||
action.uris.forEach((uri) => {
|
||||
store.dispatch(uiActions.startLoading(uri, `load_item_${uri}`));
|
||||
store.dispatch(uiActions.startLoading(uri));
|
||||
store.dispatch({
|
||||
type: `LOAD_${uriType(uri).toUpperCase()}`,
|
||||
uri,
|
||||
@ -350,7 +350,8 @@ const CoreMiddleware = (function () {
|
||||
store.getState().core.items[action.uri]
|
||||
&& store.getState().core.items[action.uri].images
|
||||
) {
|
||||
console.info(`Using "${action.uri}" from index`);
|
||||
console.info(`${action.uri}" already in index`);
|
||||
store.dispatch(uiActions.stopLoading(action.uri));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -397,7 +398,8 @@ const CoreMiddleware = (function () {
|
||||
store.getState().core.items[action.uri]
|
||||
&& (!action.options.full || store.getState().core.items[action.uri].tracks)
|
||||
) {
|
||||
console.info(`Using "${action.uri}" from index`);
|
||||
console.info(`${action.uri}" already in index`);
|
||||
store.dispatch(uiActions.stopLoading(action.uri));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -419,6 +421,7 @@ const CoreMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'LOAD_ARTIST':
|
||||
console.log(action);
|
||||
const fetchArtist = () => {
|
||||
switch (uriSource(action.uri)) {
|
||||
case 'spotify':
|
||||
@ -451,7 +454,9 @@ const CoreMiddleware = (function () {
|
||||
)
|
||||
)
|
||||
) {
|
||||
console.info(`Using "${action.uri}" from index`);
|
||||
console.info(`${action.uri}" already in index`);
|
||||
store.dispatch(coreActions.loadItems(store.getState().core.items[action.uri].albums_uris));
|
||||
store.dispatch(uiActions.stopLoading(action.uri));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -507,7 +512,8 @@ const CoreMiddleware = (function () {
|
||||
|| store.getState().core.items[action.uri].tracks
|
||||
)
|
||||
) {
|
||||
console.info(`Using "${action.uri}" from index`);
|
||||
console.info(`${action.uri}" already in index`);
|
||||
store.dispatch(uiActions.stopLoading(action.uri));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -575,7 +581,7 @@ const CoreMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'LOAD_LIBRARY':
|
||||
store.dispatch(uiActions.startLoading(action.uri, `load_library_${action.uri}`));
|
||||
store.dispatch(uiActions.startLoading(action.uri));
|
||||
const fetchLibrary = () => {
|
||||
switch (uriSource(action.uri)) {
|
||||
case 'spotify':
|
||||
@ -602,7 +608,8 @@ const CoreMiddleware = (function () {
|
||||
break;
|
||||
}
|
||||
if (store.getState().core.libraries[action.uri]) {
|
||||
console.info(`Using "${action.uri}" from index`);
|
||||
console.info(`${action.uri}" already in index`);
|
||||
store.dispatch(uiActions.stopLoading(action.uri));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -612,10 +619,12 @@ const CoreMiddleware = (function () {
|
||||
|
||||
const promises = library.items_uris.map((libraryItem) => localForage.getItem(libraryItem));
|
||||
Promise.all(promises).then(
|
||||
(libraryItems) => store.dispatch(coreActions.restoreItemsFromColdStore(compact(libraryItems))),
|
||||
(libraryItems) => {
|
||||
store.dispatch(coreActions.restoreItemsFromColdStore(compact(libraryItems)));
|
||||
store.dispatch(coreActions.restoreLibraryFromColdStore(library));
|
||||
},
|
||||
);
|
||||
|
||||
store.dispatch(coreActions.restoreLibraryFromColdStore(library));
|
||||
} else {
|
||||
fetchLibrary();
|
||||
}
|
||||
@ -720,10 +729,10 @@ const CoreMiddleware = (function () {
|
||||
action.albums = albums_loaded;
|
||||
|
||||
if (artists_loaded.length > 0) {
|
||||
store.dispatch(coreActions.artistsLoaded(artists_loaded));
|
||||
store.dispatch(coreActions.items(artists_loaded));
|
||||
}
|
||||
if (tracks_loaded.length > 0) {
|
||||
store.dispatch(coreActions.tracksLoaded(tracks_loaded));
|
||||
store.dispatch(coreActions.items(tracks_loaded));
|
||||
}
|
||||
|
||||
store.dispatch(coreActions.updateColdStore(albums_loaded));
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
|
||||
import { generateGuid } from '../../util/helpers';
|
||||
import { formatArtist } from '../../util/format';
|
||||
|
||||
const coreActions = require('../core/actions');
|
||||
const uiActions = require('../ui/actions');
|
||||
@ -58,11 +59,10 @@ export function getArtistImages(uri, artist) {
|
||||
(response) => {
|
||||
if (response) {
|
||||
if (response.results.length > 0 && response.results[0].cover_image !== undefined) {
|
||||
const updated_artist = {
|
||||
dispatch(coreActions.itemLoaded(formatArtist({
|
||||
uri,
|
||||
images: [response.results[0].cover_image],
|
||||
};
|
||||
dispatch(coreActions.artistLoaded(updated_artist));
|
||||
})));
|
||||
} else {
|
||||
console.log(`Discogs: No results for artist ${artist.name}`);
|
||||
}
|
||||
|
||||
@ -332,7 +332,9 @@ export function getImages(context, uri) {
|
||||
.then(
|
||||
(response) => {
|
||||
if (response.album) {
|
||||
dispatch(coreActions.albumLoaded({ uri, images: response.album.image }));
|
||||
dispatch(
|
||||
coreActions.itemLoaded(formatAlbum({ uri, images: response.album.image })),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@ -12,6 +12,7 @@ import {
|
||||
import {
|
||||
digestMopidyImages,
|
||||
formatImages,
|
||||
formatAlbums,
|
||||
formatTrack,
|
||||
formatTracks,
|
||||
formatSimpleObject,
|
||||
@ -1094,7 +1095,7 @@ const MopidyMiddleware = (function () {
|
||||
let albums_uris = arrayOf('uri', albums);
|
||||
albums_uris = removeDuplicates(albums_uris);
|
||||
|
||||
store.dispatch(coreActions.albumsLoaded(albums));
|
||||
store.dispatch(coreActions.itemsLoaded(albums));
|
||||
|
||||
// and plug in their URIs
|
||||
store.dispatch({
|
||||
@ -1169,11 +1170,7 @@ const MopidyMiddleware = (function () {
|
||||
}
|
||||
|
||||
artists_uris = removeDuplicates(artists_uris);
|
||||
|
||||
// load each artist
|
||||
for (var i = 0; i < artists_uris.length; i++) {
|
||||
store.dispatch(mopidyActions.getArtist(artists_uris[i]));
|
||||
}
|
||||
store.dispatch(coreActions.loadItems(artists_uris));
|
||||
|
||||
// and plug in their URIs
|
||||
store.dispatch({
|
||||
@ -1380,7 +1377,7 @@ const MopidyMiddleware = (function () {
|
||||
let albums_uris = arrayOf('uri', albums);
|
||||
albums_uris = removeDuplicates(albums_uris);
|
||||
|
||||
store.dispatch(coreActions.albumsLoaded(albums));
|
||||
store.dispatch(coreActions.itemsLoaded(formatAlbums(albums)));
|
||||
|
||||
// and plug in their URIs
|
||||
store.dispatch({
|
||||
@ -1446,11 +1443,7 @@ const MopidyMiddleware = (function () {
|
||||
}
|
||||
|
||||
artists_uris = removeDuplicates(artists_uris);
|
||||
|
||||
// load each artist
|
||||
for (var i = 0; i < artists_uris.length; i++) {
|
||||
store.dispatch(mopidyActions.getArtist(artists_uris[i]));
|
||||
}
|
||||
store.dispatch(coreActions.loadItems(artists_uris));
|
||||
|
||||
// and plug in their URIs
|
||||
store.dispatch({
|
||||
@ -1676,7 +1669,7 @@ const MopidyMiddleware = (function () {
|
||||
store.dispatch(coreActions.addPinned(playlist));
|
||||
}
|
||||
|
||||
store.dispatch(coreActions.playlistLoaded(playlist));
|
||||
store.dispatch(coreActions.itemLoaded(playlist));
|
||||
store.dispatch(uiActions.createNotification({ content: 'Playlist saved' }));
|
||||
});
|
||||
});
|
||||
@ -1726,7 +1719,7 @@ const MopidyMiddleware = (function () {
|
||||
request(store, 'playlists.create', { name: action.name, uri_scheme: action.scheme })
|
||||
.then((response) => {
|
||||
store.dispatch(uiActions.createNotification({ content: 'Created playlist' }));
|
||||
store.dispatch(coreActions.playlistLoaded(response));
|
||||
store.dispatch(coreActions.itemLoaded(response));
|
||||
store.dispatch({
|
||||
type: 'MOPIDY_LIBRARY_PLAYLIST_CREATED',
|
||||
key: response.uri,
|
||||
@ -1807,6 +1800,7 @@ const MopidyMiddleware = (function () {
|
||||
break;
|
||||
|
||||
case 'MOPIDY_GET_ARTIST':
|
||||
console.log(action);
|
||||
request(store, 'library.lookup', { uris: [action.uri] })
|
||||
.then((_response) => {
|
||||
if (!_response) return;
|
||||
@ -1876,7 +1870,7 @@ const MopidyMiddleware = (function () {
|
||||
provider: 'mopidy',
|
||||
}));
|
||||
|
||||
store.dispatch(coreActions.artistsLoaded(artists));
|
||||
store.dispatch(coreActions.itemsLoaded(artists));
|
||||
|
||||
// Re-run any consequential processes in 100ms. This allows a small window for other
|
||||
// server requests before our next batch. It's a little crude but it means the server isn't
|
||||
@ -2084,6 +2078,7 @@ const MopidyMiddleware = (function () {
|
||||
request(store, 'library.browse', { uri: action.uri })
|
||||
.then((response) => {
|
||||
const tracks_uris = [];
|
||||
const tracks = [];
|
||||
const subdirectories = [];
|
||||
|
||||
for (const item of response) {
|
||||
@ -2125,8 +2120,6 @@ const MopidyMiddleware = (function () {
|
||||
return;
|
||||
}
|
||||
|
||||
const tracks = [];
|
||||
|
||||
for (const uri in response) {
|
||||
if (response.hasOwnProperty(uri) && response[uri].length > 0) {
|
||||
tracks.push(formatTrack(response[uri][0]));
|
||||
|
||||
@ -678,19 +678,19 @@ export function getAutocompleteResults(field_id, query, types = ['album', 'artis
|
||||
}
|
||||
|
||||
if (response.artists && response.artists.items) {
|
||||
dispatch(coreActions.artistsLoaded(response.artists.items));
|
||||
dispatch(coreActions.itemsLoaded(response.artists.items));
|
||||
}
|
||||
|
||||
if (response.albums && response.albums.items) {
|
||||
dispatch(coreActions.albumsLoaded(response.albums.items));
|
||||
dispatch(coreActions.itemsLoaded(response.albums.items));
|
||||
}
|
||||
|
||||
if (response.playlists && response.playlists.items) {
|
||||
dispatch(coreActions.playlistsLoaded(response.playlists.items));
|
||||
dispatch(coreActions.itemsLoaded(response.playlists.items));
|
||||
}
|
||||
|
||||
if (response.tracks && response.tracks.items) {
|
||||
dispatch(coreActions.tracksLoaded(response.tracks.items));
|
||||
dispatch(coreActions.itemsLoaded(response.tracks.items));
|
||||
}
|
||||
|
||||
dispatch({
|
||||
|
||||
@ -121,6 +121,7 @@ const SpotifyMiddleware = (function () {
|
||||
next(action);
|
||||
break;
|
||||
|
||||
// TODO: This can go
|
||||
case 'SPOTIFY_ARTIST_ALBUMS_LOADED':
|
||||
store.dispatch(coreActions.albumsLoaded(action.data.items));
|
||||
store.dispatch({
|
||||
|
||||
@ -124,7 +124,7 @@ export default function reducer(ui = {}, action) {
|
||||
|
||||
case 'START_LOADING':
|
||||
var load_queue = { ...(ui.load_queue ? ui.load_queue : {}) };
|
||||
load_queue[action.key] = action.source;
|
||||
load_queue[action.key] = action.source || action.key;
|
||||
return { ...ui, load_queue };
|
||||
|
||||
case 'STOP_LOADING':
|
||||
|
||||
Reference in New Issue
Block a user