From e1a2bd11a9e812549be6338642397b4d824db162 Mon Sep 17 00:00:00 2001 From: Siddhant Rai Date: Wed, 6 Mar 2024 16:01:53 +0530 Subject: [PATCH] fix: upload dropdown also combined --- frontend/src/components/Dropdown.tsx | 52 ++++-- frontend/src/upload/Upload.tsx | 252 +++++++++++++-------------- 2 files changed, 158 insertions(+), 146 deletions(-) diff --git a/frontend/src/components/Dropdown.tsx b/frontend/src/components/Dropdown.tsx index cc570893..5654b430 100644 --- a/frontend/src/components/Dropdown.tsx +++ b/frontend/src/components/Dropdown.tsx @@ -8,26 +8,52 @@ function Dropdown({ showDelete, onDelete, }: { - options: string[] | { name: string; id: string; type: string }[]; - selectedValue: string; + options: + | string[] + | { name: string; id: string; type: string }[] + | { label: string; value: string }[]; + selectedValue: string | { label: string; value: string }; onSelect: | ((value: string) => void) - | ((value: { name: string; id: string; type: string }) => void); + | ((value: { name: string; id: string; type: string }) => void) + | ((value: { label: string; value: string }) => void); showDelete?: boolean; onDelete?: (value: string) => 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} - -
- ))} -
- )} -
- ); -} +import Dropdown from '../components/Dropdown'; + export default function Upload({ modalState, setModalState, @@ -67,13 +15,17 @@ export default function Upload({ setModalState: (state: ActiveState) => void; }) { const [docName, setDocName] = useState(''); - const [urlName, setUrlName] = useState('') - const [url, setUrl] = useState('') - const urlOptions: urlOption[] = [ + const [urlName, setUrlName] = useState(''); + const [url, setUrl] = useState(''); + const urlOptions: { label: string; value: string }[] = [ { label: 'Crawler', value: 'crawler' }, // { label: 'Sitemap', value: 'sitemap' }, - { label: 'Link', value: 'url' }] - const [urlType, setUrlType] = useState(null) + { label: 'Link', value: 'url' }, + ]; + const [urlType, setUrlType] = useState<{ label: string; value: string }>({ + label: '', + value: '', + }); const [activeTab, setActiveTab] = useState('file'); const [files, setfiles] = useState([]); const [progress, setProgress] = useState<{ @@ -116,8 +68,9 @@ 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 @@ -210,7 +163,7 @@ export default function Upload({ }; const uploadRemote = () => { - console.log("here") + console.log('here'); const formData = new FormData(); formData.append('name', urlName); formData.append('user', 'local'); @@ -257,87 +210,115 @@ export default function Upload({ } else { view = ( <> -

Upload New Documentation

-
+

+ Upload New Documentation +

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

- Please upload .pdf, .txt, .rst, .docx, .md, .zip limited to 25mb + {activeTab === 'file' && ( + <> + setDocName(e.target.value)} + > +

+ + Name + +
+
+ + + Choose Files + +
+

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

+
+

+ Uploaded Files

-
-

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 -
- - ) - } + {files.map((file) => ( +

+ {file.name} +

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

None

+ )} +
+ + )} + {activeTab === 'remote' && ( + <> + + setUrlType(value) + } + /> + setUrlName(e.target.value)} + > +
+ + Name + +
+ setUrl(e.target.value)} + > +
+ + Link + +
+ + )}
@@ -347,7 +328,7 @@ export default function Upload({ setfiles([]); setModalState('INACTIVE'); }} - className="font-medium dark:text-light-gray cursor-pointer" + className="cursor-pointer font-medium dark:text-light-gray" > Cancel @@ -358,10 +339,11 @@ export default function Upload({ return (
-
+
{view}