SongList.jsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React, { Component } from "react";
  2. import PropTypes from "prop-types";
  3. import { Map } from "immutable";
  4. import { connect } from "react-redux";
  5. import SongItem from "./SongItem.jsx";
  6. @connect(state => ({
  7. station: {
  8. songList: state.station.info.get("songList"),
  9. },
  10. currentSong: {
  11. exists: state.station.currentSong.get("songId") !== "",
  12. songId: state.station.currentSong.get("songId"),
  13. thumbnail: state.station.currentSong.get("thumbnail"),
  14. duration: state.station.currentSong.getIn(["timings", "duration"]),
  15. title: state.station.currentSong.get("title"),
  16. artists: state.station.currentSong.get("artists"),
  17. },
  18. }))
  19. export default class SongList extends Component {
  20. constructor(props) {
  21. super(props);
  22. }
  23. render() {
  24. const { songList } = this.props.station;
  25. const currentSong = (this.props.currentSong.exists) ? Map({
  26. thumbnail: this.props.currentSong.thumbnail,
  27. duration: this.props.currentSong.duration,
  28. title: this.props.currentSong.title,
  29. artists: this.props.currentSong.artists,
  30. }) : null;
  31. return (
  32. <ul>
  33. {
  34. (this.props.currentSong.exists) ? <SongItem key={ this.props.currentSong.songId } song={ currentSong } deleteable={ false }/> : null
  35. }
  36. {
  37. songList.map((song) => {
  38. return <SongItem key={ song.get("songId") } song={ song }/>;
  39. })
  40. }
  41. {
  42. (songList.length === 0)
  43. ? <li>No songs in queue.</li>
  44. : null
  45. }
  46. </ul>
  47. );
  48. }
  49. }