Buildout, clean up; Still to hose out deprecated actions and reducers

This commit is contained in:
James Barnsley
2020-09-30 21:03:38 +13:00
parent 867ac50159
commit 461ce84a04
15 changed files with 146 additions and 153 deletions

View File

@ -118,7 +118,7 @@ export class App extends React.Component {
if (changed.length > 0) {
changed.forEach((k) => params.delete(k))
const url = window.location.toString().replace(window.location.search, params.toString())
console.log('settings changed:', changed, 'redirect to:', url)
console.log(`Settings changed, redirecting to ${url}`, changed);
window.location.assign(url)
}

View File

@ -20,7 +20,6 @@ const SearchResults = ({
all,
results: rawResults,
}) => {
console.log('rendering', type, query);
const encodedTerm = encodeURIComponent(query.term);
let results = rawResults;

View File

@ -625,8 +625,6 @@ const CoreMiddleware = (function () {
// library listing.
localForage.removeItem(action.uri);
}
console.log(action);
console.log(library);
store.dispatch(coreActions.itemLoaded({ ...action.item, in_library: true }));
next(action);
break;
@ -784,31 +782,16 @@ const CoreMiddleware = (function () {
var tracks_loaded = [];
for (const raw_artist of action.artists) {
console.log(raw_artist);
var artist = formatArtist(raw_artist);
artist = { ...artists_index[artist.uri], ...artist };
/*
// Migrate nested tracks objects into references to our tracks index
if (raw_artist.tracks) {
var tracks = formatTracks(raw_artist.tracks);
var tracks_uris = arrayOf('uri', tracks);
artist.tracks_uris = tracks_uris;
tracks_loaded = [...tracks_loaded, ...tracks];
}*/
artists_loaded.push(artist);
}
action.artists = artists_loaded;
/*
if (tracks_loaded.length > 0) {
store.dispatch(coreActions.tracksLoaded(tracks_loaded));
}
*/
store.dispatch(coreActions.updateColdStore(artists_loaded));
next(action);
next({
...action,
artists: artists_loaded,
});
break;
case 'PLAYLISTS_LOADED':

View File

@ -2182,43 +2182,47 @@ const MopidyMiddleware = (function () {
});
break;
case 'MOPIDY_GET_LIBRARY_PLAYLISTS':
case 'MOPIDY_GET_LIBRARY_PLAYLISTS': {
request(store, 'playlists.asList')
.then((response) => {
.then((listResponse) => {
// Remove any Spotify playlists. These will be handled by our Spotify API
const playlist_uris = arrayOf('uri', response).filter(
(uri) => uriSource(uri) !== 'spotify',
const playlist_uris = arrayOf('uri', listResponse).filter(
(playlistUri) => uriSource(playlistUri) !== 'spotify',
);
const libraryPlaylists = [];
// get the full playlist objects
playlist_uris.forEach((uri, index) => {
request(store, 'playlists.lookup', { uri })
.then((response) => {
libraryPlaylists.push(
formatPlaylist({
name: response.name,
uri: response.uri,
can_edit: uriSource(response.uri) === 'm3u',
last_modified: response.last_modified,
// By not including actual tracks they will be fetched when needed. We don't
// want these simple tracks because they don't contain duration, artist, etc.
tracks_total: response.tracks ? response.tracks.length : null,
}),
);
if (playlist_uris.length) {
playlist_uris.forEach((uri, index) => {
request(store, 'playlists.lookup', { uri })
.then((response) => {
libraryPlaylists.push(
formatPlaylist({
name: response.name,
uri: response.uri,
can_edit: uriSource(response.uri) === 'm3u',
last_modified: response.last_modified,
// By not including actual tracks they will be fetched when needed. We don't
// want these simple tracks because they don't contain duration, artist, etc.
tracks_total: response.tracks ? response.tracks.length : null,
}),
);
if (index === playlist_uris.length - 1) {
store.dispatch(coreActions.itemsLoaded(libraryPlaylists));
store.dispatch(coreActions.libraryLoaded({
uri: 'mopidy:library:playlists',
items_uris: arrayOf('uri', libraryPlaylists),
}));
}
});
});
if (index === playlist_uris.length - 1) {
store.dispatch(coreActions.itemsLoaded(libraryPlaylists));
store.dispatch(coreActions.libraryLoaded({
uri: 'mopidy:library:playlists',
items_uris: arrayOf('uri', libraryPlaylists),
}));
}
});
});
} else {
store.dispatch(uiActions.stopLoading('mopidy:library:playlists'));
}
});
break;
}
case 'MOPIDY_GET_LIBRARY_ALBUMS':
request(store, 'library.browse', { uri: store.getState().mopidy.library_albums_uri })

View File

@ -148,6 +148,7 @@ const rootPersistConfig = {
'ui',
'core',
'spotify',
'pusher',
],
debug: window.test_mode,
};
@ -167,6 +168,15 @@ const corePersistConfig = {
],
};
const pusherPersistConfig = {
key: 'pusher',
storage: localForage,
blacklist: [
'connections',
],
debug: window.test_mode,
};
const mopidyPersistConfig = {
key: 'mopidy',
storage: localForage,
@ -228,7 +238,7 @@ const rootReducer = combineReducers({
ui: persistReducer(uiPersistConfig, ui),
mopidy: persistReducer(mopidyPersistConfig, mopidy),
spotify: persistReducer(spotifyPersistConfig, spotify),
pusher,
pusher: persistReducer(pusherPersistConfig, pusher),
lastfm,
genius,
google,

View File

@ -1,4 +1,3 @@
import { memoize } from 'lodash';
import { createSelector } from 'reselect';
import { indexToArray } from './arrays';
import { isLoading } from './helpers';

View File

@ -170,8 +170,6 @@ export class Album extends React.Component {
slim_mode,
} = this.props;
console.log('Album.render')
if (loading) {
return <Loader body loading />;
} else if (!album) {

View File

@ -402,8 +402,6 @@ class Artist extends React.Component {
history,
} = this.props;
console.log('render!')
if (loading) {
return <Loader body loading />;
} else if (!artist) {
@ -525,7 +523,7 @@ const mapStateToProps = (state, ownProps) => {
const loadingSelector = makeLoadingSelector([`(.*)${uri}(.*)`]);
const artistSelector = makeItemSelector(uri);
const artist = artistSelector(state);
let albums = [];
let albums = null;
if (artist && artist.albums_uris) {
const albumsSelector = makeItemSelector(artist.albums_uris);
albums = albumsSelector(state);

View File

@ -209,6 +209,7 @@ class Queue extends React.Component {
shuffleTracklist,
},
} = this.props;
const { limit } = this.state;
const total_queue_tracks = queue_tracks.length;
const tracks = queue_tracks.slice(0, limit);
@ -329,19 +330,20 @@ class Queue extends React.Component {
}
const mapStateToProps = (state) => {
let { current_track } = state.core;
const {
current_track: core_current_track,
items,
queue,
queue_metadata,
} = state.core;
const queue_tracks = [];
let current_track = {};
if (queue && items) {
for (const queue_track of queue) {
let track = {
...queue_track,
playing: current_track && current_track.tlid == queue_track.tlid,
playing: core_current_track && core_current_track.tlid == queue_track.tlid,
};
// If we have the track in our index, merge it in.

View File

@ -41,8 +41,6 @@ class QueueHistory extends React.Component {
uiActions,
} = this.props;
console.log('rendering')
const options = (
<Button
onClick={this.onBack}

View File

@ -137,18 +137,18 @@ class LibraryPlaylists extends React.Component {
sort,
sort_reverse,
view,
source,
loading,
playlists: playlistsProp,
} = this.props;
const {
filter,
limit,
} = this.state;
let { playlists } = this.props;
if (loading) {
return <Loader body loading />;
}
let playlists = [...playlistsProp];
if (sort) {
playlists = sortItems(playlists, sort, sort_reverse);