From bf63509a6e3955e86142f4461306b2fd50481bd3 Mon Sep 17 00:00:00 2001 From: Srayash Date: Mon, 2 Dec 2024 00:16:47 +0530 Subject: [PATCH 1/7] modify upload component to take receivedFile and renderTab as props. --- frontend/src/Navigation.tsx | 2 ++ frontend/src/settings/Documents.tsx | 2 ++ frontend/src/upload/Upload.tsx | 10 +++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/frontend/src/Navigation.tsx b/frontend/src/Navigation.tsx index f6d65675..c29aaf20 100644 --- a/frontend/src/Navigation.tsx +++ b/frontend/src/Navigation.tsx @@ -476,8 +476,10 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { /> {uploadModalState === 'ACTIVE' && ( setUploadModalState('INACTIVE')} > )} diff --git a/frontend/src/settings/Documents.tsx b/frontend/src/settings/Documents.tsx index bbad4763..52a63351 100644 --- a/frontend/src/settings/Documents.tsx +++ b/frontend/src/settings/Documents.tsx @@ -325,8 +325,10 @@ const Documents: React.FC = ({
{/* Your Upload component */} setModalState('INACTIVE')} />
diff --git a/frontend/src/upload/Upload.tsx b/frontend/src/upload/Upload.tsx index 3299f808..90792a4a 100644 --- a/frontend/src/upload/Upload.tsx +++ b/frontend/src/upload/Upload.tsx @@ -19,15 +19,19 @@ import { import WrapperModal from '../modals/WrapperModal'; function Upload({ + receivedFile, setModalState, isOnboarding, + renderTab, close, }: { + receivedFile: File[]; setModalState: (state: ActiveState) => void; isOnboarding: boolean; + renderTab: string | null; close: () => void; }) { - const [docName, setDocName] = useState(''); + const [docName, setDocName] = useState(receivedFile[0]?.name); const [urlName, setUrlName] = useState(''); const [url, setUrl] = useState(''); const [repoUrl, setRepoUrl] = useState(''); // P3f93 @@ -38,8 +42,8 @@ function Upload({ search_queries: [''], number_posts: 10, }); - const [activeTab, setActiveTab] = useState(null); - const [files, setfiles] = useState([]); + const [activeTab, setActiveTab] = useState(renderTab); + const [files, setfiles] = useState(receivedFile); const [progress, setProgress] = useState<{ type: 'UPLOAD' | 'TRAINING'; percentage: number; From c3973571a7286cd904f486503ef173b6589293b9 Mon Sep 17 00:00:00 2001 From: Srayash Date: Mon, 2 Dec 2024 00:22:16 +0530 Subject: [PATCH 2/7] feature: Drag and drop training, from input box. --- frontend/src/conversation/Conversation.tsx | 55 +++++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/frontend/src/conversation/Conversation.tsx b/frontend/src/conversation/Conversation.tsx index 7f06d6b1..d5781772 100644 --- a/frontend/src/conversation/Conversation.tsx +++ b/frontend/src/conversation/Conversation.tsx @@ -1,8 +1,9 @@ -import { Fragment, useEffect, useRef, useState } from 'react'; +import { Fragment, useCallback, useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useDispatch, useSelector } from 'react-redux'; import { useNavigate } from 'react-router-dom'; import Hero from '../Hero'; +import { useDropzone } from 'react-dropzone'; import ArrowDown from '../assets/arrow-down.svg'; import newChatIcon from '../assets/openNewChat.svg'; import Send from '../assets/send.svg'; @@ -28,6 +29,8 @@ import { updateConversationId, updateQuery, } from './conversationSlice'; +import Upload from '../upload/Upload'; +import { ActiveState } from '../models/misc'; export default function Conversation() { const queries = useSelector(selectQueries); @@ -45,6 +48,41 @@ export default function Conversation() { const [isShareModalOpen, setShareModalState] = useState(false); const { t } = useTranslation(); const { isMobile } = useMediaQuery(); + const [uploadModalState, setUploadModalState] = + useState('INACTIVE'); + const [files, setFiles] = useState([]); + + const onDrop = useCallback((acceptedFiles: File[]) => { + setUploadModalState('ACTIVE'); + setFiles(acceptedFiles); + }, []); + + const { getRootProps, getInputProps, isDragActive } = useDropzone({ + onDrop, + multiple: true, + onDragEnter: () => undefined, + onDragOver: () => undefined, + onDragLeave: () => undefined, + maxSize: 25000000, + accept: { + 'application/pdf': ['.pdf'], + 'text/plain': ['.txt'], + 'text/x-rst': ['.rst'], + 'text/x-markdown': ['.md'], + 'application/zip': ['.zip'], + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': + ['.docx'], + 'application/json': ['.json'], + 'text/csv': ['.csv'], + 'text/html': ['.html'], + 'application/epub+zip': ['.epub'], + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': [ + '.xlsx', + ], + 'application/vnd.openxmlformats-officedocument.presentationml.presentation': + ['.pptx'], + }, + }); const handleUserInterruption = () => { if (!eventInterrupt && status === 'loading') setEventInterrupt(true); @@ -323,7 +361,11 @@ export default function Conversation() {
-
+
+