Housekeeping library component fetches

This commit is contained in:
James Barnsley
2020-08-12 08:06:24 +12:00
parent a612a6a626
commit 2151c42536
11 changed files with 325 additions and 371 deletions

View File

@ -40,15 +40,6 @@ class LibraryAlbums extends React.Component {
uiActions: {
setWindowTitle,
},
mopidy_library_albums_status,
source,
mopidyActions,
spotifyActions,
googleActions,
google_available,
google_library_albums_status,
spotify_available,
spotify_library_albums_status,
} = this.props;
// Restore any limit defined in our location state
@ -59,54 +50,71 @@ class LibraryAlbums extends React.Component {
}
setWindowTitle(i18n('library.albums.title'));
this.getMopidyLibrary();
this.getGoogleLibrary();
this.getSpotifyLibrary();
}
if (mopidy_library_albums_status !== 'finished' && mopidy_library_albums_status !== 'started' && (source === 'all' || source === 'local')) {
mopidyActions.getLibraryAlbums();
}
componentDidUpdate = ({ source: prevSource }) => {
const { source } = this.props;
if (google_available && google_library_albums_status !== 'finished' && google_library_albums_status !== 'started' && (source === 'all' || source === 'google')) {
googleActions.getLibraryAlbums();
}
if (spotify_available && spotify_library_albums_status !== 'finished' && spotify_library_albums_status !== 'started' && (source == 'all' || source === 'spotify')) {
spotifyActions.getLibraryAlbums();
if (source !== prevSource) {
this.getMopidyLibrary();
this.getGoogleLibrary();
this.getSpotifyLibrary();
}
}
componentDidUpdate = () => {
getMopidyLibrary = () => {
const {
google_available,
spotify_available,
source,
mopidyActions,
googleActions,
spotifyActions,
mopidy_library_albums_status,
google_library_albums_status,
spotify_library_albums_status,
mopidy_library_playlists,
mopidyActions: {
getLibraryAlbums,
},
} = this.props;
if (source === 'all' || source === 'local') {
// Filter changed, but we haven't got this provider's library yet
if (source !== 'all' && source !== 'local' && mopidy_library_albums_status !== 'finished' && mopidy_library_albums_status !== 'started') {
mopidyActions.getLibraryAlbums();
}
}
if (source !== 'local' && source !== 'all') return;
if (mopidy_library_playlists) return;
if (google_available && (source === 'all' || source === 'google')) {
// Filter changed, but we haven't got this provider's library yet
if (source !== 'all' && source !== 'google' && google_library_albums_status !== 'finished' && google_library_albums_status !== 'started') {
googleActions.getLibraryAlbums();
}
}
getLibraryAlbums();
};
if (spotify_available && (source === 'all' || source === 'spotify')) {
// Filter changed, but we haven't got this provider's library yet
if (spotify_library_albums_status !== 'finished' && spotify_library_albums_status !== 'started') {
spotifyActions.getLibraryAlbums();
}
}
}
getGoogleLibrary = () => {
const {
source,
google_available,
google_library_albums_status,
googleActions: {
getLibraryAlbums,
},
} = this.props;
if (!google_available) return;
if (source !== 'google' && source !== 'all') return;
if (google_library_albums_status === 'finished') return;
if (google_library_albums_status === 'started') return;
getLibraryAlbums();
};
getSpotifyLibrary = () => {
const {
source,
spotify_available,
spotify_library_albums_status,
spotifyActions: {
getLibraryAlbums,
},
} = this.props;
if (!spotify_available) return;
if (source !== 'spotify' && source !== 'all') return;
if (spotify_library_albums_status === 'finished') return;
if (spotify_library_albums_status === 'started') return;
getLibraryAlbums();
};
handleContextMenu = (e, item) => {
const {

View File

@ -32,15 +32,6 @@ class LibraryArtists extends React.Component {
componentDidMount() {
const {
source,
mopidy_library_artists,
mopidyActions,
google_available,
google_library_artists,
googleActions,
spotify_available,
spotify_library_artists_status,
spotifyActions,
uiActions: {
setWindowTitle,
},
@ -56,58 +47,70 @@ class LibraryArtists extends React.Component {
setWindowTitle(i18n('library.artists.title'));
if (!mopidy_library_artists && (source === 'all' || source === 'local')) {
mopidyActions.getLibraryArtists();
}
this.getMopidyLibrary();
this.getGoogleLibrary();
this.getSpotifyLibrary();
}
if (google_available && !google_library_artists && (source === 'all' || source === 'google')) {
googleActions.getLibraryArtists();
}
componentDidUpdate = ({ source: prevSource }) => {
const { source } = this.props;
if (spotify_available && spotify_library_artists_status !== 'finished' && (source === 'all' || source === 'spotify')) {
spotifyActions.getLibraryArtists();
if (source !== prevSource) {
this.getMopidyLibrary();
this.getGoogleLibrary();
this.getSpotifyLibrary();
}
}
componentDidUpdate = ({
source: prevSource,
}) => {
getMopidyLibrary = () => {
const {
source,
mopidy_library_artists,
mopidyActions: {
getLibraryArtists,
},
} = this.props;
if (source !== 'local' && source !== 'all') return;
if (mopidy_library_artists) return;
getLibraryArtists();
};
getGoogleLibrary = () => {
const {
source,
google_available,
spotify_available,
mopidyActions,
googleActions,
spotifyActions,
mopidy_library_artists,
google_library_artists,
spotify_library_artists_status,
googleActions: {
getLibraryArtists,
},
} = this.props;
if (source !== prevSource) {
switch (source) {
case 'google':
if (google_available && !google_library_artists) {
googleActions.getLibraryArtists();
}
break;
case 'spotify':
if (spotify_available && spotify_library_artists_status !== 'finished' && spotify_library_artists_status !== 'started') {
spotifyActions.getLibraryArtists();
}
break;
case 'local':
if (!mopidy_library_artists) {
mopidyActions.getLibraryArtists();
}
break;
default:
mopidyActions.getLibraryArtists();
googleActions.getLibraryArtists();
spotifyActions.getLibraryArtists();
}
}
}
if (!google_available) return;
if (source !== 'google' && source !== 'all') return;
if (google_library_artists) return;
getLibraryArtists();
};
getSpotifyLibrary = () => {
const {
source,
spotify_available,
spotify_library_artists_status,
spotifyActions: {
getLibraryArtists,
},
} = this.props;
if (!spotify_available) return;
if (source !== 'spotify' && source !== 'all') return;
if (spotify_library_artists_status === 'finished') return;
if (spotify_library_artists_status === 'started') return;
getLibraryArtists();
};
handleContextMenu(e, item) {
const data = {
@ -342,8 +345,7 @@ class LibraryArtists extends React.Component {
}
}
const mapStateToProps = (state, ownProps) => ({
mopidy_connected: state.mopidy.connected,
const mapStateToProps = (state) => ({
mopidy_uri_schemes: state.mopidy.uri_schemes,
mopidy_library_artists: state.mopidy.library_artists,
google_available: (state.mopidy.uri_schemes && state.mopidy.uri_schemes.includes('gmusic:')),

View File

@ -17,15 +17,14 @@ class LibraryBrowse extends React.Component {
this.props.uiActions.setWindowTitle(i18n('library.browse.title'));
}
componentDidUpdate = ({ mopidy_connected: prev_mopidy_connected}) => {
const { mopidy_connected } = this.props;
if (!prev_mopidy_connected && mopidy_connected) this.loadDirectory();
}
loadDirectory = () => {
const {
mopidyActions: {
getDirectory,
},
} = this.props;
loadDirectory(props = this.props) {
if (props.mopidy_connected) {
this.props.mopidyActions.getDirectory(null);
}
getDirectory(null);
}
render() {
@ -124,9 +123,8 @@ class LibraryBrowse extends React.Component {
}
}
const mapStateToProps = (state, ownProps) => ({
const mapStateToProps = (state) => ({
load_queue: state.ui.load_queue,
mopidy_connected: state.mopidy.connected,
directory: state.mopidy.directory,
view: state.ui.library_directory_view,
});

View File

@ -45,27 +45,23 @@ class LibraryBrowseDirectory extends React.Component {
this.loadDirectory();
}
componentDidUpdate = ({
mopidy_connected: prev_mopidy_connected,
uri: prevUri,
}) => {
const {
uri,
mopidy_connected,
} = this.props;
componentDidUpdate = ({ uri: prevUri }) => {
const { uri } = this.props;
if (!prev_mopidy_connected && mopidy_connected) this.loadDirectory();
if (uri && uri !== prevUri) this.loadDirectory();
if (uri && uri !== prevUri) {
this.loadDirectory();
}
}
loadDirectory(props = this.props) {
if (props.mopidy_connected) {
let uri = null;
if (props.uri !== undefined) {
uri = props.uri;
}
this.props.mopidyActions.getDirectory(uri);
}
loadDirectory = () => {
const {
uri,
mopidyActions: {
getDirectory,
},
} = this.props;
getDirectory(uri);
}
loadMore = () => {
@ -283,7 +279,6 @@ const mapStateToProps = (state, ownProps) => {
return {
uri,
load_queue: state.ui.load_queue,
mopidy_connected: state.mopidy.connected,
directory: state.mopidy.directory,
view: state.ui.library_directory_view,
};

View File

@ -39,40 +39,47 @@ class LibraryPlaylists extends React.Component {
this.props.uiActions.setWindowTitle(i18n('library.playlists.title'));
if (!this.props.mopidy_library_playlists && this.props.mopidy_connected && (this.props.source == 'all' || this.props.source == 'local')) {
this.props.mopidyActions.getLibraryPlaylists();
}
if (this.props.spotify_available && this.props.spotify_library_playlists_status !== 'finished' && (this.props.source == 'all' || this.props.source == 'spotify')) {
this.props.spotifyActions.getLibraryPlaylists();
}
this.getMopidyLibrary();
this.getSpotifyLibrary();
}
componentDidUpdate = ({
mopidy_connected: prev_mopidy_connected,
}) => {
getMopidyLibrary = () => {
const {
source,
mopidy_connected,
mopidy_library_playlists,
spotify_available,
spotify_library_playlists_status,
mopidyActions,
spotifyActions,
mopidyActions: {
getLibraryPlaylists,
},
} = this.props;
if (mopidy_connected && (source == 'all' || source == 'local')) {
if (!prev_mopidy_connected) mopidyActions.getLibraryPlaylists();
if (source !== 'local' && source !== 'all') return;
if (mopidy_library_playlists) return;
if (source !== 'all' && source !== 'local' && !mopidy_library_playlists) {
this.props.mopidyActions.getLibraryPlaylists();
}
}
getLibraryPlaylists();
};
if (spotify_available && (source === 'all' || source === 'spotify')) {
if (spotify_library_playlists_status !== 'finished' && spotify_library_playlists_status !== 'started') {
spotifyActions.getLibraryPlaylists();
}
getSpotifyLibrary = () => {
const {
source,
spotify_library_playlists_status,
spotifyActions: {
getLibraryPlaylists,
},
} = this.props;
if (source !== 'spotify' && source !== 'all') return;
if (spotify_library_playlists_status === 'finished') return;
if (spotify_library_playlists_status === 'started') return;
getLibraryPlaylists();
};
componentDidUpdate = ({ source: prevSource }) => {
const { source } = this.props;
if (source !== prevSource) {
this.getMopidyLibrary();
this.getSpotifyLibrary();
}
}
@ -291,9 +298,8 @@ class LibraryPlaylists extends React.Component {
}
}
const mapStateToProps = (state, ownProps) => ({
const mapStateToProps = (state) => ({
slim_mode: state.ui.slim_mode,
mopidy_connected: state.mopidy.connected,
mopidy_uri_schemes: state.mopidy.uri_schemes,
mopidy_library_playlists: state.mopidy.library_playlists,
mopidy_library_playlists_status: (state.ui.processes.MOPIDY_LIBRARY_PLAYLISTS_PROCESSOR !== undefined ? state.ui.processes.MOPIDY_LIBRARY_PLAYLISTS_PROCESSOR.status : null),