11import filenamify from 'filenamify' ;
2- import { useEffect , useState } from 'react' ;
2+ import { useEffect , useState , useMemo , useCallback } from 'react' ;
33import type { TConversation } from 'librechat-data-provider' ;
44import { OGDialog , Button , Input , Label , Checkbox , Dropdown } from '~/components/ui' ;
55import OGDialogTemplate from '~/components/ui/OGDialogTemplate' ;
66import { useLocalize , useExportConversation } from '~/hooks' ;
77
8+ const TYPE_OPTIONS = [
9+ { value : 'screenshot' , label : 'screenshot (.png)' } ,
10+ { value : 'text' , label : 'text (.txt)' } ,
11+ { value : 'markdown' , label : 'markdown (.md)' } ,
12+ { value : 'json' , label : 'json (.json)' } ,
13+ { value : 'csv' , label : 'csv (.csv)' } ,
14+ ] ;
15+
816export default function ExportModal ( {
917 open,
1018 onOpenChange,
@@ -21,20 +29,12 @@ export default function ExportModal({
2129 const localize = useLocalize ( ) ;
2230
2331 const [ filename , setFileName ] = useState ( '' ) ;
24- const [ type , setType ] = useState ( 'Select a file type ') ;
32+ const [ type , setType ] = useState < string > ( 'screenshot ') ;
2533
2634 const [ includeOptions , setIncludeOptions ] = useState < boolean | 'indeterminate' > ( true ) ;
2735 const [ exportBranches , setExportBranches ] = useState < boolean | 'indeterminate' > ( false ) ;
2836 const [ recursive , setRecursive ] = useState < boolean | 'indeterminate' > ( true ) ;
2937
30- const typeOptions = [
31- { value : 'screenshot' , label : 'screenshot (.png)' } ,
32- { value : 'text' , label : 'text (.txt)' } ,
33- { value : 'markdown' , label : 'markdown (.md)' } ,
34- { value : 'json' , label : 'json (.json)' } ,
35- { value : 'csv' , label : 'csv (.csv)' } ,
36- ] ;
37-
3838 useEffect ( ( ) => {
3939 if ( ! open && triggerRef && triggerRef . current ) {
4040 triggerRef . current . focus ( ) ;
@@ -49,17 +49,19 @@ export default function ExportModal({
4949 setRecursive ( true ) ;
5050 } , [ conversation ?. title , open ] ) ;
5151
52- const _setType = ( newType : string ) => {
53- const exportBranchesSupport = newType === 'json' || newType === 'csv' || newType === 'webpage' ;
54- const exportOptionsSupport = newType !== 'csv' && newType !== 'screenshot' ;
55-
56- setExportBranches ( exportBranchesSupport ) ;
57- setIncludeOptions ( exportOptionsSupport ) ;
52+ const handleTypeChange = useCallback ( ( newType : string ) => {
53+ const branches = newType === 'json' || newType === 'csv' || newType === 'webpage' ;
54+ const options = newType !== 'csv' && newType !== 'screenshot' ;
55+ setExportBranches ( branches ) ;
56+ setIncludeOptions ( options ) ;
5857 setType ( newType ) ;
59- } ;
58+ } , [ ] ) ;
6059
61- const exportBranchesSupport = type === 'json' || type === 'csv' || type === 'webpage' ;
62- const exportOptionsSupport = type !== 'csv' && type !== 'screenshot' ;
60+ const exportBranchesSupport = useMemo (
61+ ( ) => type === 'json' || type === 'csv' || type === 'webpage' ,
62+ [ type ] ,
63+ ) ;
64+ const exportOptionsSupport = useMemo ( ( ) => type !== 'csv' && type !== 'screenshot' , [ type ] ) ;
6365
6466 const { exportConversation } = useExportConversation ( {
6567 conversation,
@@ -94,7 +96,13 @@ export default function ExportModal({
9496 < Label htmlFor = "type" className = "text-left text-sm font-medium" >
9597 { localize ( 'com_nav_export_type' ) }
9698 </ Label >
97- < Dropdown value = { type } onChange = { _setType } options = { typeOptions } portal = { false } />
99+ < Dropdown
100+ value = { type }
101+ onChange = { handleTypeChange }
102+ options = { TYPE_OPTIONS }
103+ className = "z-50"
104+ portal = { false }
105+ />
98106 </ div >
99107 </ div >
100108 < div className = "grid w-full gap-6 sm:grid-cols-2" >
@@ -108,7 +116,6 @@ export default function ExportModal({
108116 id = "includeOptions"
109117 disabled = { ! exportOptionsSupport }
110118 checked = { includeOptions }
111- className = "focus:ring-opacity-20 dark:border-gray-500 dark:bg-gray-700 dark:text-gray-50 dark:focus:ring-gray-600 dark:focus:ring-opacity-50 dark:focus:ring-offset-0"
112119 onCheckedChange = { setIncludeOptions }
113120 />
114121 < label
@@ -131,7 +138,6 @@ export default function ExportModal({
131138 id = "exportBranches"
132139 disabled = { ! exportBranchesSupport }
133140 checked = { exportBranches }
134- className = "focus:ring-opacity-20 dark:border-gray-500 dark:bg-gray-700 dark:text-gray-50 dark:focus:ring-gray-600 dark:focus:ring-opacity-50 dark:focus:ring-offset-0"
135141 onCheckedChange = { setExportBranches }
136142 />
137143 < label
@@ -150,12 +156,7 @@ export default function ExportModal({
150156 { localize ( 'com_nav_export_recursive_or_sequential' ) }
151157 </ Label >
152158 < div className = "flex h-[40px] w-full items-center space-x-3" >
153- < Checkbox
154- id = "recursive"
155- checked = { recursive }
156- className = "focus:ring-opacity-20 dark:border-gray-500 dark:bg-gray-700 dark:text-gray-50 dark:focus:ring-gray-600 dark:focus:ring-opacity-50 dark:focus:ring-offset-0"
157- onCheckedChange = { setRecursive }
158- />
159+ < Checkbox id = "recursive" checked = { recursive } onCheckedChange = { setRecursive } />
159160 < label
160161 htmlFor = "recursive"
161162 className = "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 dark:text-gray-50"
0 commit comments