2024-07-20 11:28:06 +02:00
|
|
|
import Vue from 'vue'
|
2022-10-02 21:16:17 +02:00
|
|
|
|
|
|
|
export const state = () => ({
|
2023-04-02 23:13:18 +02:00
|
|
|
tasks: [],
|
2024-07-20 11:28:06 +02:00
|
|
|
queuedEmbedLIds: [],
|
|
|
|
audioFilesEncoding: {},
|
|
|
|
audioFilesFinished: {},
|
|
|
|
taskProgress: {}
|
2022-10-02 21:16:17 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
export const getters = {
|
2023-04-02 23:13:18 +02:00
|
|
|
getTasksByLibraryItemId: (state) => (libraryItemId) => {
|
2024-07-20 11:28:06 +02:00
|
|
|
return state.tasks.filter((t) => t.data?.libraryItemId === libraryItemId)
|
2023-10-21 19:56:35 +02:00
|
|
|
},
|
|
|
|
getRunningLibraryScanTask: (state) => (libraryId) => {
|
2023-10-21 20:53:00 +02:00
|
|
|
const libraryScanActions = ['library-scan', 'library-match-all']
|
2024-07-20 11:28:06 +02:00
|
|
|
return state.tasks.find((t) => libraryScanActions.includes(t.action) && t.data?.libraryId === libraryId && !t.isFinished)
|
|
|
|
},
|
|
|
|
getAudioFilesEncoding: (state) => (libraryItemId) => {
|
|
|
|
return state.audioFilesEncoding[libraryItemId]
|
|
|
|
},
|
|
|
|
getAudioFilesFinished: (state) => (libraryItemId) => {
|
|
|
|
return state.audioFilesFinished[libraryItemId]
|
|
|
|
},
|
|
|
|
getTaskProgress: (state) => (libraryItemId) => {
|
|
|
|
return state.taskProgress[libraryItemId]
|
2022-10-02 21:16:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-20 11:28:06 +02:00
|
|
|
export const actions = {}
|
2022-10-02 21:16:17 +02:00
|
|
|
|
|
|
|
export const mutations = {
|
2024-07-20 11:28:06 +02:00
|
|
|
updateAudioFilesEncoding(state, payload) {
|
|
|
|
if (!state.audioFilesEncoding[payload.libraryItemId]) {
|
|
|
|
Vue.set(state.audioFilesEncoding, payload.libraryItemId, {})
|
|
|
|
}
|
|
|
|
Vue.set(state.audioFilesEncoding[payload.libraryItemId], payload.ino, payload.progress)
|
|
|
|
},
|
|
|
|
updateAudioFilesFinished(state, payload) {
|
|
|
|
if (!state.audioFilesFinished[payload.libraryItemId]) {
|
|
|
|
Vue.set(state.audioFilesFinished, payload.libraryItemId, {})
|
|
|
|
}
|
|
|
|
Vue.set(state.audioFilesFinished[payload.libraryItemId], payload.ino, payload.finished)
|
|
|
|
},
|
|
|
|
updateTaskProgress(state, payload) {
|
|
|
|
Vue.set(state.taskProgress, payload.libraryItemId, payload.progress)
|
|
|
|
},
|
2022-10-02 21:16:17 +02:00
|
|
|
setTasks(state, tasks) {
|
|
|
|
state.tasks = tasks
|
|
|
|
},
|
|
|
|
addUpdateTask(state, task) {
|
2024-07-20 11:28:06 +02:00
|
|
|
const index = state.tasks.findIndex((d) => d.id === task.id)
|
2022-10-02 21:16:17 +02:00
|
|
|
if (index >= 0) {
|
|
|
|
state.tasks.splice(index, 1, task)
|
|
|
|
} else {
|
2023-04-02 23:13:18 +02:00
|
|
|
// Remove duplicate (only have one library item per action)
|
2024-07-20 11:28:06 +02:00
|
|
|
state.tasks = state.tasks.filter((_task) => {
|
2023-04-02 23:13:18 +02:00
|
|
|
if (!_task.data?.libraryItemId || _task.action !== task.action) return true
|
|
|
|
return _task.data.libraryItemId !== task.data.libraryItemId
|
|
|
|
})
|
|
|
|
|
2022-10-02 21:16:17 +02:00
|
|
|
state.tasks.push(task)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removeTask(state, task) {
|
2024-07-20 11:28:06 +02:00
|
|
|
state.tasks = state.tasks.filter((d) => d.id !== task.id)
|
2023-04-02 23:13:18 +02:00
|
|
|
},
|
|
|
|
setQueuedEmbedLIds(state, libraryItemIds) {
|
|
|
|
state.queuedEmbedLIds = libraryItemIds
|
|
|
|
},
|
|
|
|
addQueuedEmbedLId(state, libraryItemId) {
|
2024-07-20 11:28:06 +02:00
|
|
|
if (!state.queuedEmbedLIds.some((lid) => lid === libraryItemId)) {
|
2023-04-02 23:13:18 +02:00
|
|
|
state.queuedEmbedLIds.push(libraryItemId)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removeQueuedEmbedLId(state, libraryItemId) {
|
2024-07-20 11:28:06 +02:00
|
|
|
state.queuedEmbedLIds = state.queuedEmbedLIds.filter((lid) => lid !== libraryItemId)
|
2022-10-02 21:16:17 +02:00
|
|
|
}
|
2024-07-20 11:28:06 +02:00
|
|
|
}
|