diff --git a/frontend/src/Album/Details/AlbumDetailsPageConnector.js b/frontend/src/Album/Details/AlbumDetailsPageConnector.js index bf9c53992..fffd014ad 100644 --- a/frontend/src/Album/Details/AlbumDetailsPageConnector.js +++ b/frontend/src/Album/Details/AlbumDetailsPageConnector.js @@ -5,6 +5,8 @@ import { createSelector } from 'reselect'; import { push } from 'connected-react-router'; import NotFound from 'Components/NotFound'; import { fetchAlbums, clearAlbums } from 'Store/Actions/albumActions'; +import PageContent from 'Components/Page/PageContent'; +import PageContentBodyConnector from 'Components/Page/PageContentBodyConnector'; import LoadingIndicator from 'Components/Loading/LoadingIndicator'; import AlbumDetailsConnector from './AlbumDetailsConnector'; @@ -12,15 +14,16 @@ function createMapStateToProps() { return createSelector( (state, { match }) => match, (state) => state.albums, - (match, albums) => { + (state) => state.artist, + (match, albums, artist) => { const foreignAlbumId = match.params.foreignAlbumId; - const isAlbumsFetching = albums.isFetching; - const isAlbumsPopulated = albums.isPopulated; + const isFetching = albums.isFetching || artist.isFetching; + const isPopulated = albums.isPopulated && artist.isPopulated; return { foreignAlbumId, - isAlbumsFetching, - isAlbumsPopulated + isFetching, + isPopulated }; } ); @@ -71,8 +74,8 @@ class AlbumDetailsPageConnector extends Component { render() { const { foreignAlbumId, - isAlbumsFetching, - isAlbumsPopulated + isFetching, + isPopulated } = this.props; if (!foreignAlbumId) { @@ -83,19 +86,18 @@ class AlbumDetailsPageConnector extends Component { ); } - if (isAlbumsFetching || !this.state.hasMounted) { + if ((isFetching || !this.state.hasMounted) || + (!isFetching && !isPopulated)) { return ( - + + + + + ); } - if (!isAlbumsFetching && !isAlbumsPopulated) { - return ( - - ); - } - - if (!isAlbumsFetching && isAlbumsPopulated && this.state.hasMounted) { + if (!isFetching && isPopulated && this.state.hasMounted) { return ( match, - createAllArtistSelector(), - (match, allArtists) => { + (state) => state.artist, + (match, artist) => { const foreignArtistId = match.params.foreignArtistId; - const artistIndex = _.findIndex(allArtists, { foreignArtistId }); + const { + isFetching, + isPopulated, + error, + items + } = artist; + + const artistIndex = _.findIndex(items, { foreignArtistId }); if (artistIndex > -1) { return { + isFetching, + isPopulated, foreignArtistId }; } - return {}; + return { + isFetching, + isPopulated, + error + }; } ); } @@ -48,9 +65,30 @@ class ArtistDetailsPageConnector extends Component { render() { const { - foreignArtistId + foreignArtistId, + isFetching, + isPopulated, + error } = this.props; + if (isFetching && !isPopulated) { + return ( + + + + + + ); + } + + if (!isFetching && !!error) { + return ( +
+ {getErrorMessage(error, 'Failed to load artist from API')} +
+ ); + } + if (!foreignArtistId) { return (