2021-09-04 21:17:26 +02:00
|
|
|
|
|
|
|
export const state = () => ({
|
|
|
|
downloads: []
|
|
|
|
})
|
|
|
|
|
|
|
|
export const getters = {
|
|
|
|
getDownloads: (state) => (audiobookId) => {
|
|
|
|
return state.downloads.filter(d => d.audiobookId === audiobookId)
|
2021-09-15 03:45:00 +02:00
|
|
|
},
|
|
|
|
getDownload: (state) => (id) => {
|
|
|
|
return state.downloads.find(d => d.id === id)
|
2021-09-04 21:17:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
addUpdateDownload(state, download) {
|
|
|
|
// Remove older downloads of matching type
|
|
|
|
state.downloads = state.downloads.filter(d => {
|
|
|
|
if (d.id !== download.id && d.type === download.type) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
var index = state.downloads.findIndex(d => d.id === download.id)
|
|
|
|
if (index >= 0) {
|
|
|
|
state.downloads.splice(index, 1, download)
|
|
|
|
} else {
|
|
|
|
state.downloads.push(download)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removeDownload(state, download) {
|
|
|
|
state.downloads = state.downloads.filter(d => d.id !== download.id)
|
|
|
|
}
|
|
|
|
}
|