2022-07-21 16:45:58 +00:00
|
|
|
import type { Module } from 'vuex'
|
2021-10-06 20:25:06 +00:00
|
|
|
import {findIndexById} from '@/helpers/utils'
|
2021-09-10 12:50:41 +00:00
|
|
|
|
2022-07-21 16:45:58 +00:00
|
|
|
import type { AttachmentState, RootStoreState } from '@/store/types'
|
2022-08-04 18:57:43 +00:00
|
|
|
import type { IAttachment } from '@/modelTypes/IAttachment'
|
2022-07-20 22:42:36 +00:00
|
|
|
|
2022-07-21 16:45:58 +00:00
|
|
|
const store : Module<AttachmentState, RootStoreState> = {
|
2020-07-14 19:26:05 +00:00
|
|
|
namespaced: true,
|
2022-07-21 16:45:58 +00:00
|
|
|
state: () => ({
|
2020-07-14 19:26:05 +00:00
|
|
|
attachments: [],
|
|
|
|
}),
|
|
|
|
mutations: {
|
2022-07-21 16:45:58 +00:00
|
|
|
set(state, attachments: IAttachment[]) {
|
2021-01-28 18:29:50 +00:00
|
|
|
console.debug('Set attachments', attachments)
|
2021-08-19 19:35:38 +00:00
|
|
|
state.attachments = attachments
|
2020-07-14 19:26:05 +00:00
|
|
|
},
|
2022-07-21 16:45:58 +00:00
|
|
|
add(state, attachment: IAttachment) {
|
2021-01-28 18:29:50 +00:00
|
|
|
console.debug('Add attachement', attachment)
|
2020-07-14 19:26:05 +00:00
|
|
|
state.attachments.push(attachment)
|
|
|
|
},
|
2022-07-21 16:45:58 +00:00
|
|
|
removeById(state, id: IAttachment['id']) {
|
2022-07-20 22:42:36 +00:00
|
|
|
const attachmentIndex = findIndexById<IAttachment>(state.attachments, id)
|
2021-09-10 12:50:41 +00:00
|
|
|
state.attachments.splice(attachmentIndex, 1)
|
|
|
|
console.debug('Remove attachement', id)
|
2020-07-14 19:26:05 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-21 16:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default store
|