123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- /* eslint no-param-reassign: 0 */
- /* eslint-disable import/no-cycle */
- import admin from "@/api/admin/index";
- const state = {};
- const getters = {};
- const actions = {};
- const mutations = {};
- const modules = {
- hiddenSongs: {
- namespaced: true,
- state: {
- songs: []
- },
- getters: {},
- actions: {
- resetSongs: ({ commit }) => commit("resetSongs"),
- addSong: ({ commit }, song) => commit("addSong", song),
- removeSong: ({ commit }, songId) => commit("removeSong", songId),
- updateSong: ({ commit }, updatedSong) =>
- commit("updateSong", updatedSong)
- },
- mutations: {
- resetSongs(state) {
- state.songs = [];
- },
- addSong(state, song) {
- if (!state.songs.find(s => s._id === song._id))
- state.songs.push(song);
- },
- removeSong(state, songId) {
- state.songs = state.songs.filter(song => song._id !== songId);
- },
- updateSong(state, updatedSong) {
- state.songs.forEach((song, index) => {
- if (song._id === updatedSong._id)
- state.songs[index] = updatedSong;
- });
- }
- }
- },
- unverifiedSongs: {
- namespaced: true,
- state: {
- songs: []
- },
- getters: {},
- actions: {
- resetSongs: ({ commit }) => commit("resetSongs"),
- addSong: ({ commit }, song) => commit("addSong", song),
- removeSong: ({ commit }, songId) => commit("removeSong", songId),
- updateSong: ({ commit }, updatedSong) =>
- commit("updateSong", updatedSong)
- },
- mutations: {
- resetSongs(state) {
- state.songs = [];
- },
- addSong(state, song) {
- if (!state.songs.find(s => s._id === song._id))
- state.songs.push(song);
- },
- removeSong(state, songId) {
- state.songs = state.songs.filter(song => song._id !== songId);
- },
- updateSong(state, updatedSong) {
- state.songs.forEach((song, index) => {
- if (song._id === updatedSong._id)
- state.songs[index] = updatedSong;
- });
- }
- }
- },
- verifiedSongs: {
- namespaced: true,
- state: {
- songs: []
- },
- getters: {},
- actions: {
- resetSongs: ({ commit }) => commit("resetSongs"),
- addSong: ({ commit }, song) => commit("addSong", song),
- removeSong: ({ commit }, songId) => commit("removeSong", songId),
- updateSong: ({ commit }, updatedSong) =>
- commit("updateSong", updatedSong)
- },
- mutations: {
- resetSongs(state) {
- state.songs = [];
- },
- addSong(state, song) {
- if (!state.songs.find(s => s._id === song._id))
- state.songs.push(song);
- },
- removeSong(state, songId) {
- state.songs = state.songs.filter(song => song._id !== songId);
- },
- updateSong(state, updatedSong) {
- state.songs.forEach((song, index) => {
- if (song._id === updatedSong._id)
- state.songs[index] = updatedSong;
- });
- }
- }
- },
- stations: {
- namespaced: true,
- state: {
- stations: []
- },
- getters: {},
- actions: {
- loadStations: ({ commit }, stations) =>
- commit("loadStations", stations),
- stationRemoved: ({ commit }, stationId) =>
- commit("stationRemoved", stationId),
- stationAdded: ({ commit }, station) =>
- commit("stationAdded", station)
- },
- mutations: {
- loadStations(state, stations) {
- state.stations = stations;
- },
- stationAdded(state, station) {
- state.stations.push(station);
- },
- stationRemoved(state, stationId) {
- state.stations = state.stations.filter(
- station => station._id !== stationId
- );
- }
- }
- },
- reports: {
- namespaced: true,
- state: {
- reports: []
- },
- getters: {},
- actions: {
- /* eslint-disable-next-line no-unused-vars */
- resolveReport: ({ commit }, reportId) =>
- new Promise((resolve, reject) =>
- admin.reports
- .resolve(reportId)
- .then(res => resolve(res))
- .catch(err => reject(new Error(err.message)))
- ),
- indexReports({ commit }, reports) {
- commit("indexReports", reports);
- }
- },
- mutations: {}
- },
- users: {
- namespaced: true,
- state: {},
- getters: {},
- actions: {},
- mutations: {}
- },
- news: {
- namespaced: true,
- state: {
- news: []
- },
- getters: {},
- actions: {
- setNews: ({ commit }, news) => commit("setNews", news),
- addNews: ({ commit }, news) => commit("addNews", news),
- removeNews: ({ commit }, newsId) => commit("removeNews", newsId),
- updateNews: ({ commit }, updatedNews) =>
- commit("updateNews", updatedNews)
- },
- mutations: {
- setNews(state, news) {
- state.news = news;
- },
- addNews(state, news) {
- state.news.push(news);
- },
- removeNews(state, newsId) {
- state.news = state.news.filter(news => news._id !== newsId);
- },
- updateNews(state, updatedNews) {
- state.news.forEach((news, index) => {
- if (news._id === updatedNews._id)
- this.set(state.news, index, updatedNews);
- });
- }
- }
- },
- playlists: {
- namespaced: true,
- state: {
- playlists: []
- },
- getters: {},
- actions: {
- setPlaylists: ({ commit }, playlists) =>
- commit("setPlaylists", playlists),
- addPlaylist: ({ commit }, playlist) =>
- commit("addPlaylist", playlist),
- removePlaylist: ({ commit }, playlistId) =>
- commit("removePlaylist", playlistId),
- addPlaylistSong: ({ commit }, { playlistId, song }) =>
- commit("addPlaylistSong", { playlistId, song }),
- removePlaylistSong: ({ commit }, { playlistId, youtubeId }) =>
- commit("removePlaylistSong", { playlistId, youtubeId }),
- updatePlaylistDisplayName: (
- { commit },
- { playlistId, displayName }
- ) =>
- commit("updatePlaylistDisplayName", {
- playlistId,
- displayName
- }),
- updatePlaylistPrivacy: ({ commit }, { playlistId, privacy }) =>
- commit("updatePlaylistPrivacy", { playlistId, privacy })
- },
- mutations: {
- setPlaylists(state, playlists) {
- state.playlists = playlists;
- },
- addPlaylist(state, playlist) {
- state.playlists.unshift(playlist);
- },
- removePlaylist(state, playlistId) {
- state.playlists = state.playlists.filter(
- playlist => playlist._id !== playlistId
- );
- },
- addPlaylistSong(state, { playlistId, song }) {
- state.playlists[
- state.playlists.findIndex(
- playlist => playlist._id === playlistId
- )
- ].songs.push(song);
- },
- removePlaylistSong(state, { playlistId, youtubeId }) {
- const playlistIndex = state.playlists.findIndex(
- playlist => playlist._id === playlistId
- );
- state.playlists[playlistIndex].songs.splice(
- state.playlists[playlistIndex].songs.findIndex(
- song => song.youtubeId === youtubeId
- ),
- 1
- );
- },
- updatePlaylistDisplayName(state, { playlistId, displayName }) {
- state.playlists[
- state.playlists.findIndex(
- playlist => playlist._id === playlistId
- )
- ].displayName = displayName;
- },
- updatePlaylistPrivacy(state, { playlistId, privacy }) {
- state.playlists[
- state.playlists.findIndex(
- playlist => playlist._id === playlistId
- )
- ].privacy = privacy;
- }
- }
- }
- };
- export default {
- namespaced: true,
- state,
- getters,
- actions,
- mutations,
- modules
- };
|