Polishing spotify actions, removing middleware; Mopidy current track selection

This commit is contained in:
James Barnsley
2016-10-21 09:56:07 +13:00
parent daab2133df
commit afb6bb7a0d
19 changed files with 444 additions and 102 deletions

View File

@ -0,0 +1,54 @@
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
import AlbumGrid from '../../components/AlbumGrid'
import * as mopidyActions from '../../services/mopidy/actions'
import * as spotifyActions from '../../services/spotify/actions'
class LibraryAlbums extends React.Component{
constructor(props) {
super(props);
}
// on render
componentDidMount(){
this.props.spotifyActions.getLibraryAlbums();
}
render(){
if( this.props.spotify.libraryAlbums ){
return (
<div>
<h3>My albums</h3>
<AlbumGrid items={this.props.spotify.libraryAlbums} />
</div>
);
}
return null;
}
}
/**
* Export our component
*
* We also integrate our global store, using connect()
**/
const mapStateToProps = (state, ownProps) => {
return state;
}
const mapDispatchToProps = (dispatch) => {
return {
mopidyActions: bindActionCreators(mopidyActions, dispatch),
spotifyActions: bindActionCreators(spotifyActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(LibraryAlbums)

View File

@ -0,0 +1,59 @@
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
import * as mopidyActions from '../../services/mopidy/actions'
import * as spotifyActions from '../../services/spotify/actions'
class LibraryArtists extends React.Component{
constructor(props) {
super(props);
}
// on render
componentDidMount(){
this.props.spotifyActions.getLibraryArtists();
}
render(){
if( this.props.spotify.libraryArtists ){
return (
<div>
<h3>My artists</h3>
<ul>
{
this.props.spotify.libraryArtists.artists.items.map( (artist, index) => {
var link = '/artist/' + artist.uri;
return <li key={index}><Link to={link}>{ artist.name }</Link></li>
})
}
</ul>
</div>
);
}
return null;
}
}
/**
* Export our component
*
* We also integrate our global store, using connect()
**/
const mapStateToProps = (state, ownProps) => {
return state;
}
const mapDispatchToProps = (dispatch) => {
return {
mopidyActions: bindActionCreators(mopidyActions, dispatch),
spotifyActions: bindActionCreators(spotifyActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(LibraryArtists)

View File

@ -0,0 +1,59 @@
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
import * as mopidyActions from '../../services/mopidy/actions'
import * as spotifyActions from '../../services/spotify/actions'
class LibraryPlaylists extends React.Component{
constructor(props) {
super(props);
}
// on render
componentDidMount(){
this.props.spotifyActions.getLibraryPlaylists();
}
render(){
if( this.props.spotify.libraryPlaylists ){
return (
<div>
<h3>My playlists</h3>
<ul>
{
this.props.spotify.libraryPlaylists.items.map( (playlist, index) => {
var link = '/playlist/' + playlist.uri;
return <li key={index}><Link to={link}>{ playlist.name }</Link></li>
})
}
</ul>
</div>
);
}
return null;
}
}
/**
* Export our component
*
* We also integrate our global store, using connect()
**/
const mapStateToProps = (state, ownProps) => {
return state;
}
const mapDispatchToProps = (dispatch) => {
return {
mopidyActions: bindActionCreators(mopidyActions, dispatch),
spotifyActions: bindActionCreators(spotifyActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(LibraryPlaylists)

View File

@ -0,0 +1,54 @@
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
import TrackList from '../../components/TrackList'
import * as mopidyActions from '../../services/mopidy/actions'
import * as spotifyActions from '../../services/spotify/actions'
class LibraryTracks extends React.Component{
constructor(props) {
super(props);
}
// on render
componentDidMount(){
this.props.spotifyActions.getLibraryTracks();
}
render(){
if( this.props.spotify.libraryTracks ){
return (
<div>
<h3>My tracks</h3>
<TrackList tracks={this.props.spotify.libraryTracks.items} />
</div>
);
}
return null;
}
}
/**
* Export our component
*
* We also integrate our global store, using connect()
**/
const mapStateToProps = (state, ownProps) => {
return state;
}
const mapDispatchToProps = (dispatch) => {
return {
mopidyActions: bindActionCreators(mopidyActions, dispatch),
spotifyActions: bindActionCreators(spotifyActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(LibraryTracks)