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/stores/attachments.ts

34 lines
922 B
TypeScript

import {defineStore, acceptHMRUpdate} from 'pinia'
import {findIndexById} from '@/helpers/utils'
import type {AttachmentState} from '@/store/types'
import type {IAttachment} from '@/modelTypes/IAttachment'
export const useAttachmentStore = defineStore('attachment', {
state: (): AttachmentState => ({
attachments: [],
}),
actions: {
set(attachments: IAttachment[]) {
console.debug('Set attachments', attachments)
this.attachments = attachments
},
add(attachment: IAttachment) {
console.debug('Add attachement', attachment)
this.attachments.push(attachment)
},
removeById(id: IAttachment['id']) {
const attachmentIndex = findIndexById(this.attachments, id)
this.attachments.splice(attachmentIndex, 1)
console.debug('Remove attachement', id)
},
},
})
// support hot reloading
if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useAttachmentStore, import.meta.hot))
}