2016-08-07 00:58:36 +02:00
|
|
|
import Immutable from "immutable";
|
|
|
|
|
|
|
|
import {
|
|
|
|
PUSH_PLAYLIST,
|
|
|
|
CHANGE_TRACK,
|
|
|
|
PLAY_PAUSE,
|
|
|
|
TOGGLE_RANDOM,
|
|
|
|
TOGGLE_REPEAT,
|
2016-08-08 12:22:35 +02:00
|
|
|
TOGGLE_MUTE,
|
|
|
|
INVALIDATE_STORE } from "../actions";
|
2016-08-07 00:58:36 +02:00
|
|
|
import { createReducer } from "../utils";
|
|
|
|
import { stateRecord } from "../models/webplayer";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initial state
|
|
|
|
*/
|
|
|
|
|
|
|
|
var initialState = new stateRecord();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reducers
|
|
|
|
*/
|
|
|
|
|
|
|
|
export default createReducer(initialState, {
|
|
|
|
[PLAY_PAUSE]: (state, payload) => {
|
|
|
|
return state.set("isPlaying", payload.isPlaying);
|
|
|
|
},
|
|
|
|
[CHANGE_TRACK]: (state, payload) => {
|
|
|
|
return state.set("currentIndex", payload.index);
|
|
|
|
},
|
|
|
|
[PUSH_PLAYLIST]: (state, payload) => {
|
|
|
|
return (
|
|
|
|
state
|
|
|
|
.set("playlist", new Immutable.List(payload.playlist))
|
|
|
|
.setIn(["entities", "artists"], new Immutable.Map(payload.artists))
|
|
|
|
.setIn(["entities", "albums"], new Immutable.Map(payload.albums))
|
|
|
|
.setIn(["entities", "tracks"], new Immutable.Map(payload.tracks))
|
|
|
|
.set("currentIndex", 0)
|
|
|
|
.set("isPlaying", true)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
[TOGGLE_RANDOM]: (state) => {
|
|
|
|
return state.set("isRandom", !state.get("isRandom"));
|
|
|
|
},
|
|
|
|
[TOGGLE_REPEAT]: (state) => {
|
|
|
|
return state.set("isRepeat", !state.get("isRepeat"));
|
|
|
|
},
|
|
|
|
[TOGGLE_MUTE]: (state) => {
|
|
|
|
return state.set("isMute", !state.get("isMute"));
|
|
|
|
},
|
2016-08-08 12:22:35 +02:00
|
|
|
[INVALIDATE_STORE]: () => {
|
|
|
|
return new stateRecord();
|
|
|
|
}
|
2016-08-07 00:58:36 +02:00
|
|
|
});
|