mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-02 08:38:51 +01:00
chore: remove unused component and translation strings
This commit is contained in:
parent
fd29cbed4f
commit
c37e368d98
3 changed files with 0 additions and 195 deletions
|
|
@ -1,192 +0,0 @@
|
|||
import React, { useRef, useState, useMemo } from 'react';
|
||||
import { Upload, Folder } from 'lucide-react';
|
||||
import {
|
||||
Button,
|
||||
TooltipAnchor,
|
||||
AttachmentIcon,
|
||||
DropdownPopup,
|
||||
FileUpload,
|
||||
} from '@librechat/client';
|
||||
import { EToolResources } from 'librechat-data-provider';
|
||||
import type { ExtendedFile } from '~/common';
|
||||
import { usePromptFileHandling } from '~/hooks/Prompts';
|
||||
import PromptFileRow from './PromptFileRow';
|
||||
import * as Ariakit from '@ariakit/react';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
interface PromptFileUploadProps {
|
||||
files: ExtendedFile[];
|
||||
onFilesChange: (files: ExtendedFile[]) => void;
|
||||
onToolResourcesChange?: (toolResources: any) => void;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
variant?: 'button' | 'icon';
|
||||
showFileList?: boolean;
|
||||
}
|
||||
|
||||
const PromptFileUpload: React.FC<PromptFileUploadProps> = ({
|
||||
files,
|
||||
onFilesChange,
|
||||
onToolResourcesChange,
|
||||
disabled = false,
|
||||
className = '',
|
||||
variant = 'button',
|
||||
showFileList = true,
|
||||
}) => {
|
||||
const localize = useLocalize();
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const [isPopoverActive, setIsPopoverActive] = useState(false);
|
||||
const [toolResource, setToolResource] = useState<string>(EToolResources.file_search);
|
||||
|
||||
const { handleFileChange, promptFiles, getToolResources, areFilesReady, fileStats } =
|
||||
usePromptFileHandling({
|
||||
fileSetter: onFilesChange,
|
||||
initialFiles: files,
|
||||
});
|
||||
|
||||
// Update parent component when files change
|
||||
React.useEffect(() => {
|
||||
if (onToolResourcesChange && areFilesReady) {
|
||||
const toolResources = getToolResources();
|
||||
onToolResourcesChange(toolResources);
|
||||
}
|
||||
}, [promptFiles, areFilesReady, getToolResources, onToolResourcesChange]);
|
||||
|
||||
const handleUploadClick = (isImage?: boolean) => {
|
||||
if (isImage) {
|
||||
setToolResource(EToolResources.image_edit);
|
||||
} else {
|
||||
setToolResource(EToolResources.file_search);
|
||||
}
|
||||
if (fileInputRef.current) {
|
||||
fileInputRef.current.click();
|
||||
}
|
||||
};
|
||||
|
||||
const handleRemoveFile = (fileId: string) => {
|
||||
const updatedFiles = promptFiles.filter(
|
||||
(file) => file.temp_file_id !== fileId && file.file_id !== fileId,
|
||||
);
|
||||
onFilesChange(updatedFiles);
|
||||
};
|
||||
|
||||
const dropdownItems = useMemo(() => {
|
||||
return [
|
||||
{
|
||||
label: localize('com_ui_upload_file_search'),
|
||||
onClick: () => handleUploadClick(false),
|
||||
icon: <Folder className="icon-md" />,
|
||||
},
|
||||
{
|
||||
label: localize('com_ui_upload_ocr_text'),
|
||||
onClick: () => handleUploadClick(true),
|
||||
icon: <AttachmentIcon className="icon-md" />,
|
||||
},
|
||||
];
|
||||
}, [localize]);
|
||||
|
||||
const getButtonText = () => {
|
||||
if (fileStats.uploading > 0) {
|
||||
return `${localize('com_ui_uploading')} (${fileStats.uploading})`;
|
||||
}
|
||||
if (fileStats.total > 0) {
|
||||
return `${fileStats.total} ${localize('com_ui_files_attached')}`;
|
||||
}
|
||||
return localize('com_ui_attach_files');
|
||||
};
|
||||
|
||||
const menuTrigger = (
|
||||
<TooltipAnchor
|
||||
render={
|
||||
<Ariakit.MenuButton
|
||||
disabled={disabled}
|
||||
id="prompt-attach-file-menu-button"
|
||||
aria-label="Attach File Options"
|
||||
className={cn(
|
||||
'flex size-9 items-center justify-center rounded-full p-1 transition-colors hover:bg-surface-hover focus:outline-none focus:ring-2 focus:ring-primary focus:ring-opacity-50',
|
||||
)}
|
||||
>
|
||||
<div className="flex w-full items-center justify-center gap-2">
|
||||
<AttachmentIcon />
|
||||
</div>
|
||||
</Ariakit.MenuButton>
|
||||
}
|
||||
id="prompt-attach-file-menu-button"
|
||||
description={localize('com_sidepanel_attach_files')}
|
||||
disabled={disabled}
|
||||
/>
|
||||
);
|
||||
|
||||
if (variant === 'icon') {
|
||||
return (
|
||||
<>
|
||||
<FileUpload
|
||||
ref={fileInputRef}
|
||||
handleFileChange={(e) => {
|
||||
handleFileChange(e, toolResource);
|
||||
}}
|
||||
>
|
||||
<DropdownPopup
|
||||
menuId="prompt-attach-file-menu"
|
||||
className="overflow-visible"
|
||||
isOpen={isPopoverActive}
|
||||
setIsOpen={setIsPopoverActive}
|
||||
modal={true}
|
||||
unmountOnHide={true}
|
||||
trigger={menuTrigger}
|
||||
items={dropdownItems}
|
||||
iconClassName="mr-0"
|
||||
/>
|
||||
</FileUpload>
|
||||
|
||||
{showFileList && (
|
||||
<PromptFileRow files={promptFiles} onRemoveFile={handleRemoveFile} className="mt-2" />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<FileUpload
|
||||
ref={fileInputRef}
|
||||
handleFileChange={(e) => {
|
||||
handleFileChange(e, toolResource);
|
||||
}}
|
||||
>
|
||||
<DropdownPopup
|
||||
menuId="prompt-attach-file-menu-button"
|
||||
className="overflow-visible"
|
||||
isOpen={isPopoverActive}
|
||||
setIsOpen={setIsPopoverActive}
|
||||
modal={true}
|
||||
unmountOnHide={true}
|
||||
trigger={
|
||||
<Button
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
variant="outline"
|
||||
className={cn('flex items-center gap-2', fileStats.uploading > 0 && 'opacity-70')}
|
||||
>
|
||||
{fileStats.uploading > 0 ? (
|
||||
<Upload className="h-4 w-4 animate-pulse" />
|
||||
) : (
|
||||
<AttachmentIcon className="h-4 w-4" />
|
||||
)}
|
||||
{getButtonText()}
|
||||
</Button>
|
||||
}
|
||||
items={dropdownItems}
|
||||
iconClassName="mr-0"
|
||||
/>
|
||||
</FileUpload>
|
||||
|
||||
{showFileList && promptFiles.length > 0 && (
|
||||
<PromptFileRow files={promptFiles} onRemoveFile={handleRemoveFile} className="mt-3" />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PromptFileUpload;
|
||||
|
|
@ -1,2 +1 @@
|
|||
export { default as PromptFileUpload } from './PromptFileUpload';
|
||||
export { default as PromptFileRow } from './PromptFileRow';
|
||||
|
|
|
|||
|
|
@ -898,7 +898,6 @@
|
|||
"com_ui_file_token_limit": "File Token Limit",
|
||||
"com_ui_file_token_limit_desc": "Set maximum token limit for file processing to control costs and resource usage",
|
||||
"com_ui_files": "Files",
|
||||
"com_ui_files_attached": "files attached",
|
||||
"com_ui_files_info": "Attach files to enhance your prompt with additional context",
|
||||
"com_ui_filter_prompts": "Filter Prompts",
|
||||
"com_ui_filter_prompts_name": "Filter prompts by name",
|
||||
|
|
@ -1235,7 +1234,6 @@
|
|||
"com_ui_upload_ocr_text": "Upload as Text",
|
||||
"com_ui_upload_success": "Successfully uploaded file",
|
||||
"com_ui_upload_type": "Select Upload Type",
|
||||
"com_ui_uploading": "Uploading",
|
||||
"com_ui_remove_file": "Remove file",
|
||||
"com_ui_usage": "Usage",
|
||||
"com_ui_use_2fa_code": "Use 2FA Code Instead",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue