diff --git a/resources/js/components/commit-composer.tsx b/resources/js/components/commit-composer.tsx index a8898760d..cc8ea7b5b 100644 --- a/resources/js/components/commit-composer.tsx +++ b/resources/js/components/commit-composer.tsx @@ -1,6 +1,6 @@ import { Form, Link, usePage } from '@inertiajs/react'; import { ChartBar, Clock3 } from 'lucide-react'; -import type { KeyboardEvent } from 'react'; +import type { DragEvent, KeyboardEvent } from 'react'; import { useEffect, useRef, useState } from 'react'; import CommitController from '@/actions/App/Http/Controllers/CommitController'; import ScheduledCommitController from '@/actions/App/Http/Controllers/ScheduledCommitController'; @@ -177,12 +177,20 @@ function CommitComposerBody({ return () => observer.disconnect(); }, [isInDialog]); + const cancelFileDrop = (event: DragEvent) => { + if (event.dataTransfer.types.includes('Files')) { + event.preventDefault(); + } + }; + return (
- {attachments.isDraggingFiles && ( + {!isIssue && attachments.isDraggingFiles && ( )} preview.handleShortcut(event) || @@ -322,7 +332,7 @@ function CommitComposerBody({ /> - {!preview.isPreviewing && ( + {!isIssue && !preview.isPreviewing && ( )} - + {!isIssue && ( + + )} {poll && (
@@ -601,15 +615,21 @@ export function CommitComposer({ poll === null && !isScheduling, initialKind: initialIssue, + onStart: () => { + attachments.clear(); + }, onCreated: () => { drop(); + attachments.clear(); focusBody(id); }, }); const isCommittable = !attachments.reading && - (hasImages || characterCount(body.trim()) >= minBodyLength) && + (issue.command !== null + ? characterCount(body.trim()) >= minBodyLength + : hasImages || characterCount(body.trim()) >= minBodyLength) && (issue.command !== null ? characterCount(body) : bodyCharacterCount(body)) <= maxBodyLength && diff --git a/resources/js/components/issue-command.tsx b/resources/js/components/issue-command.tsx index 56b0513c7..343cc2881 100644 --- a/resources/js/components/issue-command.tsx +++ b/resources/js/components/issue-command.tsx @@ -36,12 +36,14 @@ export function useIssueCommand({ updateBody, enabled, initialKind = null, + onStart, onCreated, }: { body: string; updateBody: (body: string) => void; enabled: boolean; initialKind?: IssueKind | null; + onStart?: () => void; onCreated: () => void; }) { const [kind, setKind] = useState( @@ -69,6 +71,7 @@ export function useIssueCommand({ setKind(next); setSelected(0); updateBody(rest); + onStart?.(); }; const change = (value: string) => { diff --git a/tests/Unit/ComposerDraft.test.tsx b/tests/Unit/ComposerDraft.test.tsx index f786609a5..c0273c01f 100644 --- a/tests/Unit/ComposerDraft.test.tsx +++ b/tests/Unit/ComposerDraft.test.tsx @@ -536,6 +536,36 @@ test('typing a command and a space turns the draft into an issue, and backspace ); assert.equal(find('data-test', 'add-poll-button'), undefined); assert.equal(view.form.props.onBefore(), false); + const issueTextarea = view.fields.find( + (element) => element.type === MentionTextarea, + )!; + assert.equal(issueTextarea.props.onPaste, undefined); + assert.equal( + view.fields.some( + (element) => element.props.onDragEnter !== undefined, + ), + false, + ); + const dropzone = view.fields.find( + (element) => element.props.onDragOver !== undefined, + )!; + const onDragOver = dropzone.props.onDragOver as (event: unknown) => void; + let prevented = false; + onDragOver({ + dataTransfer: { types: ['Files'] }, + preventDefault: () => { + prevented = true; + }, + }); + assert.equal(prevented, true); + prevented = false; + onDragOver({ + dataTransfer: { types: ['text/plain'] }, + preventDefault: () => { + prevented = true; + }, + }); + assert.equal(prevented, false); keyDown(view, 'Backspace'); view = render();