diff --git a/src/vuex/actions/TopSellers.js b/src/vuex/actions/TopSellers.js new file mode 100644 index 0000000..a2a77f4 --- /dev/null +++ b/src/vuex/actions/TopSellers.js @@ -0,0 +1,46 @@ +import axios from './axios'; + +function FetchTopArtists ({commit}) { + return new Promise((resolve, reject) => { + axios.get('/top/artists') + .then(resp => { + commit('SET_TOP_ARTISTS', resp.data); + resolve(resp.data); + }) + .catch(err => { + reject(err); + }); + }); +} + +function FetchTopSongs ({commit}) { + return new Promise((resolve, reject) => { + axios.get('/top/songs') + .then(resp => { + commit('SET_TOP_SONGS', resp.data); + resolve(resp.data); + }) + .catch(err => { + reject(err); + }); + }); +} + +function FetchTopAlbums ({commit}) { + return new Promise((resolve, reject) => { + axios.get('/top/albums') + .then(resp => { + commit('SET_TOP_ALBUMS', resp.data); + resolve(resp.data); + }) + .catch(err => { + reject(err); + }); + }); +} + +export default { + FetchTopArtists, + FetchTopSongs, + FetchTopAlbums +}; diff --git a/src/vuex/actions/index.js b/src/vuex/actions/index.js index aa9759c..b6f4676 100644 --- a/src/vuex/actions/index.js +++ b/src/vuex/actions/index.js @@ -1,7 +1,9 @@ import Auth from './Auth'; import Featured from './Featured'; +import TopSellers from './TopSellers'; export default { ...Auth, ...Featured, + ...TopSellers, }; diff --git a/src/vuex/mutations/TopSellers.js b/src/vuex/mutations/TopSellers.js new file mode 100644 index 0000000..6a464c3 --- /dev/null +++ b/src/vuex/mutations/TopSellers.js @@ -0,0 +1,17 @@ +function SET_TOP_ARTISTS (state, artists) { + state.top.artists = artists; +} + +function SET_TOP_SONGS (state, songs) { + state.top.songs = songs; +} + +function SET_TOP_ALBUMS (state, albums) { + state.top.albums = albums; +} + +export default { + SET_TOP_ARTISTS, + SET_TOP_SONGS, + SET_TOP_ALBUMS +}; diff --git a/src/vuex/mutations/index.js b/src/vuex/mutations/index.js index 79dcab2..170db11 100644 --- a/src/vuex/mutations/index.js +++ b/src/vuex/mutations/index.js @@ -1,5 +1,7 @@ import Featured from './Featured'; +import TopSellers from './TopSellers'; export default { - ...Featured + ...Featured, + ...TopSellers }; diff --git a/src/vuex/store.js b/src/vuex/store.js index cd251df..902779d 100644 --- a/src/vuex/store.js +++ b/src/vuex/store.js @@ -14,7 +14,12 @@ export default new Vuex.Store({ artists: [], albums: [], songs: [], - } + }, + top: { + artists: [], + albums: [], + songs: [], + }, }, getters: { user (state) {