station.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* eslint no-param-reassign: 0 */
  2. const state = {
  3. station: {},
  4. partyPlaylists: [],
  5. editing: {},
  6. userCount: 0,
  7. users: {
  8. loggedIn: [],
  9. loggedOut: []
  10. },
  11. currentSong: {},
  12. nextSong: null,
  13. songsList: [],
  14. stationPaused: true,
  15. localPaused: false,
  16. noSong: true,
  17. includedPlaylists: [],
  18. excludedPlaylists: []
  19. };
  20. const getters = {};
  21. const actions = {
  22. joinStation: ({ commit }, station) => {
  23. commit("joinStation", station);
  24. },
  25. leaveStation: ({ commit }, station) => {
  26. commit("leaveStation", station);
  27. },
  28. editStation: ({ commit }, station) => {
  29. commit("editStation", station);
  30. },
  31. updateUserCount: ({ commit }, userCount) => {
  32. commit("updateUserCount", userCount);
  33. },
  34. updateUsers: ({ commit }, users) => {
  35. commit("updateUsers", users);
  36. },
  37. updateCurrentSong: ({ commit }, currentSong) => {
  38. commit("updateCurrentSong", currentSong);
  39. },
  40. updateNextSong: ({ commit }, nextSong) => {
  41. commit("updateNextSong", nextSong);
  42. },
  43. updateSongsList: ({ commit }, songsList) => {
  44. commit("updateSongsList", songsList);
  45. },
  46. repositionSongInList: ({ commit }, song) => {
  47. commit("repositionSongInList", song);
  48. },
  49. updateStationPaused: ({ commit }, stationPaused) => {
  50. commit("updateStationPaused", stationPaused);
  51. },
  52. updateLocalPaused: ({ commit }, localPaused) => {
  53. commit("updateLocalPaused", localPaused);
  54. },
  55. updateNoSong: ({ commit }, noSong) => {
  56. commit("updateNoSong", noSong);
  57. },
  58. updatePartyPlaylists: ({ commit }, playlists) => {
  59. commit("updatePartyPlaylists", playlists);
  60. },
  61. updateIfStationIsFavorited: ({ commit }, { isFavorited }) => {
  62. commit("updateIfStationIsFavorited", isFavorited);
  63. },
  64. setIncludedPlaylists: ({ commit }, includedPlaylists) => {
  65. commit("setIncludedPlaylists", includedPlaylists);
  66. },
  67. setExcludedPlaylists: ({ commit }, excludedPlaylists) => {
  68. commit("setExcludedPlaylists", excludedPlaylists);
  69. },
  70. updateCurrentSongRatings: ({ commit }, songRatings) => {
  71. commit("updateCurrentSongRatings", songRatings);
  72. },
  73. updateOwnCurrentSongRatings: ({ commit }, ownSongRatings) => {
  74. commit("updateOwnCurrentSongRatings", ownSongRatings);
  75. },
  76. updateCurrentSongSkipVotes: (
  77. { commit },
  78. { skipVotes, skipVotesCurrent }
  79. ) => {
  80. commit("updateCurrentSongSkipVotes", { skipVotes, skipVotesCurrent });
  81. }
  82. };
  83. const mutations = {
  84. joinStation(state, station) {
  85. state.station = { ...station };
  86. },
  87. leaveStation(state) {
  88. state.station = {};
  89. state.partyPlaylists = [];
  90. state.editing = {};
  91. state.userCount = 0;
  92. state.users = {
  93. loggedIn: [],
  94. loggedOut: []
  95. };
  96. state.currentSong = {};
  97. state.nextSong = null;
  98. state.songsList = [];
  99. state.stationPaused = true;
  100. state.localPaused = false;
  101. state.noSong = true;
  102. state.includedPlaylists = [];
  103. state.excludedPlaylists = [];
  104. },
  105. editStation(state, station) {
  106. state.editing = { ...station };
  107. },
  108. updateUserCount(state, userCount) {
  109. state.userCount = userCount;
  110. },
  111. updateUsers(state, users) {
  112. state.users = users;
  113. },
  114. updateCurrentSong(state, currentSong) {
  115. state.currentSong = currentSong;
  116. },
  117. updateNextSong(state, nextSong) {
  118. state.nextSong = nextSong;
  119. },
  120. updateSongsList(state, songsList) {
  121. state.songsList = songsList;
  122. },
  123. repositionSongInList(state, song) {
  124. if (
  125. state.songsList[song.newIndex] &&
  126. state.songsList[song.newIndex].youtubeId === song.youtubeId
  127. )
  128. return;
  129. const { songsList } = state;
  130. songsList.splice(
  131. song.newIndex,
  132. 0,
  133. songsList.splice(song.oldIndex, 1)[0]
  134. );
  135. state.songsList = songsList;
  136. },
  137. updateStationPaused(state, stationPaused) {
  138. state.stationPaused = stationPaused;
  139. },
  140. updateLocalPaused(state, localPaused) {
  141. state.localPaused = localPaused;
  142. },
  143. updateNoSong(state, noSong) {
  144. state.noSong = noSong;
  145. },
  146. updatePartyPlaylists(state, playlists) {
  147. state.partyPlaylists = playlists;
  148. },
  149. updateIfStationIsFavorited(state, isFavorited) {
  150. state.station.isFavorited = isFavorited;
  151. },
  152. setIncludedPlaylists(state, includedPlaylists) {
  153. state.includedPlaylists = JSON.parse(JSON.stringify(includedPlaylists));
  154. },
  155. setExcludedPlaylists(state, excludedPlaylists) {
  156. state.excludedPlaylists = JSON.parse(JSON.stringify(excludedPlaylists));
  157. },
  158. updateCurrentSongRatings(state, songRatings) {
  159. state.currentSong.likes = songRatings.likes;
  160. state.currentSong.dislikes = songRatings.dislikes;
  161. },
  162. updateOwnCurrentSongRatings(state, ownSongRatings) {
  163. state.currentSong.liked = ownSongRatings.liked;
  164. state.currentSong.disliked = ownSongRatings.disliked;
  165. },
  166. updateCurrentSongSkipVotes(state, { skipVotes, skipVotesCurrent }) {
  167. state.currentSong.skipVotes = skipVotes;
  168. if (skipVotesCurrent !== null)
  169. state.currentSong.skipVotesCurrent = skipVotesCurrent;
  170. }
  171. };
  172. export default {
  173. namespaced: true,
  174. state,
  175. getters,
  176. actions,
  177. mutations
  178. };