diff --git a/src/components/tasks/partials/attachments.vue b/src/components/tasks/partials/attachments.vue index 21337842..ff5bd6a3 100644 --- a/src/components/tasks/partials/attachments.vue +++ b/src/components/tasks/partials/attachments.vue @@ -138,9 +138,8 @@ diff --git a/src/store/modules/tasks.ts b/src/store/modules/tasks.ts index d18e218e..9f7248aa 100644 --- a/src/store/modules/tasks.ts +++ b/src/store/modules/tasks.ts @@ -27,6 +27,7 @@ import type { IList } from '@/modelTypes/IList' import type { RootStoreState, TaskState } from '@/store/types' import {useLabelStore} from '@/stores/labels' import {useListStore} from '@/stores/lists' +import {useAttachmentStore} from '@/stores/attachments' import {playPop} from '@/helpers/playPop' // IDEA: maybe use a small fuzzy search here to prevent errors @@ -138,7 +139,8 @@ const tasksStore : Module= { } ctx.commit('kanban/setTaskInBucketByIndex', newTask, {root: true}) } - ctx.commit('attachments/add', attachment, {root: true}) + const attachmentStore = useAttachmentStore() + attachmentStore.add(attachment) }, async addAssignee(ctx, { @@ -282,7 +284,7 @@ const tasksStore : Module= { const labelStore = useLabelStore() const labelAddsToWaitFor = parsedLabels.map(async labelTitle => { - let label = validateLabel(labelStore.labels, labelTitle) + let label = validateLabel(Object.values(labelStore.labels), labelTitle) if (typeof label === 'undefined') { // label not found, create it const labelModel = new LabelModel({title: labelTitle}) diff --git a/src/stores/attachments.ts b/src/stores/attachments.ts index 172696e4..7c0f16d5 100644 --- a/src/stores/attachments.ts +++ b/src/stores/attachments.ts @@ -1,29 +1,34 @@ -import type { Module } from 'vuex' +import {defineStore, acceptHMRUpdate} from 'pinia' import {findIndexById} from '@/helpers/utils' -import type { AttachmentState, RootStoreState } from '@/store/types' -import type { IAttachment } from '@/modelTypes/IAttachment' +import type {AttachmentState} from '@/store/types' +import type {IAttachment} from '@/modelTypes/IAttachment' -const store : Module = { - namespaced: true, - state: () => ({ +export const useAttachmentStore = defineStore('attachment', { + state: (): AttachmentState => ({ attachments: [], }), - mutations: { - set(state, attachments: IAttachment[]) { + + actions: { + set(attachments: IAttachment[]) { console.debug('Set attachments', attachments) - state.attachments = attachments + this.attachments = attachments }, - add(state, attachment: IAttachment) { + + add(attachment: IAttachment) { console.debug('Add attachement', attachment) - state.attachments.push(attachment) + this.attachments.push(attachment) }, - removeById(state, id: IAttachment['id']) { - const attachmentIndex = findIndexById(state.attachments, id) - state.attachments.splice(attachmentIndex, 1) + + removeById(id: IAttachment['id']) { + const attachmentIndex = findIndexById(this.attachments, id) + this.attachments.splice(attachmentIndex, 1) console.debug('Remove attachement', id) }, }, -} +}) -export default store \ No newline at end of file +// support hot reloading +if (import.meta.hot) { + import.meta.hot.accept(acceptHMRUpdate(useAttachmentStore, import.meta.hot)) +} \ No newline at end of file diff --git a/src/views/tasks/TaskDetailView.vue b/src/views/tasks/TaskDetailView.vue index 6401f420..ea67956e 100644 --- a/src/views/tasks/TaskDetailView.vue +++ b/src/views/tasks/TaskDetailView.vue @@ -463,6 +463,7 @@ import {getListTitle} from '@/helpers/getListTitle' import type {IList} from '@/modelTypes/IList' import {colorIsDark} from '@/helpers/color/colorIsDark' import {useNamespaceStore} from '@/stores/namespaces' +import {useAttachmentStore} from '@/stores/attachments' function scrollIntoView(el) { if (!el) { @@ -595,7 +596,8 @@ export default defineComponent({ return typeof this.task !== 'undefined' && typeof this.task.maxRight !== 'undefined' && this.task.maxRight > rights.READ }, hasAttachments() { - return this.$store.state.attachments.attachments.length > 0 + const attachmentsStore = useAttachmentStore() + return attachmentsStore.attachments.length > 0 }, shouldShowClosePopup() { return this.$route.name.includes('kanban') @@ -624,7 +626,8 @@ export default defineComponent({ try { this.task = await this.taskService.get({id: taskId}) - this.$store.commit('attachments/set', this.task.attachments) + const attachmentStore = useAttachmentStore() + attachmentStore.set(this.task.attachments) this.taskColor = this.task.hexColor this.setActiveFields() await this.$nextTick()