This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/store/modules/attachments.ts

26 lines
801 B
TypeScript

import {findIndexById} from '@/helpers/utils'
import type { AttachmentState } from '@/store/types'
import type { IAttachment } from '@/models/attachment'
export default {
namespaced: true,
state: (): AttachmentState => ({
attachments: [],
}),
mutations: {
set(state: AttachmentState, attachments: IAttachment[]) {
console.debug('Set attachments', attachments)
state.attachments = attachments
},
add(state: AttachmentState, attachment: IAttachment) {
console.debug('Add attachement', attachment)
state.attachments.push(attachment)
},
removeById(state: AttachmentState, id: IAttachment['id']) {
const attachmentIndex = findIndexById<IAttachment>(state.attachments, id)
state.attachments.splice(attachmentIndex, 1)
console.debug('Remove attachement', id)
},
},
}