⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(web): upload every file dropped into an editor
Tina031b1059dcf
diff --git a/apps/web/src/components/activity/comment-editor-image-upload.test.tsx b/apps/web/src/components/activity/comment-editor-image-upload.test.tsxindex 0ca89394c..13bbcaf1f 100644--- a/apps/web/src/components/activity/comment-editor-image-upload.test.tsx+++ b/apps/web/src/components/activity/comment-editor-image-upload.test.tsx@@ -272,6 +272,37 @@ describe("CommentEditor image upload insertion", () => {expect(onChange).not.toHaveBeenCalled();});+ it("uploads every file dropped at once (#2111)", async () => {+ // jsdom has no layout, so give ProseMirror a drop position.+ const posAtCoords = vi+ .spyOn(EditorView.prototype, "posAtCoords")+ .mockReturnValue({ pos: 1, inside: -1 });+ uploadMock.mockImplementation(async ({ file }) => ({+ ...asset,+ url: `/api/asset/${file.name}`,+ filename: file.name,+ }));+ try {+ render(<CommentEditor value="" onChange={() => {}} taskId="task-1" />);+ await waitFor(() => expect(latestEditor()).toBeDefined());+ const editor = latestEditor();++ const files = ["first.png", "second.png"].map(+ (name) => new File(["bytes"], name, { type: "image/png" }),+ );+ fireEvent.drop(editor.view.dom, {+ dataTransfer: { files, getData: () => "" },+ });++ await waitFor(() => expect(toast.success).toHaveBeenCalledTimes(2));+ expect(uploadMock).toHaveBeenCalledTimes(2);+ expect(editor.getHTML()).toContain("/api/asset/first.png");+ expect(editor.getHTML()).toContain("/api/asset/second.png");+ } finally {+ posAtCoords.mockRestore();+ }+ });+it("reports an error when the insert command does not execute", async () => {const resolveUpload = deferredUpload();render(<CommentEditor value="" onChange={() => {}} taskId="task-1" />);diff --git a/apps/web/src/components/activity/comment-editor.tsx b/apps/web/src/components/activity/comment-editor.tsxindex 6cc6c4cbd..1848a5017 100644--- a/apps/web/src/components/activity/comment-editor.tsx+++ b/apps/web/src/components/activity/comment-editor.tsx@@ -637,25 +637,19 @@ export default function CommentEditor({}return false;},- handleDrop: (view, event) => {+ handleDrop: (_view, event) => {if (readOnly || disabled) return false;const droppedFiles = Array.from(event.dataTransfer?.files || []);- const droppedFile = droppedFiles[0];- if (!droppedFile) return false;+ if (droppedFiles.length === 0) return false;event.preventDefault();- const coordinates = view.posAtCoords({- left: event.clientX,- top: event.clientY,- });-- const dropRange = coordinates- ? { from: coordinates.pos, to: coordinates.pos }- : undefined;-- void handleAssetFileUpload(droppedFile, editor, dropRange);+ // Each upload inserts after the previous one, the same way pasted+ // files do, so a multi-file drop keeps every file.+ for (const droppedFile of droppedFiles) {+ void handleAssetFileUpload(droppedFile, editor);+ }return true;},handleTextInput: (view, _from, _to, text) => {diff --git a/apps/web/src/components/task/task-description.test.tsx b/apps/web/src/components/task/task-description.test.tsxindex bb35ebd2d..4c2157c31 100644--- a/apps/web/src/components/task/task-description.test.tsx+++ b/apps/web/src/components/task/task-description.test.tsx@@ -1,7 +1,10 @@import { fireEvent, render, waitFor } from "@testing-library/react";import { type Editor, Extension } from "@tiptap/core";import TaskItem from "@tiptap/extension-task-item";+import { EditorView } from "@tiptap/pm/view";import { describe, expect, it, vi } from "vite-plus/test";+import { toast } from "@/lib/toast";+import { uploadTaskImage } from "@/lib/upload-task-image";import TaskDescription from "./task-description";const mocks = vi.hoisted(() => ({@@ -109,6 +112,59 @@ describe("TaskDescription", () => {}});+ it("uploads every file dropped at once (#2111)", async () => {+ const taskId = "multi-drop-task";+ mocks.editor = null;+ mocks.save.mockClear();+ mocks.tasks.set(taskId, { id: taskId, description: "" });+ // jsdom has no layout, so give ProseMirror a drop position and stub the+ // scroll-into-view measurement.+ const posAtCoords = vi+ .spyOn(EditorView.prototype, "posAtCoords")+ .mockReturnValue({ pos: 1, inside: -1 });+ const coordsAtPos = vi+ .spyOn(EditorView.prototype, "coordsAtPos")+ .mockReturnValue({ left: 0, right: 0, top: 0, bottom: 0 });+ const uploadMock = vi.mocked(uploadTaskImage);+ uploadMock.mockReset();+ uploadMock.mockImplementation(async ({ file }) => ({+ url: `/api/asset/${file.name}`,+ alt: file.name,+ filename: file.name,+ kind: "image" as const,+ mimeType: file.type,+ size: file.size,+ }));+ vi.mocked(toast.success).mockClear();+ try {+ const { unmount } = render(<TaskDescription taskId={taskId} />);+ await waitFor(() => expect(mocks.editor?.isDestroyed).toBe(false));+ const editor = mocks.editor!;++ const files = ["first.png", "second.png"].map(+ (name) => new File(["bytes"], name, { type: "image/png" }),+ );+ fireEvent.drop(editor.view.dom, {+ dataTransfer: { files, getData: () => "" },+ });++ await waitFor(() => expect(toast.success).toHaveBeenCalledTimes(2));+ expect(uploadMock).toHaveBeenCalledTimes(2);+ expect(editor.getHTML()).toContain("/api/asset/first.png");+ expect(editor.getHTML()).toContain("/api/asset/second.png");+ // Let the debounced save land before the next test clears its mock.+ await waitFor(() =>+ expect(mocks.save.mock.calls.at(-1)?.[0].description).toContain(+ "second.png",+ ),+ );+ unmount();+ } finally {+ posAtCoords.mockRestore();+ coordsAtPos.mockRestore();+ }+ });+it("preserves bold Markdown when pasting, saving and reopening a checklist (#1779)", async () => {mocks.save.mockClear();mocks.tasks.set("markdown-task", { id: "markdown-task", description: "" });diff --git a/apps/web/src/components/task/task-description.tsx b/apps/web/src/components/task/task-description.tsxindex ef0203eb4..34e74afa2 100644--- a/apps/web/src/components/task/task-description.tsx+++ b/apps/web/src/components/task/task-description.tsx@@ -536,22 +536,17 @@ export default function TaskDescription({ taskId }: TaskDescriptionProps) {setEmbedComposerError("");return true;},- handleDrop: (view, event) => {+ handleDrop: (_view, event) => {const droppedFiles = Array.from(event.dataTransfer?.files || []);- const droppedFile = droppedFiles[0];- if (!droppedFile) return false;+ if (droppedFiles.length === 0) return false;event.preventDefault();- const coordinates = view.posAtCoords({- left: event.clientX,- top: event.clientY,- });- const dropRange = coordinates- ? { from: coordinates.pos, to: coordinates.pos }- : undefined;-- void handleAssetFileUpload(droppedFile, editor, dropRange);+ // Each upload inserts after the previous one, the same way pasted+ // files do, so a multi-file drop keeps every file.+ for (const droppedFile of droppedFiles) {+ void handleAssetFileUpload(droppedFile, editor);+ }return true;},handleTextInput: (view, _from, _to, text) => {