station.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Map } from "immutable";
  2. import {
  3. INITIALIZE_STATION,
  4. PAUSE_STATION,
  5. RESUME_STATION,
  6. LEAVE_STATION,
  7. } from "actions/station";
  8. const initialState = Map({
  9. id: "",
  10. name: "",
  11. displayName: "",
  12. description: "",
  13. paused: true,
  14. pausedAt: 0,
  15. privacy: "public",
  16. type: "official",
  17. locked: false,
  18. partyMode: false,
  19. privatePlaylist: "",
  20. });
  21. const actionsMap = {
  22. [INITIALIZE_STATION]: (state, action) => {
  23. return state.merge({
  24. id: action.station.stationId,
  25. name: action.station.name,
  26. displayName: action.station.displayName,
  27. description: action.station.description,
  28. paused: action.station.paused,
  29. pausedAt: action.station.pausedAt,
  30. privacy: action.station.privacy,
  31. type: action.station.type,
  32. locked: action.station.locked,
  33. partyMode: action.station.partyMode,
  34. privatePlaylist: action.station.privatePlaylist,
  35. });
  36. },
  37. [PAUSE_STATION]: (state, action) => {
  38. return state.merge({
  39. paused: true,
  40. pausedAt: action.pausedAt,
  41. });
  42. },
  43. [RESUME_STATION]: (state, action) => {
  44. return state.merge({
  45. paused: false,
  46. });
  47. },
  48. [LEAVE_STATION]: (state, action) => {
  49. return initialState;
  50. },
  51. };
  52. export default function reducer(state = initialState, action = {}) {
  53. const fn = actionsMap[action.type];
  54. return fn ? fn(state, action) : state;
  55. }