station.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. ownerId: "",
  21. });
  22. const actionsMap = {
  23. [INITIALIZE_STATION]: (state, action) => {
  24. return state.merge({
  25. id: action.station.stationId,
  26. name: action.station.name,
  27. displayName: action.station.displayName,
  28. description: action.station.description,
  29. paused: action.station.paused,
  30. pausedAt: action.station.pausedAt,
  31. privacy: action.station.privacy,
  32. type: action.station.type,
  33. locked: action.station.locked,
  34. partyMode: action.station.partyMode,
  35. privatePlaylist: action.station.privatePlaylist,
  36. ownerId: action.station.owner,
  37. });
  38. },
  39. [PAUSE_STATION]: (state, action) => {
  40. return state.merge({
  41. paused: true,
  42. pausedAt: action.pausedAt,
  43. });
  44. },
  45. [RESUME_STATION]: (state, action) => {
  46. return state.merge({
  47. paused: false,
  48. });
  49. },
  50. [LEAVE_STATION]: (state, action) => {
  51. return initialState;
  52. },
  53. };
  54. export default function reducer(state = initialState, action = {}) {
  55. const fn = actionsMap[action.type];
  56. return fn ? fn(state, action) : state;
  57. }