2020-02-16 18:30:00 +00:00
|
|
|
import IsEqual from 'lodash.isequal'
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
isSideNavOpen: false,
|
|
|
|
sessionSearchHistory: [],
|
|
|
|
searchSettings: {
|
|
|
|
sortBy: 'relevance',
|
|
|
|
time: '',
|
|
|
|
type: 'all',
|
|
|
|
duration: ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const getters = {
|
2020-03-01 03:37:02 +00:00
|
|
|
getIsSideNavOpen () {
|
|
|
|
return state.isSideNavOpen
|
|
|
|
},
|
|
|
|
|
|
|
|
getCurrentVolume () {
|
|
|
|
return state.currentVolume
|
|
|
|
},
|
|
|
|
|
2020-02-16 18:30:00 +00:00
|
|
|
getSessionSearchHistory () {
|
|
|
|
return state.sessionSearchHistory
|
|
|
|
},
|
|
|
|
|
|
|
|
getSearchSettings () {
|
|
|
|
return state.searchSettings
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const actions = {}
|
|
|
|
|
|
|
|
const mutations = {
|
|
|
|
toggleSideNav (state) {
|
|
|
|
state.isSideNavOpen = !state.isSideNavOpen
|
|
|
|
},
|
|
|
|
|
|
|
|
setSessionSearchHistory (state, history) {
|
|
|
|
state.sessionSearchHistory = history
|
|
|
|
},
|
|
|
|
|
|
|
|
addToSessionSearchHistory (state, payload) {
|
|
|
|
const sameSearch = state.sessionSearchHistory.findIndex((search) => {
|
|
|
|
return search.query === payload.query && IsEqual(payload.searchSettings, search.searchSettings)
|
|
|
|
})
|
|
|
|
|
|
|
|
if (sameSearch !== -1) {
|
|
|
|
state.sessionSearchHistory[sameSearch].data = state.sessionSearchHistory[sameSearch].data.concat(payload.data)
|
|
|
|
state.sessionSearchHistory[sameSearch].nextPageRef = payload.nextPageRef
|
|
|
|
} else {
|
|
|
|
state.sessionSearchHistory.push(payload)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setSearchSortBy (state, value) {
|
|
|
|
state.searchSettings.sortBy = value
|
|
|
|
},
|
|
|
|
|
|
|
|
setSearchTime (state, value) {
|
|
|
|
state.searchSettings.time = value
|
|
|
|
},
|
|
|
|
|
|
|
|
setSearchType (state, value) {
|
|
|
|
state.searchSettings.type = value
|
|
|
|
},
|
|
|
|
|
|
|
|
setSearchDuration (state, value) {
|
|
|
|
state.searchSettings.duration = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
state,
|
|
|
|
getters,
|
|
|
|
actions,
|
|
|
|
mutations
|
|
|
|
}
|