From a50eca852fcb841166baa07a6cc405eeb70c6e9d Mon Sep 17 00:00:00 2001 From: Dominik Pschenitschni Date: Mon, 31 Oct 2022 20:40:26 +0000 Subject: [PATCH] feat: attachments store with composition api (#2603) Co-authored-by: Dominik Pschenitschni Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/2603 Co-authored-by: Dominik Pschenitschni Co-committed-by: Dominik Pschenitschni --- src/stores/attachments.ts | 44 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/stores/attachments.ts b/src/stores/attachments.ts index 51d32d558..596114af4 100644 --- a/src/stores/attachments.ts +++ b/src/stores/attachments.ts @@ -1,34 +1,34 @@ +import {ref, readonly} from 'vue' import {defineStore, acceptHMRUpdate} from 'pinia' import {findIndexById} from '@/helpers/utils' import type {IAttachment} from '@/modelTypes/IAttachment' -export interface AttachmentState { - attachments: IAttachment[], -} +export const useAttachmentStore = defineStore('attachment', () => { + const attachments = ref([]) -export const useAttachmentStore = defineStore('attachment', { - state: (): AttachmentState => ({ - attachments: [], - }), + function set(newAttachments: IAttachment[]) { + console.debug('Set attachments', newAttachments) + attachments.value = newAttachments + } - actions: { - set(attachments: IAttachment[]) { - console.debug('Set attachments', attachments) - this.attachments = attachments - }, + function add(attachment: IAttachment) { + console.debug('Add attachement', attachment) + attachments.value.push(attachment) + } - add(attachment: IAttachment) { - console.debug('Add attachement', attachment) - this.attachments.push(attachment) - }, + function removeById(id: IAttachment['id']) { + const attachmentIndex = findIndexById(attachments.value, id) + attachments.value.splice(attachmentIndex, 1) + console.debug('Remove attachement', id) + } - removeById(id: IAttachment['id']) { - const attachmentIndex = findIndexById(this.attachments, id) - this.attachments.splice(attachmentIndex, 1) - console.debug('Remove attachement', id) - }, - }, + return { + attachments: readonly(attachments), + set, + add, + removeById, + } }) // support hot reloading