2022-10-02 21:16:17 +02:00
|
|
|
|
|
|
|
export const state = () => ({
|
2023-04-02 23:13:18 +02:00
|
|
|
tasks: [],
|
|
|
|
queuedEmbedLIds: []
|
2022-10-02 21:16:17 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
export const getters = {
|
2023-04-02 23:13:18 +02:00
|
|
|
getTasksByLibraryItemId: (state) => (libraryItemId) => {
|
2023-10-21 19:56:35 +02:00
|
|
|
return state.tasks.filter(t => t.data?.libraryItemId === libraryItemId)
|
|
|
|
},
|
|
|
|
getRunningLibraryScanTask: (state) => (libraryId) => {
|
2023-10-21 20:53:00 +02:00
|
|
|
const libraryScanActions = ['library-scan', 'library-match-all']
|
|
|
|
return state.tasks.find(t => libraryScanActions.includes(t.action) && t.data?.libraryId === libraryId && !t.isFinished)
|
2022-10-02 21:16:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
setTasks(state, tasks) {
|
|
|
|
state.tasks = tasks
|
|
|
|
},
|
|
|
|
addUpdateTask(state, task) {
|
2023-04-02 23:13:18 +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)
|
|
|
|
state.tasks = state.tasks.filter(_task => {
|
|
|
|
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) {
|
|
|
|
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) {
|
|
|
|
if (!state.queuedEmbedLIds.some(lid => lid === libraryItemId)) {
|
|
|
|
state.queuedEmbedLIds.push(libraryItemId)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removeQueuedEmbedLId(state, libraryItemId) {
|
|
|
|
state.queuedEmbedLIds = state.queuedEmbedLIds.filter(lid => lid !== libraryItemId)
|
2022-10-02 21:16:17 +02:00
|
|
|
}
|
|
|
|
}
|