@@ -32,6 +32,7 @@ type TFileForm = {
3232
3333export const UploadFileForm = ( { setOpen, connection } : TFileForm ) => {
3434 const [ links , setLinks ] = useState < string [ ] > ( [ ] ) ;
35+ const [ text , setText ] = useState < string > ( "" )
3536 const [ files , setFiles ] = useState < File [ ] > ( [ ] ) ;
3637 const [ removedFiles , setRemovedFiles ] = useState < string [ ] > ( [ ] ) ;
3738 const [ pending , startTransition ] = useTransition ( ) ;
@@ -47,6 +48,7 @@ export const UploadFileForm = ({ setOpen, connection }: TFileForm) => {
4748 removedFiles . forEach ( ( fileName ) => data . append ( "removedFiles" , fileName ) ) ;
4849 } else {
4950 data . set ( "service" , "DIRECT_UPLOAD" ) ;
51+ if ( text ) data . append ( "texts" , text )
5052 }
5153 const res = await setConnectionConfig ( EMPTY_FORM_STATE , data )
5254 if ( res . status === "SUCCESS" ) {
@@ -109,6 +111,7 @@ export const UploadFileForm = ({ setOpen, connection }: TFileForm) => {
109111 < DataInput
110112 files = { files }
111113 setFiles = { setFiles }
114+ setText = { setText }
112115 links = { links }
113116 setLinks = { setLinks }
114117 currentFiles = { connection ? connection . files . map ( f => f . name ) : [ ] }
@@ -139,12 +142,13 @@ type TDataInput = {
139142 setFiles : Dispatch < SetStateAction < File [ ] > > ;
140143 links : string [ ] ;
141144 setLinks : Dispatch < SetStateAction < string [ ] > > ;
145+ setText : Dispatch < SetStateAction < string > > ;
142146 currentFiles : string [ ] ;
143147 removedFiles : string [ ] ;
144148 setRemovedFiles : Dispatch < SetStateAction < string [ ] > > ;
145149} ;
146150
147- export const DataInput = ( { files, setFiles, links, setLinks, currentFiles, removedFiles, setRemovedFiles } : TDataInput ) => {
151+ export const DataInput = ( { files, setFiles, links, setLinks, currentFiles, removedFiles, setRemovedFiles, setText } : TDataInput ) => {
148152 const inputFile = useRef < HTMLInputElement > ( null ) ;
149153 const [ invalidLinks , setInvalidLinks ] = useState < string [ ] > ( [ ] ) ;
150154 const [ invalidFile , setInvalidFile ] = useState ( "" ) ;
@@ -160,12 +164,12 @@ export const DataInput = ({ files, setFiles, links, setLinks, currentFiles, remo
160164 e . preventDefault ( ) ;
161165 const droppedFiles = Array . from ( e . dataTransfer . files ) ;
162166 const validFiles = droppedFiles . filter ( ( f ) => {
163- if ( f . type !== "application/pdf" ) {
164- setInvalidFile ( `${ f . name } is not supported. Please upload PDFs only.` ) ;
167+ if ( f . type !== "application/pdf" && f . type !== "text/plain" && f . name . endsWith ( ".txt" ) ) {
168+ setInvalidFile ( `${ f . name } is not supported. Please upload PDFs only.` ) ;
165169 return false ;
166170 }
167171 if ( currentFiles . includes ( f . name ) ) {
168- setInvalidFile ( `${ f . name } is already added` ) ;
172+ setInvalidFile ( `${ f . name } is already added` ) ;
169173 return false ;
170174 }
171175 return true ;
@@ -177,8 +181,8 @@ export const DataInput = ({ files, setFiles, links, setLinks, currentFiles, remo
177181 e . preventDefault ( ) ;
178182 const selectedFiles = Array . from ( e . target . files || [ ] ) ;
179183 const validFiles = selectedFiles . filter ( ( f ) => {
180- if ( f . type !== "application/pdf" ) {
181- setInvalidFile ( `${ f . name } is not supported. Please upload PDFs only.` ) ;
184+ if ( f . type !== "application/pdf" && f . type !== "text/plain" && f . name . endsWith ( ".txt" ) ) {
185+ setInvalidFile ( `${ f . name } is not supported. Please upload PDFs or .txt only.` ) ;
182186 return false ;
183187 }
184188 if ( currentFiles . includes ( f . name ) ) {
@@ -224,22 +228,25 @@ export const DataInput = ({ files, setFiles, links, setLinks, currentFiles, remo
224228 return (
225229 < div className = "flex-1 flex flex-col h-full" >
226230 < Tabs defaultValue = "file" className = "w-full h-full flex flex-col" >
227- < TabsList className = "grid w-full grid-cols-2 " >
231+ < TabsList className = "grid w-full grid-cols-3 " >
228232 < TabsTrigger value = "file" className = "gap-2" >
229233 < UploadCloud className = "h-5 w-5" />
230- Upload Files
234+ Files
235+ </ TabsTrigger >
236+ < TabsTrigger data-test = { "btn-texts" } value = "texts" className = "gap-2" >
237+ < Link className = "h-5 w-5" />
238+ Texts
231239 </ TabsTrigger >
232240 < TabsTrigger value = "link" className = "gap-2" >
233241 < Link className = "h-5 w-5" />
234- Paste Links
242+ Links
235243 </ TabsTrigger >
236244 </ TabsList >
237-
238245 < TabsContent value = "file" className = "flex-1" >
239246 < Card className = "flex flex-col" >
240247 < CardHeader >
241- < CardTitle > Upload your PDFs </ CardTitle >
242- < CardDescription > Only PDF files are supported.</ CardDescription >
248+ < CardTitle > Upload your Files </ CardTitle >
249+ < CardDescription > Only PDF,txt files are supported.</ CardDescription >
243250 { invalidFile && (
244251 < div className = "mt-2 text-red-600 text-sm" >
245252 < AlertCircle className = "h-4 w-4 inline-block mr-1" />
@@ -254,14 +261,13 @@ export const DataInput = ({ files, setFiles, links, setLinks, currentFiles, remo
254261 className = "border-2 border-dashed border-gray-300 rounded-xl p-5 text-center hover:border-teal-500 transition-colors flex flex-col justify-center"
255262 >
256263 < UploadCloud className = "h-12 w-12 mx-auto text-gray-400 mb-4" />
257- < p className = "text-gray-600 mb-2" > Drag & drop PDF files here </ p >
264+ < p className = "text-gray-600 mb-2" > Drag & drop PDF , txt files here </ p >
258265 < p className = "text-sm text-gray-500 mb-4" > or</ p >
259266 < input
260267 type = "file"
261268 name = "fileUpload"
262269 ref = { inputFile }
263270 multiple
264- accept = "application/pdf"
265271 onChange = { addNewFile }
266272 className = { env === 'TEST' ? "block" : "hidden" }
267273 id = "file-upload"
@@ -295,8 +301,8 @@ export const DataInput = ({ files, setFiles, links, setLinks, currentFiles, remo
295301 < TabsContent value = "link" className = "flex-1" >
296302 < Card className = "flex flex-col" >
297303 < CardHeader >
298- < CardTitle > Provide PDF URLs</ CardTitle >
299- < CardDescription > Enter valid HTTP/HTTPS links to PDF files.</ CardDescription >
304+ < CardTitle > Provide PDF, txt URLs</ CardTitle >
305+ < CardDescription > Enter valid HTTP/HTTPS links to PDF, txt files.</ CardDescription >
300306 </ CardHeader >
301307 < CardContent >
302308 < div className = "space-y-4" >
@@ -324,6 +330,25 @@ export const DataInput = ({ files, setFiles, links, setLinks, currentFiles, remo
324330 </ CardContent >
325331 </ Card >
326332 </ TabsContent >
333+
334+ < TabsContent value = "texts" className = "flex-1" >
335+ < Card className = "flex flex-col" >
336+ < CardHeader >
337+ < CardTitle > Provide Direcct Text</ CardTitle >
338+ < CardDescription > Enter Text</ CardDescription >
339+ </ CardHeader >
340+ < CardContent >
341+ < div className = "space-y-4" >
342+ < Textarea
343+ onChange = { ( e ) => setText ( e . target . value ) }
344+ name = "text"
345+ placeholder = "Enter direct text"
346+ className = { `w-full h-60 resize-none` }
347+ />
348+ </ div >
349+ </ CardContent >
350+ </ Card >
351+ </ TabsContent >
327352 </ Tabs >
328353 </ div >
329354 ) ;
0 commit comments