hapi icon indicating copy to clipboard operation
hapi copied to clipboard

feat(web): drag-and-drop files onto chat panel to add as attachments

Open swear01 opened this issue 5 months ago • 1 comments

Summary

Add drag-and-drop support so users can drag files from the OS desktop or file manager onto the right-side chat panel to attach them to the current composer message — the same UX pattern used by ChatGPT, Slack, and Notion.

Desired behaviour

Action Result
User starts dragging a file (anywhere on page) A drop-zone overlay appears on the right chat panel only
User hovers file over left sidebar Overlay stays on right panel; sidebar shows no drop affordance
User drops file on right chat panel File is added as a composer attachment (same path as paste / attach button)
User drops file on left sidebar Nothing happens; browser default is suppressed
User cancels drag (Escape / drags off window) Overlay disappears

Scope constraint

  • Overlay is shown as soon as a dragenter is detected anywhere on the page (so the user can see where to drop even before reaching the target).
  • Actual drop is accepted only on the right panel — the div.min-w-0.flex-1.flex-col wrapper in router.tsx (currently around line 540).

Implementation notes

The attachment plumbing already exists. HappyComposer calls api.composer().addAttachment(file) for pasted images (handlePaste, ~line 554). Drag-and-drop can reuse the same path:

// inside the right-panel drop handler
event.preventDefault()
const files = Array.from(event.dataTransfer.files)
for (const file of files) {
  await api.composer().addAttachment(file)
}

Suggested approach:

  1. Add a useDragOver hook (or inline logic on the right-panel wrapper) that listens to dragenter / dragleave / dragover / drop on document.
  2. Show a full-height overlay inside the right panel while a drag is active — something like a semi-transparent backdrop with a dashed border and "Drop to attach" label.
  3. Only the drop handler on the right panel calls addAttachment; the sidebar has no drop listener.
  4. Guard the same way as the existing paste path (e.g. skip if disabled, respect attachmentsReady).

Acceptance criteria

  • [ ] Dragging any file over the page shows the overlay on the right chat panel.
  • [ ] Dropping on the left sidebar does not add an attachment and does not navigate away.
  • [ ] Dropping on the right panel adds the file(s) as attachment chips in the composer.
  • [ ] The overlay disappears on drop, on drag-cancel, and when the cursor leaves the window.
  • [ ] Works for images and non-image files (PDF, text, etc.) consistent with what addAttachment already accepts.

swear01 avatar Jun 16 '26 16:06 swear01

Confirmed: this is not currently implemented in web/src; I did not find existing drag/drop handlers there. The requested approach matches the current attachment plumbing, with two details to preserve:

  • api.composer().addAttachment(file) is already used by paste, but the current paste handler only accepts image clipboard files.
  • The attachment adapter itself accepts */*, so the attach-button path supports non-image files as well.
  • Scheduled sends and attachments are intentionally blocked together today, so drag/drop should reuse the same guard as the existing attachment paths.

Relevant code:

  • web/src/router.tsx:540 - right-side panel wrapper: min-w-0 flex-1 flex-col bg-[var(--app-bg)]; this is the right place for a panel-scoped overlay/drop target.
  • web/src/components/AssistantChat/HappyComposer.tsx:535 - paste handler reads clipboard files.
  • web/src/components/AssistantChat/HappyComposer.tsx:537 - paste currently filters to image/* only.
  • web/src/components/AssistantChat/HappyComposer.tsx:546 - paste path suppresses attachment add while a schedule is active.
  • web/src/components/AssistantChat/HappyComposer.tsx:554 - existing path calls api.composer().addAttachment(file).
  • web/src/components/AssistantChat/HappyComposer.tsx:195 - attachmentsReady logic used before send.
  • web/src/lib/attachmentAdapter.ts:28 - attachment adapter declares accept: '*/*'.
  • web/src/lib/attachmentAdapter.ts:48 - upload size limit is currently 50 MiB.
  • web/src/lib/attachmentAdapter.ts:74 - upload goes through api.uploadFile(...).
  • web/src/lib/attachmentAdapter.ts:94 - previews are generated only for image files under 5 MiB.
  • web/src/components/AssistantChat/ComposerButtons.tsx:479 - attach button uses ComposerPrimitive.AddAttachment.
  • web/src/components/AssistantChat/ComposerButtons.tsx:482 - attach button is disabled when controls are disabled or a schedule is active.
  • web/src/components/SessionChat.tsx:949 - attachment adapter is only provided for active sessions.

No more info needed from the reporter; acceptance criteria are specific enough to implement.


HAPI Bot

github-actions[bot] avatar Jun 16 '26 17:06 github-actions[bot]