Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Attached File Display (增强附件显示) #250

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions docs/playground/independent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ import {
EllipsisOutlined,
FireOutlined,
HeartOutlined,
LinkOutlined,
PaperClipOutlined,
PlusOutlined,
ReadOutlined,
ShareAltOutlined,
SmileOutlined,
} from '@ant-design/icons';
import { Button, type GetProp, Space } from 'antd';
import { UploadChangeParam } from 'antd/es/upload';

interface AttachedFile {
uid: string;
name: string;
size: number;
}

const renderTitle = (icon: React.ReactElement, title: string) => (
<Space align="start">
Expand Down Expand Up @@ -200,6 +207,8 @@ const Independent: React.FC = () => {

const [activeKey, setActiveKey] = React.useState(defaultConversationsItems[0].key);

const [attachedFiles, setAttachedFiles] = React.useState<AttachedFile[]>([]);

// ==================== Runtime ====================
const [agent] = useXAgent({
request: async ({ message }, { onSuccess }) => {
Expand Down Expand Up @@ -286,6 +295,20 @@ const Independent: React.FC = () => {
</Space>
);

const handleFileChange = (info: UploadChangeParam) => {
const { file } = info;
if (file && !file.status) {
setAttachedFiles((prevFiles) => [
...prevFiles,
{
uid: file.uid,
name: file.name,
size: file.size ?? 0,
},
]);
}
};

const attachmentsNode = (
<Attachments
beforeUpload={() => false}
Expand All @@ -294,8 +317,16 @@ const Independent: React.FC = () => {
title: 'Drag & Drop files here',
description: 'Support file type: image, video, audio, document, etc.',
}}
onChange={handleFileChange}
>
<Button type="text" icon={<LinkOutlined />} />
<div>
<Button type="text" icon={<PaperClipOutlined />} />
<Space direction="vertical" style={{ marginTop: 8 }}>
{attachedFiles.map((file) => (
<Attachments.FileCard key={file.uid} item={file} />
))}
</Space>
</div>
</Attachments>
);

Expand Down