admin.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /* eslint no-param-reassign: 0 */
  2. /* eslint-disable import/no-cycle */
  3. import admin from "@/api/admin/index";
  4. const state = {};
  5. const getters = {};
  6. const actions = {};
  7. const mutations = {};
  8. const modules = {
  9. hiddenSongs: {
  10. namespaced: true,
  11. state: {
  12. songs: []
  13. },
  14. getters: {},
  15. actions: {
  16. resetSongs: ({ commit }) => commit("resetSongs"),
  17. addSong: ({ commit }, song) => commit("addSong", song),
  18. removeSong: ({ commit }, songId) => commit("removeSong", songId),
  19. updateSong: ({ commit }, updatedSong) =>
  20. commit("updateSong", updatedSong)
  21. },
  22. mutations: {
  23. resetSongs(state) {
  24. state.songs = [];
  25. },
  26. addSong(state, song) {
  27. if (!state.songs.find(s => s._id === song._id))
  28. state.songs.push(song);
  29. },
  30. removeSong(state, songId) {
  31. state.songs = state.songs.filter(song => song._id !== songId);
  32. },
  33. updateSong(state, updatedSong) {
  34. state.songs.forEach((song, index) => {
  35. if (song._id === updatedSong._id)
  36. state.songs[index] = updatedSong;
  37. });
  38. }
  39. }
  40. },
  41. unverifiedSongs: {
  42. namespaced: true,
  43. state: {
  44. songs: []
  45. },
  46. getters: {},
  47. actions: {
  48. resetSongs: ({ commit }) => commit("resetSongs"),
  49. addSong: ({ commit }, song) => commit("addSong", song),
  50. removeSong: ({ commit }, songId) => commit("removeSong", songId),
  51. updateSong: ({ commit }, updatedSong) =>
  52. commit("updateSong", updatedSong)
  53. },
  54. mutations: {
  55. resetSongs(state) {
  56. state.songs = [];
  57. },
  58. addSong(state, song) {
  59. if (!state.songs.find(s => s._id === song._id))
  60. state.songs.push(song);
  61. },
  62. removeSong(state, songId) {
  63. state.songs = state.songs.filter(song => song._id !== songId);
  64. },
  65. updateSong(state, updatedSong) {
  66. state.songs.forEach((song, index) => {
  67. if (song._id === updatedSong._id)
  68. state.songs[index] = updatedSong;
  69. });
  70. }
  71. }
  72. },
  73. verifiedSongs: {
  74. namespaced: true,
  75. state: {
  76. songs: []
  77. },
  78. getters: {},
  79. actions: {
  80. resetSongs: ({ commit }) => commit("resetSongs"),
  81. addSong: ({ commit }, song) => commit("addSong", song),
  82. removeSong: ({ commit }, songId) => commit("removeSong", songId),
  83. updateSong: ({ commit }, updatedSong) =>
  84. commit("updateSong", updatedSong)
  85. },
  86. mutations: {
  87. resetSongs(state) {
  88. state.songs = [];
  89. },
  90. addSong(state, song) {
  91. if (!state.songs.find(s => s._id === song._id))
  92. state.songs.push(song);
  93. },
  94. removeSong(state, songId) {
  95. state.songs = state.songs.filter(song => song._id !== songId);
  96. },
  97. updateSong(state, updatedSong) {
  98. state.songs.forEach((song, index) => {
  99. if (song._id === updatedSong._id)
  100. state.songs[index] = updatedSong;
  101. });
  102. }
  103. }
  104. },
  105. stations: {
  106. namespaced: true,
  107. state: {
  108. stations: []
  109. },
  110. getters: {},
  111. actions: {
  112. loadStations: ({ commit }, stations) =>
  113. commit("loadStations", stations),
  114. stationRemoved: ({ commit }, stationId) =>
  115. commit("stationRemoved", stationId),
  116. stationAdded: ({ commit }, station) =>
  117. commit("stationAdded", station)
  118. },
  119. mutations: {
  120. loadStations(state, stations) {
  121. state.stations = stations;
  122. },
  123. stationAdded(state, station) {
  124. state.stations.push(station);
  125. },
  126. stationRemoved(state, stationId) {
  127. state.stations = state.stations.filter(
  128. station => station._id !== stationId
  129. );
  130. }
  131. }
  132. },
  133. reports: {
  134. namespaced: true,
  135. state: {
  136. reports: []
  137. },
  138. getters: {},
  139. actions: {
  140. /* eslint-disable-next-line no-unused-vars */
  141. resolveReport: ({ commit }, reportId) =>
  142. new Promise((resolve, reject) =>
  143. admin.reports
  144. .resolve(reportId)
  145. .then(res => resolve(res))
  146. .catch(err => reject(new Error(err.message)))
  147. ),
  148. indexReports({ commit }, reports) {
  149. commit("indexReports", reports);
  150. }
  151. },
  152. mutations: {}
  153. },
  154. users: {
  155. namespaced: true,
  156. state: {},
  157. getters: {},
  158. actions: {},
  159. mutations: {}
  160. },
  161. news: {
  162. namespaced: true,
  163. state: {
  164. news: []
  165. },
  166. getters: {},
  167. actions: {
  168. setNews: ({ commit }, news) => commit("setNews", news),
  169. addNews: ({ commit }, news) => commit("addNews", news),
  170. removeNews: ({ commit }, newsId) => commit("removeNews", newsId),
  171. updateNews: ({ commit }, updatedNews) =>
  172. commit("updateNews", updatedNews)
  173. },
  174. mutations: {
  175. setNews(state, news) {
  176. state.news = news;
  177. },
  178. addNews(state, news) {
  179. state.news.push(news);
  180. },
  181. removeNews(state, newsId) {
  182. state.news = state.news.filter(news => news._id !== newsId);
  183. },
  184. updateNews(state, updatedNews) {
  185. state.news.forEach((news, index) => {
  186. if (news._id === updatedNews._id)
  187. this.set(state.news, index, updatedNews);
  188. });
  189. }
  190. }
  191. },
  192. playlists: {
  193. namespaced: true,
  194. state: {
  195. playlists: []
  196. },
  197. getters: {},
  198. actions: {
  199. setPlaylists: ({ commit }, playlists) =>
  200. commit("setPlaylists", playlists),
  201. addPlaylist: ({ commit }, playlist) =>
  202. commit("addPlaylist", playlist),
  203. removePlaylist: ({ commit }, playlistId) =>
  204. commit("removePlaylist", playlistId),
  205. addPlaylistSong: ({ commit }, { playlistId, song }) =>
  206. commit("addPlaylistSong", { playlistId, song }),
  207. removePlaylistSong: ({ commit }, { playlistId, youtubeId }) =>
  208. commit("removePlaylistSong", { playlistId, youtubeId }),
  209. updatePlaylistDisplayName: (
  210. { commit },
  211. { playlistId, displayName }
  212. ) =>
  213. commit("updatePlaylistDisplayName", {
  214. playlistId,
  215. displayName
  216. }),
  217. updatePlaylistPrivacy: ({ commit }, { playlistId, privacy }) =>
  218. commit("updatePlaylistPrivacy", { playlistId, privacy })
  219. },
  220. mutations: {
  221. setPlaylists(state, playlists) {
  222. state.playlists = playlists;
  223. },
  224. addPlaylist(state, playlist) {
  225. state.playlists.unshift(playlist);
  226. },
  227. removePlaylist(state, playlistId) {
  228. state.playlists = state.playlists.filter(
  229. playlist => playlist._id !== playlistId
  230. );
  231. },
  232. addPlaylistSong(state, { playlistId, song }) {
  233. state.playlists[
  234. state.playlists.findIndex(
  235. playlist => playlist._id === playlistId
  236. )
  237. ].songs.push(song);
  238. },
  239. removePlaylistSong(state, { playlistId, youtubeId }) {
  240. const playlistIndex = state.playlists.findIndex(
  241. playlist => playlist._id === playlistId
  242. );
  243. state.playlists[playlistIndex].songs.splice(
  244. state.playlists[playlistIndex].songs.findIndex(
  245. song => song.youtubeId === youtubeId
  246. ),
  247. 1
  248. );
  249. },
  250. updatePlaylistDisplayName(state, { playlistId, displayName }) {
  251. state.playlists[
  252. state.playlists.findIndex(
  253. playlist => playlist._id === playlistId
  254. )
  255. ].displayName = displayName;
  256. },
  257. updatePlaylistPrivacy(state, { playlistId, privacy }) {
  258. state.playlists[
  259. state.playlists.findIndex(
  260. playlist => playlist._id === playlistId
  261. )
  262. ].privacy = privacy;
  263. }
  264. }
  265. }
  266. };
  267. export default {
  268. namespaced: true,
  269. state,
  270. getters,
  271. actions,
  272. mutations,
  273. modules
  274. };