LibreChat/client/src/components/Chat/Input/Files/AttachFile.tsx
Danny Avila f307488dd4
✍️ refactor(Textarea): Optimize Text Input & Enhance UX (#2058)
* refactor(useDebouncedInput): make object as input arg and accept setter

* refactor(ChatForm/Textarea): consolidate textarea/form logic to one component, use react-hook-form, programmatically click send button instead of passing submitMessage, forwardRef and memoize SendButton

* refactor(Textarea): use Controller field value to avoid manual update of ref

* chore: remove forms provider

* chore: memoize AttachFile

* refactor(ChatForm/SendButton): only re-render SendButton when there is text input

* chore: make iconURL bigger

* chore: optimize Root/Nav

* refactor(SendButton): memoize disabled prop based on text

* chore: memoize Nav and ChatForm

* chore: remove textarea ref text on submission

* feat(EditMessage): Make Esc exit the edit mode and dismiss changes when editing a message

* style(MenuItem): Display the ☑️  icon only on the selected model
2024-03-11 09:18:10 -04:00

51 lines
1.4 KiB
TypeScript

import React from 'react';
import {
EModelEndpoint,
supportsFiles,
fileConfig as defaultFileConfig,
mergeFileConfig,
} from 'librechat-data-provider';
import { useGetFileConfig } from '~/data-provider';
import { AttachmentIcon } from '~/components/svg';
import { FileUpload } from '~/components/ui';
import { useFileHandling } from '~/hooks';
const AttachFile = ({
endpoint,
endpointType,
disabled = false,
}: {
endpoint: EModelEndpoint | '';
endpointType?: EModelEndpoint;
disabled?: boolean | null;
}) => {
const { handleFileChange } = useFileHandling();
const { data: fileConfig = defaultFileConfig } = useGetFileConfig({
select: (data) => mergeFileConfig(data),
});
const endpointFileConfig = fileConfig.endpoints[endpoint ?? ''];
if (!supportsFiles[endpointType ?? endpoint ?? ''] || endpointFileConfig?.disabled) {
return null;
}
return (
<div className="absolute bottom-2 left-2 md:bottom-3 md:left-4">
<FileUpload handleFileChange={handleFileChange} className="flex">
<button
disabled={!!disabled}
type="button"
className="btn relative p-0 text-black dark:text-white"
aria-label="Attach files"
style={{ padding: 0 }}
>
<div className="flex w-full items-center justify-center gap-2">
<AttachmentIcon />
</div>
</button>
</FileUpload>
</div>
);
};
export default React.memo(AttachFile);