import filenamify from 'filenamify'; import { useEffect, useState } from 'react'; import type { TConversation } from 'librechat-data-provider'; import { Dialog, DialogButton, Input, Label, Checkbox, Dropdown } from '~/components/ui'; import { useLocalize, useExportConversation } from '~/hooks'; import DialogTemplate from '~/components/ui/DialogTemplate'; import { cn, defaultTextProps } from '~/utils'; export default function ExportModal({ open, onOpenChange, conversation, }: { open: boolean; onOpenChange: (open: boolean) => void; conversation: TConversation | null; }) { const localize = useLocalize(); const [filename, setFileName] = useState(''); const [type, setType] = useState('Select a file type'); const [includeOptions, setIncludeOptions] = useState(true); const [exportBranches, setExportBranches] = useState(false); const [recursive, setRecursive] = useState(true); const typeOptions = [ { value: 'screenshot', display: 'screenshot (.png)' }, { value: 'text', display: 'text (.txt)' }, { value: 'markdown', display: 'markdown (.md)' }, { value: 'json', display: 'json (.json)' }, { value: 'csv', display: 'csv (.csv)' }, ]; useEffect(() => { setFileName(filenamify(String(conversation?.title || 'file'))); setType('screenshot'); setIncludeOptions(true); setExportBranches(false); setRecursive(true); }, [conversation?.title, open]); const _setType = (newType: string) => { const exportBranchesSupport = newType === 'json' || newType === 'csv' || newType === 'webpage'; const exportOptionsSupport = newType !== 'csv' && newType !== 'screenshot'; setExportBranches(exportBranchesSupport); setIncludeOptions(exportOptionsSupport); setType(newType); }; const exportBranchesSupport = type === 'json' || type === 'csv' || type === 'webpage'; const exportOptionsSupport = type !== 'csv' && type !== 'screenshot'; const { exportConversation } = useExportConversation({ conversation, filename, type, includeOptions, exportBranches, recursive, }); return (
setFileName(filenamify(e.target.value || ''))} placeholder={localize('com_nav_export_filename_placeholder')} className={cn( defaultTextProps, 'flex h-10 max-h-10 w-full resize-none px-3 py-2', )} />
{type === 'json' ? (
) : null}
} buttons={ <> {localize('com_endpoint_export')} } selection={undefined} />
); }