You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Sonarr/frontend/src/Episode/History/EpisodeHistoryConnector.js

70 lines
1.7 KiB

import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { clearEpisodeHistory, episodeHistoryMarkAsFailed, fetchEpisodeHistory } from 'Store/Actions/episodeHistoryActions';
import createUISettingsSelector from 'Store/Selectors/createUISettingsSelector';
import EpisodeHistory from './EpisodeHistory';
function createMapStateToProps() {
return createSelector(
(state) => state.episodeHistory,
createUISettingsSelector(),
(episodeHistory, uiSettings) => {
return {
...episodeHistory,
timeFormat: uiSettings.timeFormat,
shortDateFormat: uiSettings.shortDateFormat
};
}
);
}
const mapDispatchToProps = {
fetchEpisodeHistory,
clearEpisodeHistory,
episodeHistoryMarkAsFailed
};
class EpisodeHistoryConnector extends Component {
//
// Lifecycle
componentDidMount() {
this.props.fetchEpisodeHistory({ episodeId: this.props.episodeId });
}
componentWillUnmount() {
this.props.clearEpisodeHistory();
}
//
// Listeners
onMarkAsFailedPress = (historyId) => {
this.props.episodeHistoryMarkAsFailed({ historyId, episodeId: this.props.episodeId });
};
//
// Render
render() {
return (
<EpisodeHistory
{...this.props}
onMarkAsFailedPress={this.onMarkAsFailedPress}
/>
);
}
}
EpisodeHistoryConnector.propTypes = {
episodeId: PropTypes.number.isRequired,
fetchEpisodeHistory: PropTypes.func.isRequired,
clearEpisodeHistory: PropTypes.func.isRequired,
episodeHistoryMarkAsFailed: PropTypes.func.isRequired
};
export default connect(createMapStateToProps, mapDispatchToProps)(EpisodeHistoryConnector);