import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { createStore, bindActionCreators } from 'redux' import Link from './Link' import ArtistSentence from './ArtistSentence' import Thumbnail from './Thumbnail' import * as uiActions from '../services/ui/actions' class GridSlider extends React.Component{ constructor(props){ super(props) this._pagelimit = 3 this.state = { page: 0 } } handleClick(e,link){ if (e.target.tagName.toLowerCase() !== 'a'){ this.props.history.push(link) } } handleContextMenu(e,item){ e.preventDefault() var data = { uris: [item.uri], item: item } this.props.uiActions.showContextMenu(e, data, 'album', 'click' ) } next(){ if (this.state.page >= this._pagelimit) return false this.setState({ page: this.state.page + 1 }) } previous(){ if (this.state.page <= 0) return false this.setState({ page: this.state.page - 1 }) } render(){ if (this.props.tracks){ var className = "grid-slider-wrapper" if (this.props.className ) className += ' '+this.props.className var style = { left: '-'+(this.state.page * 100)+'%' } return (
{ this.props.title ? this.props.title : null }
this.previous() } /> = this._pagelimit} onClick={ () => this.next() } />
{ this.props.tracks.map( (track, index) => { var album = Object.assign({}, track.album, { artists: track.artists }) return (
this.handleClick(e,global.baseURL+'album/'+album.uri) } onContextMenu={e => this.handleContextMenu(e,album)}>
{ album.name }
{ album.artists ? : - }
) } ) }
); } return null; } } const mapStateToProps = (state, ownProps) => { return {} } const mapDispatchToProps = (dispatch) => { return { uiActions: bindActionCreators(uiActions, dispatch) } } export default connect(mapStateToProps, mapDispatchToProps)(GridSlider)