2017-09-04 02:20:56 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { createSelector } from 'reselect';
|
2017-11-16 02:24:33 +00:00
|
|
|
import { cancelFetchReleases, clearReleases } from 'Store/Actions/releaseActions';
|
2017-09-04 02:20:56 +00:00
|
|
|
import { toggleEpisodeMonitored } from 'Store/Actions/episodeActions';
|
|
|
|
import createEpisodeSelector from 'Store/Selectors/createEpisodeSelector';
|
|
|
|
import createArtistSelector from 'Store/Selectors/createArtistSelector';
|
2017-10-19 01:56:15 +00:00
|
|
|
import episodeEntities from 'Album/episodeEntities';
|
2017-09-24 19:44:25 +00:00
|
|
|
import { fetchTracks, clearTracks } from 'Store/Actions/trackActions';
|
2017-09-04 02:20:56 +00:00
|
|
|
import EpisodeDetailsModalContent from './EpisodeDetailsModalContent';
|
|
|
|
|
|
|
|
function createMapStateToProps() {
|
|
|
|
return createSelector(
|
|
|
|
createEpisodeSelector(),
|
|
|
|
createArtistSelector(),
|
2017-10-07 22:38:31 +00:00
|
|
|
(album, artist) => {
|
2017-09-04 02:20:56 +00:00
|
|
|
const {
|
2017-09-16 20:22:06 +00:00
|
|
|
artistName,
|
2017-09-15 03:35:12 +00:00
|
|
|
nameSlug,
|
2017-10-07 22:38:31 +00:00
|
|
|
monitored: artistMonitored
|
|
|
|
} = artist;
|
2017-09-04 02:20:56 +00:00
|
|
|
|
|
|
|
return {
|
2017-09-16 20:22:06 +00:00
|
|
|
artistName,
|
2017-09-15 03:35:12 +00:00
|
|
|
nameSlug,
|
|
|
|
artistMonitored,
|
2017-10-07 02:28:30 +00:00
|
|
|
...album
|
2017-09-04 02:20:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-11-16 02:24:33 +00:00
|
|
|
function createMapDispatchToProps(dispatch, props) {
|
|
|
|
return {
|
|
|
|
dispatchCancelFetchReleases() {
|
|
|
|
dispatch(cancelFetchReleases());
|
|
|
|
},
|
|
|
|
|
|
|
|
dispatchClearReleases() {
|
|
|
|
dispatch(clearReleases());
|
|
|
|
},
|
|
|
|
|
|
|
|
dispatchFetchTracks({ artistId, albumId }) {
|
|
|
|
dispatch(fetchTracks({ artistId, albumId }));
|
|
|
|
},
|
|
|
|
|
|
|
|
dispatchClearTracks() {
|
|
|
|
dispatch(clearTracks());
|
|
|
|
},
|
|
|
|
|
|
|
|
onMonitorAlbumPress(monitored) {
|
|
|
|
const {
|
|
|
|
albumId,
|
|
|
|
episodeEntity
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
dispatch(toggleEpisodeMonitored({
|
|
|
|
episodeEntity,
|
|
|
|
albumId,
|
|
|
|
monitored
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2017-09-04 02:20:56 +00:00
|
|
|
|
|
|
|
class EpisodeDetailsModalContentConnector extends Component {
|
|
|
|
|
|
|
|
//
|
|
|
|
// Lifecycle
|
2017-09-24 19:44:25 +00:00
|
|
|
componentDidMount() {
|
|
|
|
this._populate();
|
|
|
|
}
|
2017-09-04 02:20:56 +00:00
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
// Clear pending releases here so we can reshow the search
|
|
|
|
// results even after switching tabs.
|
2017-09-24 19:44:25 +00:00
|
|
|
this._unpopulate();
|
2017-11-16 02:24:33 +00:00
|
|
|
this.props.dispatchCancelFetchReleases();
|
|
|
|
this.props.dispatchClearReleases();
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
2017-09-24 19:44:25 +00:00
|
|
|
//
|
|
|
|
// Control
|
|
|
|
|
|
|
|
_populate() {
|
|
|
|
const artistId = this.props.artistId;
|
2017-10-07 02:28:30 +00:00
|
|
|
const albumId = this.props.albumId;
|
2017-11-16 02:24:33 +00:00
|
|
|
this.props.dispatchFetchTracks({ artistId, albumId });
|
2017-09-24 19:44:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_unpopulate() {
|
2017-11-16 02:24:33 +00:00
|
|
|
this.props.dispatchClearTracks();
|
2017-09-24 19:44:25 +00:00
|
|
|
}
|
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
//
|
2017-11-16 02:24:33 +00:00
|
|
|
// Render
|
2017-09-04 02:20:56 +00:00
|
|
|
|
2017-11-16 02:24:33 +00:00
|
|
|
render() {
|
2017-09-04 02:20:56 +00:00
|
|
|
const {
|
2017-11-16 02:24:33 +00:00
|
|
|
dispatchClearReleases,
|
|
|
|
...otherProps
|
2017-09-04 02:20:56 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
2017-11-16 02:24:33 +00:00
|
|
|
<EpisodeDetailsModalContent {...otherProps} />
|
2017-09-04 02:20:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EpisodeDetailsModalContentConnector.propTypes = {
|
2017-10-07 02:28:30 +00:00
|
|
|
albumId: PropTypes.number.isRequired,
|
2017-09-04 02:20:56 +00:00
|
|
|
episodeEntity: PropTypes.string.isRequired,
|
|
|
|
artistId: PropTypes.number.isRequired,
|
2017-11-16 02:24:33 +00:00
|
|
|
dispatchFetchTracks: PropTypes.func.isRequired,
|
|
|
|
dispatchClearTracks: PropTypes.func.isRequired,
|
|
|
|
dispatchCancelFetchReleases: PropTypes.func.isRequired,
|
|
|
|
dispatchClearReleases: PropTypes.func.isRequired
|
2017-09-04 02:20:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EpisodeDetailsModalContentConnector.defaultProps = {
|
|
|
|
episodeEntity: episodeEntities.EPISODES
|
|
|
|
};
|
|
|
|
|
2017-11-16 02:24:33 +00:00
|
|
|
export default connect(createMapStateToProps, createMapDispatchToProps)(EpisodeDetailsModalContentConnector);
|