feat: improved routing removing display none/block on route change; feat: improved favorites data rendering; feat: added type checking for socket.io
This commit is contained in:
@@ -5,6 +5,8 @@ import home from '@/store/modules/home'
|
||||
import settings from '@/store/modules/settings'
|
||||
import defaultSettings from '@/store/modules/defaultSettings'
|
||||
import spotifyCredentials from '@/store/modules/spotifyCredentials'
|
||||
import charts from '@/store/modules/charts'
|
||||
import favorites from '@/store/modules/favorites'
|
||||
|
||||
// Load Vuex
|
||||
Vue.use(Vuex)
|
||||
@@ -15,7 +17,9 @@ export default new Vuex.Store({
|
||||
home,
|
||||
settings,
|
||||
defaultSettings,
|
||||
credentials: spotifyCredentials
|
||||
spotifyCredentials,
|
||||
charts,
|
||||
favorites
|
||||
},
|
||||
strict: process.env.NODE_ENV !== 'production'
|
||||
})
|
||||
|
||||
40
src/store/modules/charts.js
Normal file
40
src/store/modules/charts.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
const state = {
|
||||
list: []
|
||||
}
|
||||
|
||||
let chartsCached = false
|
||||
|
||||
const actions = {
|
||||
/**
|
||||
* @param {object} context
|
||||
* @param {object[]} payload
|
||||
*/
|
||||
cacheCharts({ commit }, payload) {
|
||||
if (chartsCached) return
|
||||
|
||||
payload.forEach((chartObj, index) => {
|
||||
commit('SET_UNKNOWN_CHART', { index, chartObj })
|
||||
})
|
||||
|
||||
chartsCached = true
|
||||
}
|
||||
}
|
||||
|
||||
const getters = {
|
||||
getCharts: state => state.list
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
SET_UNKNOWN_CHART(state, payload) {
|
||||
Vue.set(state.list, payload.index, payload.chartObj)
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations
|
||||
}
|
||||
61
src/store/modules/favorites.js
Normal file
61
src/store/modules/favorites.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
const state = {
|
||||
albums: [],
|
||||
artists: [],
|
||||
playlists: [],
|
||||
tracks: []
|
||||
}
|
||||
|
||||
const actions = {
|
||||
setFavorites({ commit, dispatch }, payload) {
|
||||
payload.playlists.forEach((playlist, index) => {
|
||||
commit('SET_FAVORITES_PLAYLISTS', { index, data: playlist })
|
||||
})
|
||||
|
||||
payload.albums.forEach((album, index) => {
|
||||
commit('SET_FAVORITES_ALBUMS', { index, data: album })
|
||||
})
|
||||
|
||||
payload.artists.forEach((artist, index) => {
|
||||
commit('SET_FAVORITES_ARTISTS', { index, data: artist })
|
||||
})
|
||||
|
||||
dispatch('setFavoritesTracks', payload.tracks)
|
||||
},
|
||||
setFavoritesTracks({ commit }, payload) {
|
||||
payload.forEach((track, index) => {
|
||||
commit('SET_FAVORITES_TRACKS', { index, data: track })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const getters = {
|
||||
getFavorites: state => state,
|
||||
getFavoritesAlbums: state => state.albums,
|
||||
getFavoritesArtists: state => state.artists,
|
||||
getFavoritesPlaylists: state => state.playlists,
|
||||
getFavoritesTracks: state => state.tracks
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
SET_FAVORITES_ALBUMS: (state, payload) => {
|
||||
Vue.set(state.albums, payload.index, payload.data)
|
||||
},
|
||||
SET_FAVORITES_ARTISTS: (state, payload) => {
|
||||
Vue.set(state.artists, payload.index, payload.data)
|
||||
},
|
||||
SET_FAVORITES_PLAYLISTS: (state, payload) => {
|
||||
Vue.set(state.playlists, payload.index, payload.data)
|
||||
},
|
||||
SET_FAVORITES_TRACKS: (state, payload) => {
|
||||
Vue.set(state.tracks, payload.index, payload.data)
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
state,
|
||||
actions,
|
||||
getters,
|
||||
mutations
|
||||
}
|
||||
Reference in New Issue
Block a user