From eaec2063012fe8554c83dd655cb7fa81c8730a02 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 19 Mar 2026 17:31:00 +0100 Subject: [PATCH] refactor(attachments): return uploaded attachments instead of writing to store uploadFiles now returns the array of uploaded IAttachment objects so callers can handle state updates themselves. --- frontend/src/helpers/attachments.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/frontend/src/helpers/attachments.ts b/frontend/src/helpers/attachments.ts index 86e43951b..645eabdce 100644 --- a/frontend/src/helpers/attachments.ts +++ b/frontend/src/helpers/attachments.ts @@ -2,9 +2,8 @@ import AttachmentModel from '@/models/attachment' import type {IAttachment} from '@/modelTypes/IAttachment' import AttachmentService from '@/services/attachment' -import {useTaskStore} from '@/stores/tasks' -export async function uploadFile(taskId: number, file: File, onSuccess?: (url: string) => void) { +export async function uploadFile(taskId: number, file: File, onSuccess?: (url: string) => void): Promise { const attachmentService = new AttachmentService() const files = [file] @@ -16,16 +15,14 @@ export async function uploadFiles( taskId: number, files: File[] | FileList, onSuccess?: (attachmentUrl: string) => void, -) { +): Promise { const attachmentModel = new AttachmentModel({taskId}) const response = await attachmentService.create(attachmentModel, files) console.debug(`Uploaded attachments for task ${taskId}, response was`, response) + const uploaded: IAttachment[] = [] response.success?.map((attachment: IAttachment) => { - useTaskStore().addTaskAttachment({ - taskId, - attachment, - }) + uploaded.push(attachment) onSuccess?.(generateAttachmentUrl(taskId, attachment.id)) }) @@ -33,6 +30,8 @@ export async function uploadFiles( const messages = response.errors.map((e: {message: string}) => e.message) throw new Error(messages.join('\n')) } + + return uploaded } export function generateAttachmentUrl(taskId: number, attachmentId: number) {