All files / src/containers AlbumsContainer.jsx

65% Statements 13/20
90% Branches 9/10
28.57% Functions 2/7
68.42% Lines 13/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55                      4x 4x               4x 4x 3x 1x             2x 1x 1x 1x     1x       5x           5x                
import React, { Component } from "react";
import { connect } from "react-redux";
import Albums from "../components/Albums";
import { getAlbums } from "../redux/selectors";
import { push } from "react-router-redux";
import Progress from "../components/Progress";
import ErrorSnackbar from "../components/ErrorSnackbar";
import { recommendations } from "../redux/actions";
 
export class AlbumsContainer extends Component {
  constructor(props) {
    super(props);
    this.handleAlbumClick = this.handleAlbumClick.bind(this);
  }
  handleAlbumClick(album) {
    const newurl = `${process.env.PUBLIC_URL}/recommendations/${album.id}`;
    this.props.fetchRecommendations(album);
    this.props.changeUrl(newurl);
  }
  render() {
    const { albums } = this.props;
    if (albums) {
      if (albums.result && albums.result.items) {
        return (
          <Albums
            title={"Albums"}
            albums={albums.result.items}
            handleClick={this.handleAlbumClick}
          />
        );
      } else if (albums.loading) {
        return <Progress status="searching..." />;
      } else Eif (albums.error) {
        return <ErrorSnackbar message={albums.error.message} />;
      }
    }
    return <div />;
  }
}
 
const mapStateToProps = (state, ownProps) => {
  return {
    albums: getAlbums(state)
  };
};
 
const mapDispatchToProps = dispatch => ({
  changeUrl: url => {
    dispatch(push(url));
  },
  fetchRecommendations: album => dispatch(recommendations({ album: album }))
});
 
export default connect(mapStateToProps, mapDispatchToProps)(AlbumsContainer);