Lidarr/frontend/src/Album/EpisodeDetailsModalContentC...

126 lines
3.0 KiB
JavaScript
Raw Normal View History

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';
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,
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,
nameSlug,
artistMonitored,
...album
2017-09-04 02:20:56 +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();
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;
const albumId = this.props.albumId;
this.props.dispatchFetchTracks({ artistId, albumId });
2017-09-24 19:44:25 +00:00
}
_unpopulate() {
this.props.dispatchClearTracks();
2017-09-24 19:44:25 +00:00
}
2017-09-04 02:20:56 +00:00
//
// Render
2017-09-04 02:20:56 +00:00
render() {
2017-09-04 02:20:56 +00:00
const {
dispatchClearReleases,
...otherProps
2017-09-04 02:20:56 +00:00
} = this.props;
return (
<EpisodeDetailsModalContent {...otherProps} />
2017-09-04 02:20:56 +00:00
);
}
}
EpisodeDetailsModalContentConnector.propTypes = {
albumId: PropTypes.number.isRequired,
2017-09-04 02:20:56 +00:00
episodeEntity: PropTypes.string.isRequired,
artistId: PropTypes.number.isRequired,
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
};
export default connect(createMapStateToProps, createMapDispatchToProps)(EpisodeDetailsModalContentConnector);