diff --git a/src/about/index.js b/src/about/index.js
deleted file mode 100755
index cc272b63..00000000
--- a/src/about/index.js
+++ /dev/null
@@ -1,8 +0,0 @@
-
-import React from 'react'
-
-export default React.createClass({
- render() {
- return
About
- }
-})
\ No newline at end of file
diff --git a/src/actions.js b/src/actions.js
deleted file mode 100755
index 8d539dee..00000000
--- a/src/actions.js
+++ /dev/null
@@ -1,32 +0,0 @@
-
-/**
- * Actions and Action Creators
- **/
-
-export const TOGGLE_DONE = 'TOGGLE_DONE'
-export const ADD_TODO = 'ADD_TODO'
-export const SET_ALBUM = 'SET_ALBUM'
-
-export function toggleDone( id ){
- return {
- type: TOGGLE_DONE,
- id: id
- }
-}
-
-export function addTodo( title ){
- return {
- type: ADD_TODO,
- id: title,
- title: title
- }
-}
-
-export function setAlbum( album ){
- return {
- type: SET_ALBUM,
- album: album
- }
-}
-
-
diff --git a/src/common/actions.js b/src/actions/albumActions.js
similarity index 100%
rename from src/common/actions.js
rename to src/actions/albumActions.js
diff --git a/src/actions/index.js b/src/actions/index.js
new file mode 100755
index 00000000..c632dc3a
--- /dev/null
+++ b/src/actions/index.js
@@ -0,0 +1,3 @@
+
+import albumActions from './albumActions'
+
diff --git a/src/actions/queueActions.js b/src/actions/queueActions.js
new file mode 100755
index 00000000..e69de29b
diff --git a/src/bootstrap.js b/src/bootstrap.js
new file mode 100755
index 00000000..7d5e29d7
--- /dev/null
+++ b/src/bootstrap.js
@@ -0,0 +1,17 @@
+
+console.info('Bootstrapping...');
+
+import { createStore } from 'redux'
+import reducer from './reducers/index'
+import Services from './services/Services'
+
+// start all our services
+Promise.all(Services.setup())
+ .then(() => {
+ console.info('Services started...');
+ });
+
+// create our global store
+let store = createStore( reducer, {} );
+
+export default store;
diff --git a/src/common/Album.js b/src/components/Album.js
similarity index 81%
rename from src/common/Album.js
rename to src/components/Album.js
index 562fdcb0..b04f67ff 100755
--- a/src/common/Album.js
+++ b/src/components/Album.js
@@ -3,8 +3,8 @@ import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
-import Tracklist from '../common/Tracklist'
-import * as actions from './actions'
+import TrackList from './TrackList'
+import * as albumActions from '../actions/albumActions'
class Album extends React.Component{
@@ -47,7 +47,7 @@ class Album extends React.Component{
{ this.state.album.name }
{ this.state.album.label }
-
+
);
}
@@ -77,7 +77,7 @@ const mapStateToProps = (state, ownProps) => {
const mapDispatchToProps = (dispatch) => {
return {
- actions: bindActionCreators(actions, dispatch)
+ albumActions: bindActionCreators(albumActions, dispatch)
}
}
diff --git a/src/App.js b/src/components/App.js
similarity index 89%
rename from src/App.js
rename to src/components/App.js
index b7eb9178..824ac903 100755
--- a/src/App.js
+++ b/src/components/App.js
@@ -5,8 +5,8 @@ import { createStore, bindActionCreators } from 'redux'
import { Link } from 'react-router'
import { connect } from 'react-redux'
-import * as actions from './actions'
-import Services from './services/Services'
+import * as actions from '../actions/index'
+import Services from '../services/Services'
/**
@@ -49,7 +49,7 @@ class App extends React.Component{
return (
- - Now playing
+ - Now playing
- 808's and Heartbreak
- A million
- Library: Albums
diff --git a/src/routes/NowPlaying.js b/src/components/Queue.js
similarity index 79%
rename from src/routes/NowPlaying.js
rename to src/components/Queue.js
index 323efb71..ed6da288 100755
--- a/src/routes/NowPlaying.js
+++ b/src/components/Queue.js
@@ -4,8 +4,8 @@ import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import Services from '../services/Services'
-import Tracklist from '../common/Tracklist'
-import * as actions from '../actions'
+import TrackList from '../components/TrackList'
+import * as queueActions from '../actions/queueActions'
class NowPlaying extends React.Component{
@@ -31,7 +31,7 @@ class NowPlaying extends React.Component{
renderTracks(){
if( this.state.tracks ){
return (
-
+
);
}
return null;
@@ -60,7 +60,7 @@ const mapStateToProps = (state, ownProps) => {
const mapDispatchToProps = (dispatch) => {
return {
- actions: bindActionCreators(actions, dispatch)
+ queueActions: bindActionCreators(queueActions, dispatch)
}
}
diff --git a/src/common/Tracklist.js b/src/components/TrackList.js
similarity index 100%
rename from src/common/Tracklist.js
rename to src/components/TrackList.js
diff --git a/src/config/Mopidy.js b/src/config/Mopidy.js
deleted file mode 100755
index 9101bdd2..00000000
--- a/src/config/Mopidy.js
+++ /dev/null
@@ -1,37 +0,0 @@
-
-import React, { PropTypes } from 'react'
-import * as actions from './actions'
-import { connect } from 'react-redux'
-import { bindActionCreators } from 'redux'
-
-class Mopidy extends React.Component{
-
- constructor(props){
- super(props);
- let self = this;
- console.log('Mopidy > constructor')
- }
-
- render(){
- return null
- }
-}
-
-
-/**
- * Export our component
- *
- * We also integrate our global store, using connect()
- **/
-
-const mapStateToProps = (state, ownProps) => {
- return state;
-}
-
-const mapDispatchToProps = (dispatch) => {
- return {
- actions: bindActionCreators(actions, dispatch)
- }
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(Mopidy)
\ No newline at end of file
diff --git a/src/config/Spotify.js b/src/config/Spotify.js
deleted file mode 100755
index 5b4f5dac..00000000
--- a/src/config/Spotify.js
+++ /dev/null
@@ -1,79 +0,0 @@
-
-import React, { PropTypes } from 'react'
-import * as actions from './actions'
-import { connect } from 'react-redux'
-import { bindActionCreators } from 'redux'
-
-class Spotify extends React.Component{
-
- constructor(props){
- super(props);
- let self = this;
- this.urlBase = 'https://api.spotify.com/v1/';
- console.log('SpotifyProvider > constructor')
-
- // listen for incoming messages from the authorization iframe
- // this is triggered when authentication is granted from the popup
- window.addEventListener('message', function(event){
- if( !/^https?:\/\/jamesbarnsley\.co\.nz/.test(event.origin) ) return false;
- self.handleMessage( event );
- }, false);
- }
-
- handleMessage( event ){
-
- // convert to json
- var data = JSON.parse(event.data);
-
- // fire event
- this.props.actions.authorizeSpotifySuccess( data );
- }
-
- test(){
- console.log('test stuff');
- }
-
- getAlbum( albumid ){
- return $.when(
- $.ajax({
- method: 'GET',
- cache: true,
- url: this.urlBase+'albums/'+albumid
- })
- );
- }
-
- render(){
-
- if( this.props.config.authorizingSpotify ){
- var src = '//jamesbarnsley.co.nz/spotmop.php?action=authorize&app='+location.protocol+'//'+window.location.host;
- return (
-
- Authorizing...
-
-
- );
- }
-
- return null
- }
-}
-
-
-/**
- * Export our component
- *
- * We also integrate our global store, using connect()
- **/
-
-const mapStateToProps = (state, ownProps) => {
- return state;
-}
-
-const mapDispatchToProps = (dispatch) => {
- return {
- actions: bindActionCreators(actions, dispatch)
- }
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(Spotify)
\ No newline at end of file
diff --git a/src/config/actions.js b/src/config/actions.js
deleted file mode 100755
index 8c52a76b..00000000
--- a/src/config/actions.js
+++ /dev/null
@@ -1,21 +0,0 @@
-
-/**
- * Actions and Action Creators
- **/
-
-export const AUTHORIZE_SPOTIFY = 'AUTHORIZE_SPOTIFY'
-export const AUTHORIZE_SPOTIFY_SUCCESS = 'AUTHORIZE_SPOTIFY_SUCCESS'
-
-export function authorizeSpotify( authorize = true ){
- return {
- type: AUTHORIZE_SPOTIFY,
- authorize: authorize
- }
-}
-
-export function authorizeSpotifySuccess( authorization ){
- return {
- type: AUTHORIZE_SPOTIFY_SUCCESS,
- authorization: authorization
- }
-}
\ No newline at end of file
diff --git a/src/config/reducer.js b/src/config/reducer.js
deleted file mode 100755
index 706b8409..00000000
--- a/src/config/reducer.js
+++ /dev/null
@@ -1,24 +0,0 @@
-
-import * as actions from './actions'
-
-export default function config(config = {}, action){
- switch (action.type) {
-
- case actions.AUTHORIZE_SPOTIFY:
- return Object.assign({}, config, {
- authorizingSpotify: action.authorize
- });
-
- case actions.AUTHORIZE_SPOTIFY_SUCCESS:
- console.info('Spotify authorization successful');
- var config = Object.assign({}, config, action.authorization)
- config = Object.assign({}, config, { authorizingSpotify: false })
- return config
-
- default:
- return config
- }
-}
-
-
-
diff --git a/src/index.html b/src/index.html
index 656e218f..90a52170 100755
--- a/src/index.html
+++ b/src/index.html
@@ -4,7 +4,7 @@
Testing React and Redux
-
+
diff --git a/src/index.js b/src/index.js
index bf3257e0..f2f3a86a 100755
--- a/src/index.js
+++ b/src/index.js
@@ -10,12 +10,11 @@ import ReactDOM from 'react-dom';
import { Provider } from 'react-redux'
import { createStore } from 'redux'
import { Router, Route, Link, hashHistory } from 'react-router'
-import reducer from './reducer'
-import App from './App'
-import LibraryAlbums from './library/LibraryAlbums'
-import Album from './common/Album'
-import NowPlaying from './routes/NowPlaying'
+import store from './bootstrap.js'
+import App from './components/App'
+import Album from './components/Album'
+import Queue from './components/Queue'
import Services from './services/Services'
@@ -38,14 +37,12 @@ Promise.all(Services.setup())
**/
ReactDOM.render(
-
+
-
-
-
+
diff --git a/src/library/LibraryAlbums.js b/src/library/LibraryAlbums.js
deleted file mode 100755
index 24260f42..00000000
--- a/src/library/LibraryAlbums.js
+++ /dev/null
@@ -1,68 +0,0 @@
-
-import React, { PropTypes } from 'react'
-import * as actions from './actions'
-import { connect } from 'react-redux'
-import { bindActionCreators } from 'redux'
-
-class LibraryAlbums extends React.Component{
-
- constructor(props) {
- super(props);
-
- this.state = {
- albums: []
- };
- }
-
- // on load of this component
- componentDidMount(){
-
- var url = 'http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=4320a3ef51c9b3d69de552ac083c55e3&artist=Cher&album=Believe&format=json';
- //var url = 'https://pixabay.com/api/?key=3190651-5f431f6c829ace6d75ff07701&q=yellow+flowers&image_type=photo&pretty=true';
-
- var self = this;
-
- // url (required), options (optional)
- fetch(url, {
- method: 'get'
- }).then(function(response) {
- return response.json();
- }).then(function( json ) {
- self.setState({ albums: json.hits });
- }).catch(function(err) {
- console.error( err );
- });
- }
-
- render() {
- return (
-
-
Library album
- {
- this.state.albums.map(album =>
- { album.webformatURL }
- )
- }
-
- );
- }
-}
-
-
-/**
- * Export our component
- *
- * We also integrate our global store, using connect()
- **/
-
-const mapStateToProps = (state, ownProps) => {
- return state;
-}
-
-const mapDispatchToProps = (dispatch) => {
- return {
- actions: bindActionCreators(actions, dispatch)
- }
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(LibraryAlbums)
\ No newline at end of file
diff --git a/src/library/actions.js b/src/library/actions.js
deleted file mode 100755
index d7864d46..00000000
--- a/src/library/actions.js
+++ /dev/null
@@ -1,12 +0,0 @@
-
-/**
- * Actions and Action Creators
- **/
-
-export const LOAD_ALBUMS = 'LOAD_ALBUMS'
-
-export function loadAlbums(){
- return {
- type: LOAD_ALBUMS
- }
-}
\ No newline at end of file
diff --git a/src/library/reducer.js b/src/library/reducer.js
deleted file mode 100755
index 4697fd92..00000000
--- a/src/library/reducer.js
+++ /dev/null
@@ -1,16 +0,0 @@
-
-import * as actions from './actions'
-
-export default function album(album = {}, action) {
- switch (action.type) {
-
- case actions.SET_ALBUM:
- return Object.assign({}, album, action.album);
-
- default:
- return album
- }
-}
-
-
-
diff --git a/src/common/reducer.js b/src/reducers/album.js
similarity index 77%
rename from src/common/reducer.js
rename to src/reducers/album.js
index b1ce8565..847330e3 100755
--- a/src/common/reducer.js
+++ b/src/reducers/album.js
@@ -1,5 +1,5 @@
-import * as actions from './actions'
+import * as actions from '../actions/albumActions'
export default function album(album = {}, action) {
switch (action.type) {
diff --git a/src/reducer.js b/src/reducers/index.js
similarity index 74%
rename from src/reducer.js
rename to src/reducers/index.js
index 8d2dc149..c8efc575 100755
--- a/src/reducer.js
+++ b/src/reducers/index.js
@@ -6,15 +6,13 @@
**/
// import all of our application reducers
-import todos from './todos/reducer'
-import config from './config/reducer'
+import album from './album'
import { combineReducers } from 'redux'
// combine them into one root reducer
export default combineReducers({
- todos,
- config
+ album
})
diff --git a/src/todos/index.js b/src/todos/index.js
deleted file mode 100755
index 3dbaa37b..00000000
--- a/src/todos/index.js
+++ /dev/null
@@ -1,158 +0,0 @@
-
-import React, { PropTypes } from 'react'
-import * as actions from '../actions'
-import { connect } from 'react-redux'
-import { bindActionCreators } from 'redux'
-
-class Todos extends React.Component{
-
- constructor(props) {
- super(props);
- }
-
- // on load of this component
- componentDidMount(){
- this.props.actions.load();
- }
-
- render(){
- return (
-
- );
- }
-}
-
-
-
-/**
- * The Todo's presenter, or view
- *
- * Any UI and UX display occurs here, and is passed back to it's brain through props
- * This allows for reuse of the brain for different contexts without duplicating functionality
- **/
-class Todos_View extends React.Component{
-
- constructor(props) {
- super(props);
- }
-
- render(){
- return (
-
-
- {
- this.props.todos.map(todo =>
-
- )
- }
-
-
-
- );
- }
-}
-
-
-/**
- * The Todo item
- **/
-class TodoItem extends React.Component{
-
- constructor(props) {
- super(props);
- this.handleClick = this.handleClick.bind(this);
- }
-
- handleClick(){
- this.props.actions.toggleDone(this.props.todo.id);
- this.props.actions.save();
- }
-
- render(){
- var style = {};
- if( this.props.todo.completed ) style.textDecoration = 'line-through';
- return - { this.props.todo.title }
;
- }
-}
-
-
-/**
- * The Todo item
- **/
-class AddTodoForm extends React.Component{
-
- constructor(props) {
- super(props);
-
- this.state = {
- title: ''
- }
- this.handleChange = this.handleChange.bind(this);
- this.handleSubmit = this.handleSubmit.bind(this);
- }
-
- handleSubmit(){
- this.props.actions.addTodo( this.state.title );
- this.props.actions.save();
- this.setState({ title: '' });
- }
-
- handleChange( newTitle ){
- this.setState({ title: newTitle });
- }
-
- render(){
- return
- }
-}
-
-class AddTodoForm_View extends React.Component{
-
- constructor(props) {
- super(props);
- this.handleChange = this.handleChange.bind(this);
- this.handleSubmit = this.handleSubmit.bind(this);
- }
-
- handleChange( event ){
- this.props.handleChange( event.target.value );
- }
-
- handleSubmit( event ){
- event.preventDefault();
- this.props.handleSubmit();
- }
-
- render(){
- return (
-
- );
- }
-}
-
-/*
-Todos.propTypes = {
- todos: React.PropTypes.array.isRequired
-};
-*/
-
-/**
- * Export our component
- *
- * We also integrate our global store, using connect()
- **/
-
-const mapStateToProps = (state, ownProps) => {
- return state;
-}
-
-const mapDispatchToProps = (dispatch) => {
- return {
- actions: bindActionCreators(actions, dispatch)
- }
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(Todos)
\ No newline at end of file
diff --git a/src/todos/reducer.js b/src/todos/reducer.js
deleted file mode 100755
index d9d3330f..00000000
--- a/src/todos/reducer.js
+++ /dev/null
@@ -1,38 +0,0 @@
-
-import * as actions from '../actions'
-
-export default function todos(todos = [], action){
- switch( action.type ){
-
- case actions.LOAD:
- if( localStorage.getItem( 'todos' ) ){
- return JSON.parse( localStorage.getItem( 'todos' ) );
- }
- return [];
-
- case actions.SAVE:
- localStorage.setItem( 'todos', JSON.stringify(todos) );
- return todos;
-
- case actions.ADD_TODO:
- return Object.assign([], todos, [...todos, { id: action.id, title: action.title, completed: false }] )
-
- case actions.TOGGLE_DONE:
- return Object.assign([], todos,
- todos.map(todo => {
- if( todo.id === action.id ){
- return Object.assign({}, todo, {
- completed: !todo.completed
- })
- }
- return todo
- })
- );
-
- default:
- return todos
- }
-}
-
-
-