From d2dba3a0db8278ebec7f2e6571f77b0651c05bfd Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Tue, 13 Feb 2024 01:53:25 +0530 Subject: [PATCH] adding remote uploads tab --- frontend/src/upload/Upload.tsx | 182 +++++++++++++++++++++++++-------- frontend/tailwind.config.cjs | 5 +- 2 files changed, 146 insertions(+), 41 deletions(-) diff --git a/frontend/src/upload/Upload.tsx b/frontend/src/upload/Upload.tsx index f0735bc9..0e45e8c5 100644 --- a/frontend/src/upload/Upload.tsx +++ b/frontend/src/upload/Upload.tsx @@ -4,8 +4,61 @@ import { useDropzone } from 'react-dropzone'; import { useDispatch } from 'react-redux'; import { ActiveState } from '../models/misc'; import { getDocs } from '../preferences/preferenceApi'; +import Arrow2 from '../assets/dropdown-arrow.svg'; import { setSourceDocs } from '../preferences/preferenceSlice'; - +type urlOption = { + label: string, + value: string +} | null +function DropdownUrlType({ + options, + selectedOption, + onSelect, +}: { + options: urlOption[]; + selectedOption: urlOption; + onSelect: (value: urlOption) => void; +}) { + const [isOpen, setIsOpen] = useState(false); + return ( +
+ + {isOpen && ( +
+ {options.map((option, index) => ( +
+ { + onSelect(option); + setIsOpen(false); + }} + className="ml-2 flex-1 overflow-hidden overflow-ellipsis whitespace-nowrap px-1 py-3" + > + {option?.label} + +
+ ))} +
+ )} +
+ ); +} export default function Upload({ modalState, setModalState, @@ -14,6 +67,14 @@ export default function Upload({ setModalState: (state: ActiveState) => void; }) { const [docName, setDocName] = useState(''); + const [urlName, setUrlName] = useState('') + const [url, setUrl] = useState('') + const urlOptions: urlOption[] = [ + { label: 'Github', value: 'github' }, + { label: 'Sitemap', value: 'Sitemap' }, + { label: 'Link', value: 'link' }] + const [urlType, setUrlType] = useState(null) + const [activeTab, setActiveTab] = useState('file'); const [files, setfiles] = useState([]); const [progress, setProgress] = useState<{ type: 'UPLOAD' | 'TRAINIING'; @@ -55,9 +116,8 @@ export default function Upload({ setProgress(undefined); setModalState('INACTIVE'); }} - className={`rounded-3xl bg-purple-30 px-4 py-2 text-sm font-medium text-white ${ - isCancellable ? '' : 'hidden' - }`} + className={`rounded-3xl bg-purple-30 px-4 py-2 text-sm font-medium text-white ${isCancellable ? '' : 'hidden' + }`} > Finish @@ -166,7 +226,6 @@ export default function Upload({ ['.docx'], }, }); - let view; if (progress?.type === 'UPLOAD') { view = ; @@ -176,41 +235,85 @@ export default function Upload({ view = ( <>

Upload New Documentation

-

- Please upload .pdf, .txt, .rst, .docx, .md, .zip limited to 25mb -

- setDocName(e.target.value)} - > -
- Name -
-
- - - Choose Files - -
-
-

Uploaded Files

- {files.map((file) => ( -

- {file.name} -

- ))} - {files.length === 0 &&

None

} +
+ +
+ { + activeTab === 'file' && ( + <> + setDocName(e.target.value)} + > +
+ Name +
+
+ + + Choose Files + +
+

+ Please upload .pdf, .txt, .rst, .docx, .md, .zip limited to 25mb +

+
+

Uploaded Files

+ {files.map((file) => ( +

+ {file.name} +

+ ))} + {files.length === 0 &&

None

} +
+ + ) + } + { + activeTab === 'remote' && ( + <> + setUrlType(value)} selectedOption={urlType} options={urlOptions} /> + setUrlName(e.target.value)} + > +
+ Name +
+ setUrl(e.target.value)} + > +
+ Link +
+ + ) + }
@@ -232,9 +335,8 @@ export default function Upload({ return (
{view} diff --git a/frontend/tailwind.config.cjs b/frontend/tailwind.config.cjs index 5946c5a3..50af33c8 100644 --- a/frontend/tailwind.config.cjs +++ b/frontend/tailwind.config.cjs @@ -43,7 +43,10 @@ module.exports = { 'dark-charcoal':'#2F3036', 'bright-gray':'#ECECF1', 'outer-space':'#444654', - 'gun-metal':'#2E303E' + 'gun-metal':'#2E303E', + 'sonic-silver':'#747474', + 'soap':'#D8CCF1', + 'independence':'#54546D' }, }, },