playlistQueue.js 714 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { Map } from "immutable";
  2. import {
  3. SELECT_PLAYLIST,
  4. DESELECT_PLAYLISTS,
  5. ADD_SONG,
  6. } from "actions/playlistQueue";
  7. const initialState = Map({
  8. playlistSelected: null,
  9. addedSongId: null,
  10. });
  11. const actionsMap = {
  12. [SELECT_PLAYLIST]: (state, action) => {
  13. return state.merge({
  14. playlistSelected: action.playlistId,
  15. });
  16. },
  17. [DESELECT_PLAYLISTS]: (state, action) => {
  18. return state.merge({
  19. playlistSelected: null,
  20. addedSongId: null,
  21. });
  22. },
  23. [ADD_SONG]: (state, action) => {
  24. return state.merge({
  25. addedSongId: action.songId,
  26. });
  27. },
  28. };
  29. export default function reducer(state = initialState, action = {}) {
  30. const fn = actionsMap[action.type];
  31. return fn ? fn(state, action) : state;
  32. }