From f23f85523c23eaf2639ea6f8f1ad6208d634fda8 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Fri, 13 Sep 2024 14:47:05 +0800 Subject: [PATCH] feat: added attachment preview and upload/removal capabilities. - Added functionality to display attachment preview with upload and removal capabilities. - Added support for file attachments to the input bar. --- .../pages/home/Inputbar/AttachmentPreview.tsx | 36 ++++ .../src/pages/home/Inputbar/Inputbar.tsx | 188 ++++++++++-------- 2 files changed, 139 insertions(+), 85 deletions(-) create mode 100644 src/renderer/src/pages/home/Inputbar/AttachmentPreview.tsx diff --git a/src/renderer/src/pages/home/Inputbar/AttachmentPreview.tsx b/src/renderer/src/pages/home/Inputbar/AttachmentPreview.tsx new file mode 100644 index 0000000000..3c52c05e88 --- /dev/null +++ b/src/renderer/src/pages/home/Inputbar/AttachmentPreview.tsx @@ -0,0 +1,36 @@ +import { FileMetadata } from '@renderer/types' +import { Upload } from 'antd' +import { isEmpty } from 'lodash' +import { FC } from 'react' +import styled from 'styled-components' + +interface Props { + files: FileMetadata[] + setFiles: (files: FileMetadata[]) => void +} + +const AttachmentPreview: FC = ({ files, setFiles }) => { + if (isEmpty(files)) { + return null + } + + return ( + + ({ uid: file.id, url: 'file://' + file.path, status: 'done', name: file.name }))} + onRemove={(item) => setFiles(files.filter((file) => item.uid !== file.id))} + /> + + ) +} + +const Container = styled.div` + display: flex; + flex-direction: row; + gap: 10px; + margin: 10px 20px; + margin-right: 0; +` + +export default AttachmentPreview diff --git a/src/renderer/src/pages/home/Inputbar/Inputbar.tsx b/src/renderer/src/pages/home/Inputbar/Inputbar.tsx index 766199349a..bbccc987e1 100644 --- a/src/renderer/src/pages/home/Inputbar/Inputbar.tsx +++ b/src/renderer/src/pages/home/Inputbar/Inputbar.tsx @@ -27,6 +27,7 @@ import { useTranslation } from 'react-i18next' import styled from 'styled-components' import AttachmentButton from './AttachmentButton' +import AttachmentPreview from './AttachmentPreview' import SendMessageButton from './SendMessageButton' import TokenCount from './TokenCount' @@ -202,100 +203,108 @@ const Inputbar: FC = ({ assistant, setActiveTopic }) => { }, [assistant]) return ( - -