Refactor movie alternative titles connector

pull/9497/head
Bogdan 11 months ago
parent 22cc34b4fe
commit 8554c0d9cb

@ -6,31 +6,43 @@ import MovieTitlesTableContent from './MovieTitlesTableContent';
function createMapStateToProps() { function createMapStateToProps() {
return createSelector( return createSelector(
(state, { movieId }) => movieId,
(state) => state.movies, (state) => state.movies,
(movies) => { (movieId, movies) => {
return movies; const {
isFetching,
isPopulated,
error,
items
} = movies;
const alternateTitles = items.find((m) => m.id === movieId)?.alternateTitles;
return {
isFetching,
isPopulated,
error,
alternateTitles
};
} }
); );
} }
const mapDispatchToProps = {
// fetchMovies
};
class MovieTitlesTableContentConnector extends Component { class MovieTitlesTableContentConnector extends Component {
// //
// Render // Render
render() { render() {
const movie = this.props.items.filter((obj) => { const {
return obj.id === this.props.movieId; alternateTitles,
}); ...otherProps
} = this.props;
return ( return (
<MovieTitlesTableContent <MovieTitlesTableContent
{...this.props} {...otherProps}
items={movie[0].alternateTitles} items={alternateTitles}
/> />
); );
} }
@ -38,7 +50,11 @@ class MovieTitlesTableContentConnector extends Component {
MovieTitlesTableContentConnector.propTypes = { MovieTitlesTableContentConnector.propTypes = {
movieId: PropTypes.number.isRequired, movieId: PropTypes.number.isRequired,
items: PropTypes.arrayOf(PropTypes.object).isRequired alternateTitles: PropTypes.arrayOf(PropTypes.object).isRequired
};
MovieTitlesTableContentConnector.defaultProps = {
alternateTitles: []
}; };
export default connect(createMapStateToProps, mapDispatchToProps)(MovieTitlesTableContentConnector); export default connect(createMapStateToProps)(MovieTitlesTableContentConnector);

Loading…
Cancel
Save