stationInfo.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. import { Map, List, fromJS } from "immutable";
  2. const JOIN = "STATION_INFO::JOIN";
  3. const LEAVE = "STATION_INFO::LEAVE";
  4. const USER_LIST_UPDATE = "STATION_INFO::USER_LIST_UPDATE";
  5. const USER_COUNT_UPDATE = "STATION_INFO::USER_COUNT_UPDATE";
  6. const NAME_UPDATE = "STATION_INFO::NAME_UPDATE";
  7. const DISPLAY_NAME_UPDATE = "STATION_INFO::DISPLAY_NAME_UPDATE";
  8. const DESCRIPTION_UPDATE = "STATION_INFO::DESCRIPTION_UPDATE";
  9. const MODE_UPDATE = "STATION_INFO::MODE_UPDATE";
  10. const QUEUE_INDEX = "STATION_INFO::QUEUE_INDEX";
  11. const QUEUE_UPDATE = "STATION_INFO::QUEUE_UPDATE";
  12. const PAUSE = "STATION_INFO::PAUSE";
  13. const RESUME = "STATION_INFO::RESUME";
  14. const SELECT_PLAYLIST = "STATION_INFO::SELECT_PLAYLIST";
  15. const SELECT_PLAYLIST_QUEUE = "STATION_INFO::SELECT_PLAYLIST_QUEUE";
  16. function joinStation(station) {
  17. return {
  18. type: JOIN,
  19. station,
  20. }
  21. }
  22. function leaveStation() {
  23. return {
  24. type: LEAVE,
  25. }
  26. }
  27. function userListUpdate(userList) {
  28. return {
  29. type: USER_LIST_UPDATE,
  30. userList,
  31. }
  32. }
  33. function userCountUpdate(userCount) {
  34. return {
  35. type: USER_COUNT_UPDATE,
  36. userCount,
  37. }
  38. }
  39. function nameUpdate(name) {
  40. return {
  41. type: NAME_UPDATE,
  42. name,
  43. }
  44. }
  45. function displayNameUpdate(displayName) {
  46. return {
  47. type: DISPLAY_NAME_UPDATE,
  48. displayName,
  49. }
  50. }
  51. function descriptionUpdate(description) {
  52. return {
  53. type: DESCRIPTION_UPDATE,
  54. description,
  55. }
  56. }
  57. function modeUpdate(mode) {
  58. return {
  59. type: MODE_UPDATE,
  60. mode,
  61. }
  62. }
  63. function queueIndex(songList) {
  64. return {
  65. type: QUEUE_INDEX,
  66. songList,
  67. }
  68. }
  69. function queueUpdate(songList) {
  70. return {
  71. type: QUEUE_UPDATE,
  72. songList,
  73. }
  74. }
  75. function pause() {
  76. return {
  77. type: PAUSE,
  78. }
  79. }
  80. function resume() {
  81. return {
  82. type: RESUME,
  83. }
  84. }
  85. function selectPlaylist(playlistId) {
  86. return {
  87. type: SELECT_PLAYLIST,
  88. playlistId,
  89. }
  90. }
  91. function selectPlaylistQueue(playlistId) {
  92. return {
  93. type: SELECT_PLAYLIST_QUEUE,
  94. playlistId,
  95. }
  96. }
  97. const initialState = Map({
  98. "stationId": "",
  99. "name": "",
  100. "displayName": "",
  101. "description": "",
  102. "privacy": "private",
  103. "type": "community",
  104. "ownerId": "",
  105. "paused": true,
  106. "mode": "",
  107. "userList": List([]),
  108. "userCount": 0,
  109. "songList": List([]),
  110. "privatePlaylist": "",
  111. "privatePlaylistQueue": "",
  112. });
  113. function reducer(state = initialState, action) {
  114. let name, displayName, description, mode, userList, userCount, songList;
  115. function getModeTemp(partyEnabled, queueLocked) {
  116. // If party enabled
  117. // If queue locked
  118. // Mode is DJ
  119. // If queue not locked
  120. // Mode party
  121. // If party not enabled
  122. // Mode is normal
  123. if (partyEnabled) {
  124. if (queueLocked) return "dj";
  125. else return "party";
  126. } else return "normal";
  127. }
  128. switch (action.type) {
  129. case JOIN:
  130. const { stationId, privacy, type, ownerId, paused } = action.station;
  131. name = action.station.name;
  132. displayName = action.station.displayName;
  133. description = action.station.description;
  134. userCount = action.station.userCount;
  135. return state.merge({
  136. stationId,
  137. name: action.station.name,
  138. displayName,
  139. description,
  140. privacy,
  141. type,
  142. ownerId,
  143. paused,
  144. mode: (getModeTemp(action.station.partyMode, action.station.locked)),
  145. userList: fromJS(action.station.userList),
  146. userCount,
  147. songList: fromJS(action.station.songList),
  148. privatePlaylist: action.station.privatePlaylist,
  149. });
  150. case LEAVE:
  151. return initialState;
  152. case USER_LIST_UPDATE:
  153. return state.merge({
  154. userList: fromJS(action.userList),
  155. });
  156. case USER_COUNT_UPDATE:
  157. return state.merge({
  158. userCount: action.userCount,
  159. });
  160. case NAME_UPDATE:
  161. return state.merge({
  162. name: action.name,
  163. });
  164. case DISPLAY_NAME_UPDATE:
  165. return state.merge({
  166. displayName: action.displayName,
  167. });
  168. case DESCRIPTION_UPDATE:
  169. return state.merge({
  170. description: action.description,
  171. });
  172. case MODE_UPDATE:
  173. return state.merge({
  174. mode: action.mode,
  175. });
  176. case QUEUE_INDEX:
  177. return state.merge({
  178. songList: fromJS(action.songList),
  179. });
  180. case QUEUE_UPDATE:
  181. return state.merge({
  182. songList: fromJS(action.songList),
  183. });
  184. case PAUSE:
  185. return state.merge({
  186. paused: true,
  187. });
  188. case RESUME:
  189. return state.merge({
  190. paused: false,
  191. });
  192. case SELECT_PLAYLIST:
  193. return state.merge({
  194. privatePlaylist: action.playlistId,
  195. });
  196. case SELECT_PLAYLIST_QUEUE:
  197. return state.merge({
  198. privatePlaylistQueue: action.playlistId,
  199. });
  200. }
  201. return state;
  202. }
  203. const actionCreators = {
  204. joinStation,
  205. leaveStation,
  206. userListUpdate,
  207. userCountUpdate,
  208. nameUpdate,
  209. displayNameUpdate,
  210. descriptionUpdate,
  211. modeUpdate,
  212. queueIndex,
  213. queueUpdate,
  214. pause,
  215. resume,
  216. selectPlaylist,
  217. selectPlaylistQueue,
  218. };
  219. const actionTypes = {
  220. JOIN_STATION: JOIN,
  221. LEAVE_STATION: LEAVE,
  222. USER_LIST_UPDATE,
  223. USER_COUNT_UPDATE,
  224. NAME_UPDATE,
  225. DISPLAY_NAME_UPDATE,
  226. DESCRIPTION_UPDATE,
  227. MODE_UPDATE,
  228. QUEUE_INDEX,
  229. QUEUE_UPDATE,
  230. PAUSE,
  231. RESUME,
  232. SELECT_PLAYLIST,
  233. SELECT_PLAYLIST_QUEUE,
  234. };
  235. export {
  236. actionCreators,
  237. actionTypes,
  238. };
  239. export default reducer;