fix(web): file add size
This commit is contained in:
@@ -5,10 +5,11 @@
|
||||
* @Last Modified time: 2026-03-23 17:46:25
|
||||
*/
|
||||
import { type FC, useEffect, useMemo, useState } from 'react'
|
||||
import { Flex, Input, Spin } from 'antd'
|
||||
import { Flex, Input } from 'antd'
|
||||
import clsx from 'clsx'
|
||||
|
||||
import type { ChatInputProps } from './types'
|
||||
import FileList from './FileList'
|
||||
|
||||
/**
|
||||
* Chat Input Component
|
||||
@@ -52,6 +53,7 @@ const ChatInput: FC<ChatInputProps> = ({
|
||||
})) || []
|
||||
}, [fileList])
|
||||
|
||||
|
||||
const handleSend = () => {
|
||||
if (loading || !inputValue || inputValue.trim() === '') return
|
||||
onSend(inputValue)
|
||||
@@ -64,100 +66,9 @@ const ChatInput: FC<ChatInputProps> = ({
|
||||
<Flex gap={0} vertical justify="space-between" className={clsx("rb-border rb:shadow-[0px_2px_12px_0px_rgba(23,23,25,0.12)] rb:rounded-3xl rb:min-h-30", {
|
||||
' rb:border-[#171719]!': isFocus
|
||||
})}>
|
||||
{previewFileList.length > 0 && <div className="rb:overflow-x-auto rb:max-w-full">
|
||||
<Flex gap={14} className="rb:mx-3! rb:mt-3! rb:w-max!">
|
||||
{previewFileList.map((file) => {
|
||||
if (file.type?.includes('image')) {
|
||||
return (
|
||||
<Spin key={`${file.url || file.uid}_${file.status}`} spinning={file.status === 'uploading'}>
|
||||
<div className={clsx("rb:inline-block rb:group rb:relative rb:rounded-lg rb:bg-[#F6F6F6] rb:border rb:border-[#F6F6F6]", {
|
||||
'rb:border-[#FF5D34]': file.status === 'error'
|
||||
})}>
|
||||
<img src={file.url} alt={file.name} className="rb:size-12! rb:rounded-lg rb:object-cover" />
|
||||
<div
|
||||
className="rb:hidden rb:group-hover:block rb:absolute rb:-right-1 rb:-top-1 rb:size-3.5 rb:cursor-pointer rb:bg-cover rb:bg-[url('@/assets/images/conversation/delete.svg')] rb:hover:bg-[url('@/assets/images/conversation/delete_hover.svg')]"
|
||||
onClick={() => handleDelete(file)}
|
||||
></div>
|
||||
</div>
|
||||
</Spin>
|
||||
)
|
||||
}
|
||||
if (file.type?.includes('video')) {
|
||||
return (
|
||||
<Spin key={`${file.url || file.uid}_${file.status}`} spinning={file.status === 'uploading'}>
|
||||
<div className={clsx("rb:w-45 rb:h-12 rb:inline-block rb:group rb:relative rb:rounded-lg rb:border rb:border-[#F6F6F6]", {
|
||||
'rb:border-[#FF5D34]': file.status === 'error'
|
||||
})}>
|
||||
<video src={file.url} controls className="rb:w-45 rb:h-12 rb:rounded-lg rb:object-cover" />
|
||||
<div
|
||||
className="rb:hidden rb:group-hover:block rb:absolute rb:-right-1 rb:-top-1 rb:size-3.5 rb:cursor-pointer rb:bg-cover rb:bg-[url('@/assets/images/conversation/delete.svg')]"
|
||||
onClick={() => handleDelete(file)}
|
||||
></div>
|
||||
</div>
|
||||
</Spin>
|
||||
)
|
||||
}
|
||||
if (file.type?.includes('audio')) {
|
||||
return (
|
||||
<Spin key={`${file.url || file.uid}_${file.status}`} spinning={file.status === 'uploading'}>
|
||||
<div className={clsx("rb:w-45 rb:h-12rb:inline-flex rb:items-center rb:group rb:relative rb:rounded-lg rb:bg-[#F6F6F6] rb:py-2 rb:px-2.5 rb:gap-2 rb:border rb:border-[#F6F6F6]", {
|
||||
'rb:border-[#FF5D34]': file.status === 'error'
|
||||
})}>
|
||||
<audio src={file.url} controls className="rb:w-45 rb:h-12" />
|
||||
<div
|
||||
className="rb:hidden rb:group-hover:block rb:absolute rb:-right-1 rb:-top-1 rb:size-3.5 rb:cursor-pointer rb:bg-cover rb:bg-[url('@/assets/images/conversation/delete.svg')]"
|
||||
onClick={() => handleDelete(file)}
|
||||
></div>
|
||||
</div>
|
||||
</Spin>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<Spin key={`${file.url || file.uid}_${file.status}`} spinning={file.status === 'uploading'}>
|
||||
<Flex
|
||||
align="center"
|
||||
gap={10}
|
||||
className={clsx("rb:w-45 rb:text-[12px] rb:group rb:relative rb:rounded-lg rb:bg-[#F6F6F6] rb:py-2! rb:px-2.5! rb:border rb:border-[#F6F6F6]", {
|
||||
'rb:border-[#FF5D34]': file.status === 'error'
|
||||
})}>
|
||||
<div
|
||||
className={clsx(
|
||||
"rb:size-5 rb:cursor-pointer rb:bg-cover rb:bg-[url('@/assets/images/conversation/pdf_disabled.svg')]",
|
||||
file.type?.includes('pdf')
|
||||
? "rb:bg-[url('@/assets/images/file/pdf.svg')]"
|
||||
: (file.type?.includes('excel') || file.type?.includes('spreadsheetml.sheet'))
|
||||
? "rb:bg-[url('@/assets/images/file/excel.svg')]"
|
||||
: file.type?.includes('csv')
|
||||
? "rb:bg-[url('@/assets/images/file/csv.svg')]"
|
||||
: file.type?.includes('html')
|
||||
? "rb:bg-[url('@/assets/images/file/html.svg')]"
|
||||
: file.type?.includes('json')
|
||||
? "rb:bg-[url('@/assets/images/file/json.svg')]"
|
||||
: file.type?.includes('ppt')
|
||||
? "rb:bg-[url('@/assets/images/file/ppt.svg')]"
|
||||
: file.type?.includes('text')
|
||||
? "rb:bg-[url('@/assets/images/file/txt.svg')]"
|
||||
: file.type?.includes('markdown')
|
||||
? "rb:bg-[url('@/assets/images/file/md.svg')]"
|
||||
: (file.type?.includes('doc') || file.type?.includes('docx') || file.type?.includes('word') || file.type?.includes('wordprocessingml.document'))
|
||||
? "rb:bg-[url('@/assets/images/file/word.svg')]"
|
||||
: null
|
||||
)}
|
||||
></div>
|
||||
<div className="rb:flex-1 rb:w-32.5">
|
||||
<div className="rb:leading-4 rb:text-ellipsis rb:overflow-hidden rb:whitespace-nowrap">{file.name}</div>
|
||||
<div className="rb:leading-3.5 rb:mt-0.5 rb:text-[#5B6167] rb:text-ellipsis rb:overflow-hidden rb:whitespace-nowrap">{file.type?.split('/')[file.type?.split('/').length - 1]} · {file.size}</div>
|
||||
</div>
|
||||
<div
|
||||
className="rb:hidden rb:group-hover:block rb:absolute rb:-right-1 rb:-top-1 rb:size-3.5 rb:cursor-pointer rb:bg-cover rb:bg-[url('@/assets/images/conversation/delete.svg')]"
|
||||
onClick={() => handleDelete(file)}
|
||||
></div>
|
||||
</Flex>
|
||||
</Spin>
|
||||
)
|
||||
})}
|
||||
</Flex>
|
||||
</div>}
|
||||
<div className="rb:overflow-x-auto rb:max-w-full">
|
||||
<FileList fileList={previewFileList} onDelete={handleDelete} />
|
||||
</div>
|
||||
{/* Message input area */}
|
||||
<Input.TextArea
|
||||
value={inputValue}
|
||||
|
||||
114
web/src/components/Chat/FileList.tsx
Normal file
114
web/src/components/Chat/FileList.tsx
Normal file
@@ -0,0 +1,114 @@
|
||||
import { type FC } from 'react'
|
||||
import { Flex, Spin } from 'antd'
|
||||
import clsx from 'clsx'
|
||||
import type { UploadFile, FlexProps } from 'antd'
|
||||
|
||||
interface FileListProps {
|
||||
fileList: UploadFile[];
|
||||
onDelete?: (file: UploadFile) => void;
|
||||
wrap?: FlexProps['wrap'];
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const FileList: FC<FileListProps> = ({ fileList, onDelete, wrap,
|
||||
className = "rb:mx-3! rb:mt-3! rb:w-max!"
|
||||
}) => {
|
||||
if (!fileList.length) return null
|
||||
|
||||
return (
|
||||
<Flex gap={14} wrap={wrap} className={className}>
|
||||
{fileList.map((file) => {
|
||||
if (file.type?.includes('image')) {
|
||||
return (
|
||||
<Spin key={`${file.url || file.uid}_${file.status}`} spinning={file.status === 'uploading'}>
|
||||
<div className={clsx("rb:inline-block rb:group rb:relative rb:rounded-lg rb:bg-[#F6F6F6] rb:border rb:border-[#F6F6F6]", {
|
||||
'rb:border-[#FF5D34]': file.status === 'error'
|
||||
})}>
|
||||
<img src={file.url} alt={file.name} className="rb:size-12! rb:rounded-lg rb:object-cover" />
|
||||
{onDelete && <div
|
||||
className="rb:hidden rb:group-hover:block rb:absolute rb:-right-1 rb:-top-1 rb:size-3.5 rb:cursor-pointer rb:bg-cover rb:bg-[url('@/assets/images/conversation/delete.svg')] rb:hover:bg-[url('@/assets/images/conversation/delete_hover.svg')]"
|
||||
onClick={() => onDelete(file)}
|
||||
></div>}
|
||||
</div>
|
||||
</Spin>
|
||||
)
|
||||
}
|
||||
if (file.type?.includes('video')) {
|
||||
return (
|
||||
<Spin key={`${file.url || file.uid}_${file.status}`} spinning={file.status === 'uploading'}>
|
||||
<div className={clsx("rb:w-45 rb:h-12 rb:inline-block rb:group rb:relative rb:rounded-lg rb:border rb:border-[#F6F6F6]", {
|
||||
'rb:border-[#FF5D34]': file.status === 'error'
|
||||
})}>
|
||||
<video src={file.url} controls className="rb:w-45 rb:h-12 rb:rounded-lg rb:object-cover" />
|
||||
{onDelete && <div
|
||||
className="rb:hidden rb:group-hover:block rb:absolute rb:-right-1 rb:-top-1 rb:size-3.5 rb:cursor-pointer rb:bg-cover rb:bg-[url('@/assets/images/conversation/delete.svg')]"
|
||||
onClick={() => onDelete(file)}
|
||||
></div>}
|
||||
</div>
|
||||
</Spin>
|
||||
)
|
||||
}
|
||||
if (file.type?.includes('audio')) {
|
||||
return (
|
||||
<Spin key={`${file.url || file.uid}_${file.status}`} spinning={file.status === 'uploading'}>
|
||||
<div className={clsx("rb:w-45 rb:h-12rb:inline-flex rb:items-center rb:group rb:relative rb:rounded-lg rb:bg-[#F6F6F6] rb:py-2 rb:px-2.5 rb:gap-2 rb:border rb:border-[#F6F6F6]", {
|
||||
'rb:border-[#FF5D34]': file.status === 'error'
|
||||
})}>
|
||||
<audio src={file.url} controls className="rb:w-45 rb:h-12" />
|
||||
{onDelete && <div
|
||||
className="rb:hidden rb:group-hover:block rb:absolute rb:-right-1 rb:-top-1 rb:size-3.5 rb:cursor-pointer rb:bg-cover rb:bg-[url('@/assets/images/conversation/delete.svg')]"
|
||||
onClick={() => onDelete(file)}
|
||||
></div>}
|
||||
</div>
|
||||
</Spin>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<Spin key={`${file.url || file.uid}_${file.status}`} spinning={file.status === 'uploading'}>
|
||||
<Flex
|
||||
align="center"
|
||||
gap={10}
|
||||
className={clsx("rb:w-45 rb:text-[12px] rb:group rb:relative rb:rounded-lg rb:bg-[#F6F6F6] rb:py-2! rb:px-2.5! rb:border rb:border-[#F6F6F6]", {
|
||||
'rb:border-[#FF5D34]': file.status === 'error'
|
||||
})}>
|
||||
<div
|
||||
className={clsx(
|
||||
"rb:size-5 rb:cursor-pointer rb:bg-cover rb:bg-[url('@/assets/images/conversation/pdf_disabled.svg')]",
|
||||
file.type?.includes('pdf')
|
||||
? "rb:bg-[url('@/assets/images/file/pdf.svg')]"
|
||||
: (file.type?.includes('excel') || file.type?.includes('spreadsheetml.sheet'))
|
||||
? "rb:bg-[url('@/assets/images/file/excel.svg')]"
|
||||
: file.type?.includes('csv')
|
||||
? "rb:bg-[url('@/assets/images/file/csv.svg')]"
|
||||
: file.type?.includes('html')
|
||||
? "rb:bg-[url('@/assets/images/file/html.svg')]"
|
||||
: file.type?.includes('json')
|
||||
? "rb:bg-[url('@/assets/images/file/json.svg')]"
|
||||
: file.type?.includes('ppt')
|
||||
? "rb:bg-[url('@/assets/images/file/ppt.svg')]"
|
||||
: file.type?.includes('text')
|
||||
? "rb:bg-[url('@/assets/images/file/txt.svg')]"
|
||||
: file.type?.includes('markdown')
|
||||
? "rb:bg-[url('@/assets/images/file/md.svg')]"
|
||||
: (file.type?.includes('doc') || file.type?.includes('docx') || file.type?.includes('word') || file.type?.includes('wordprocessingml.document'))
|
||||
? "rb:bg-[url('@/assets/images/file/word.svg')]"
|
||||
: null
|
||||
)}
|
||||
></div>
|
||||
<div className="rb:flex-1 rb:w-32.5">
|
||||
<div className="rb:leading-4 rb:text-ellipsis rb:overflow-hidden rb:whitespace-nowrap">{file.name}</div>
|
||||
<div className="rb:leading-3.5 rb:mt-0.5 rb:text-[#5B6167] rb:text-ellipsis rb:overflow-hidden rb:whitespace-nowrap">{[file.type?.split('/').pop(), file.size].filter(item => item).join(' · ')}</div>
|
||||
</div>
|
||||
{onDelete && <div
|
||||
className="rb:hidden rb:group-hover:block rb:absolute rb:-right-1 rb:-top-1 rb:size-3.5 rb:cursor-pointer rb:bg-cover rb:bg-[url('@/assets/images/conversation/delete.svg')]"
|
||||
onClick={() => onDelete(file)}
|
||||
></div>}
|
||||
</Flex>
|
||||
</Spin>
|
||||
)
|
||||
})}
|
||||
</Flex>
|
||||
)
|
||||
}
|
||||
|
||||
export default FileList
|
||||
@@ -6,12 +6,14 @@
|
||||
*/
|
||||
import { useEffect, useRef, useMemo } from 'react';
|
||||
import { EditorView, basicSetup } from 'codemirror';
|
||||
import { placeholder as cmPlaceholder } from '@codemirror/view';
|
||||
import { EditorState } from '@codemirror/state';
|
||||
import { python } from '@codemirror/lang-python';
|
||||
import { javascript } from '@codemirror/lang-javascript';
|
||||
import { java } from '@codemirror/lang-java';
|
||||
import { cpp } from '@codemirror/lang-cpp';
|
||||
import { rust } from '@codemirror/lang-rust';
|
||||
import { json } from '@codemirror/lang-json';
|
||||
import { oneDark } from '@codemirror/theme-one-dark';
|
||||
|
||||
/**
|
||||
@@ -26,12 +28,14 @@ import { oneDark } from '@codemirror/theme-one-dark';
|
||||
*/
|
||||
interface CodeMirrorEditorProps {
|
||||
value?: string;
|
||||
language?: 'python' | 'python3' | 'javascript' | 'typescript' | 'java' | 'cpp' | 'c' | 'rust';
|
||||
language?: 'python' | 'python3' | 'javascript' | 'typescript' | 'java' | 'cpp' | 'c' | 'rust' | 'json';
|
||||
onChange?: (value: string) => void;
|
||||
theme?: 'light' | 'dark';
|
||||
readOnly?: boolean;
|
||||
height?: string;
|
||||
size?: 'default' | 'small';
|
||||
placeholder?: string;
|
||||
variant?: 'outlined' | 'borderless';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,6 +51,7 @@ const languageExtensions: Record<string, any> = {
|
||||
cpp: cpp(),
|
||||
c: cpp(),
|
||||
rust: rust(),
|
||||
json: json(),
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -61,6 +66,8 @@ const CodeMirrorEditor = ({
|
||||
theme = 'light',
|
||||
readOnly = false,
|
||||
size,
|
||||
placeholder,
|
||||
variant = 'borderless',
|
||||
}: CodeMirrorEditorProps) => {
|
||||
// Reference to the DOM element that will contain the editor
|
||||
const editorRef = useRef<HTMLDivElement>(null);
|
||||
@@ -88,6 +95,7 @@ const CodeMirrorEditor = ({
|
||||
}
|
||||
}),
|
||||
EditorState.readOnly.of(readOnly), // Set read-only mode
|
||||
...(placeholder ? [cmPlaceholder(placeholder)] : []),
|
||||
];
|
||||
|
||||
// Apply dark theme if specified
|
||||
@@ -111,7 +119,7 @@ const CodeMirrorEditor = ({
|
||||
return () => {
|
||||
viewRef.current?.destroy();
|
||||
};
|
||||
}, [language, theme, readOnly]);
|
||||
}, [language, theme, readOnly, placeholder]);
|
||||
|
||||
/**
|
||||
* Update editor content when the value prop changes externally
|
||||
@@ -144,7 +152,13 @@ const CodeMirrorEditor = ({
|
||||
return `${size === 'small' ? 16 : 20}px`
|
||||
}, [size])
|
||||
|
||||
return <div ref={editorRef} style={{ minHeight, fontSize, lineHeight }} />;
|
||||
return (
|
||||
<div
|
||||
ref={editorRef}
|
||||
style={{ minHeight, fontSize, lineHeight }}
|
||||
className={variant === 'borderless' ? '' : 'rb-border rb:rounded-[8px]'}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default CodeMirrorEditor;
|
||||
|
||||
Reference in New Issue
Block a user