Skip to content

[refactor] add Chat Message component with File Text parsing API#96

Open
Copilot wants to merge 5 commits intomainfrom
copilot/add-file-upload-support
Open

[refactor] add Chat Message component with File Text parsing API#96
Copilot wants to merge 5 commits intomainfrom
copilot/add-file-upload-support

Conversation

Copy link
Contributor

Copilot AI commented Mar 6, 2026

PR-96 PR-96 PR-96 Powered by Pull Request Badge

Adds file attach, paste, and drop support to the project evaluation chat input. Each uploaded file is sent as its own ConsultMessage with a markdown image embed or link.

Changes

models/File.ts (new)

  • FileModel extends TableModel<Base> — wraps the signed-link file upload flow
  • upload(file: File | Blob): POSTs to file/signed-link/{name} for a { putLink, getLink } pair, PUTs the file directly to the CDN URL via native fetch, returns the public download URL
  • Uses crypto.randomUUID() for Blob filenames to avoid collisions

components/PasteDropBox.tsx (new)

  • Standalone <PasteDropBox /> wrapper component that intercepts onPaste and onDrop events from its children
  • Reads three data types from DataTransferItemList and fires separate callbacks:
    • Files → onFiles(files: File[])
    • HTML text (text/html) → onHTML(html: string)
    • Plain text (text/plain) → onText(text: string)
  • preventDefault() is only called when the corresponding callback is provided

pages/dashboard/project/[id].tsx

  • Attach button: uses MUI component="label" pattern — <IconButton component="label"> with a sr-only <input type="file" multiple> inside, eliminating the need for a ref and manual click handler
  • Paste/drop: TextField is wrapped with <PasteDropBox onFiles={this.handleFiles}> to proxy paste and drop file events
  • handleFiles: uploads each file sequentially, sends ConsultMessage as ![name](url) for images or [name](url) otherwise
  • Disabled state: file button and send button both gate on fileStore.uploading > 0 || messageStore.uploading > 0

Translation (en-US / zh-CN / zh-TW)

  • Added attach_files key for the file button tooltip
<Tooltip title={t('attach_files')}>
  <IconButton component="label" size="small" disabled={...}>
    <SymbolIcon name="attach_file" />
    <input type="file" multiple className="sr-only" onChange={this.handleFileInputChange} />
  </IconButton>
</Tooltip>
<PasteDropBox className="flex-1 min-w-0" onFiles={this.handleFiles}>
  <TextField name="content" ... />
</PasteDropBox>
Original prompt

This section details on the original issue you should resolve

<issue_title>需求评估页面支持文件上传、解析</issue_title>
<issue_description>### Task description

  1. 新增文件 API 封装类,可抄:https://github.com/FreeCodeCamp-Chengdu/HOP/blob/66e0273c8e162d8bd39ad09fd5305a08b7588f57/models/Base/File.ts#L8-L32
  2. 需求输入框左侧新增文件多选按钮,目标代码:
    <Paper
    component="form"
    elevation={1}
    className="sticky bottom-0 mx-1 mt-auto mb-1 flex items-end gap-2 p-1.5 sm:mx-0 sm:mb-0 sm:p-2"
    onSubmit={this.handleMessageSubmit}
    >
    <TextField
    name="content"
    placeholder={t('type_your_message')}
    multiline
    maxRows={4}
    fullWidth
    variant="outlined"
    size="small"
    required
    onKeyUp={this.handleQuickSubmit}
    />
    <Button
    type="submit"
    variant="contained"
    className="min-w-full px-2 whitespace-nowrap sm:min-w-0"
    disabled={messageStore.uploading > 0}
    >
    {t('send')}
    </Button>
    </Paper>
  3. 需求输入框监听粘贴、拖放,再将所有文件过滤出来,可抄:https://github.com/idea2app/Edkit/blob/bd165e30b0a712b7c792f3461bfe65694fc079f7/source/Editor.ts#L115-L137
  4. 将所有输入文件依次上传,并各发一条 ConsultMessage

Reward currency

TQT $

Reward amount

90

Reward payer

石垚 tech-query@idea2app.cn

Task source

https://idea2app.feishu.cn/record/W7lXrg8MCewHvoc9Wztc12WtnMd</issue_description>

Comments on the Issue (you are @copilot in this section)

Human changes

  • [refactor] add Chat Message component with File Text parsing API (resolve 需求评估页面支持文件上传、解析 #95)
  • [add] File Preview & Paste Drop Box components
  • [refactor] simplify Copilot codes
  • [optimize] upgrade to ESLint 10 & other latest Upstream packages

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Add models/File.ts with FileModel class for uploading files via signed links
- Add file attach button (left of input) triggering multi-file selector
- Add paste/drop handlers on TextField to extract and upload files
- Each uploaded file is sent as a separate ConsultMessage (markdown link/image)
- Send button disabled during file or message upload
- Add attach_files translation key to all 3 locale files

Co-authored-by: TechQuery <19969570+TechQuery@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for file upload and parsing in demand assessment page feat: file upload support on requirement evaluation chat page Mar 6, 2026
- Extract paste/drop handling into standalone PasteDropBox component
  that reads text/html, text/plain, and files from DataTransfer and
  fires separate onHTML, onText, onFiles callbacks
- Replace hidden input + ref + onClick with MUI component="label"
  pattern on IconButton (sr-only input inside the button label)
- Wrap TextField with PasteDropBox in project evaluation page

Co-authored-by: TechQuery <19969570+TechQuery@users.noreply.github.com>
[refactor] simplify Copilot codes
[optimize] upgrade to ESLint 10 & other latest Upstream packages
@TechQuery TechQuery marked this pull request as ready for review March 7, 2026 13:20
@TechQuery TechQuery changed the title feat: file upload support on requirement evaluation chat page [refactor] add Chat Message component with File Text parsing API Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

需求评估页面支持文件上传、解析

2 participants