import filenamify from 'filenamify'; import { useEffect, useState, useMemo, useCallback } from 'react'; import { OGDialogTemplate, OGDialog, Button, Input, Label, Checkbox, Dropdown, } from '@librechat/client'; import type { TConversation } from 'librechat-data-provider'; import { useLocalize, useExportConversation } from '~/hooks'; const TYPE_OPTIONS = [ { value: 'screenshot', label: 'screenshot (.png)' }, { value: 'text', label: 'text (.txt)' }, { value: 'markdown', label: 'markdown (.md)' }, { value: 'json', label: 'json (.json)' }, { value: 'csv', label: 'csv (.csv)' }, ]; export default function ExportModal({ open, onOpenChange, conversation, triggerRef, children, }: { open: boolean; conversation: TConversation | null; onOpenChange: React.Dispatch>; triggerRef?: React.RefObject; children?: React.ReactNode; }) { const localize = useLocalize(); const [filename, setFileName] = useState(''); const [type, setType] = useState('screenshot'); const [includeOptions, setIncludeOptions] = useState(true); const [exportBranches, setExportBranches] = useState(false); const [recursive, setRecursive] = useState(true); useEffect(() => { if (!open && triggerRef && triggerRef.current) { triggerRef.current.focus(); } }, [open, triggerRef]); useEffect(() => { setFileName(filenamify(String(conversation?.title ?? 'file'))); setType('screenshot'); setIncludeOptions(true); setExportBranches(false); setRecursive(true); }, [conversation?.title, open]); const handleTypeChange = useCallback((newType: string) => { const branches = newType === 'json' || newType === 'csv' || newType === 'webpage'; const options = newType !== 'csv' && newType !== 'screenshot'; setExportBranches(branches); setIncludeOptions(options); setType(newType); }, []); const exportBranchesSupport = useMemo( () => type === 'json' || type === 'csv' || type === 'webpage', [type], ); const exportOptionsSupport = useMemo(() => type !== 'csv' && type !== 'screenshot', [type]); const { exportConversation } = useExportConversation({ conversation, filename: filenamify(filename), type, includeOptions, exportBranches, recursive, }); return ( {children}
setFileName(e.target.value || '')} placeholder={localize('com_nav_export_filename_placeholder')} />
{type === 'json' ? (
) : null}
} buttons={ <> } selection={undefined} />
); }