feat: Add 'EnterToSend' Option & Update Br. Translation 🇧🇷 (#2413)

* chore: Add EnterToSend, Translation Portuguese Brazilian Update

* Inverted selection and corrected translation

* fix: removed Trailing spaces not allowed

* feat: Refactor key event handler & updated translations

* fix: removed return; & updated files translations

* fix: duplicate switchs on General.tsx

* fix: added again switch

* refactor(useTextarea): limit refactoring of handleKeyDown

* refactor: correct keyDown handler and add English localization

---------

Co-authored-by: Raí Santos <140329135+itzraiss@users.noreply.github.com>
Co-authored-by: Raí Santos <raimorningstarchristus@gmail.com>
This commit is contained in:
Danny Avila 2024-04-14 19:06:20 -04:00 committed by GitHub
parent f380f261a5
commit d2d9ac0280
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 966 additions and 896 deletions

View file

@ -1,6 +1,7 @@
import debounce from 'lodash/debounce';
import React, { useEffect, useRef, useCallback } from 'react';
import { useRecoilValue } from 'recoil';
import { EModelEndpoint } from 'librechat-data-provider';
import React, { useEffect, useRef, useCallback } from 'react';
import type { TEndpointOption } from 'librechat-data-provider';
import type { UseFormSetValue } from 'react-hook-form';
import type { KeyboardEvent } from 'react';
@ -10,6 +11,7 @@ import useGetSender from '~/hooks/Conversations/useGetSender';
import useFileHandling from '~/hooks/Files/useFileHandling';
import { useChatContext } from '~/Providers/ChatContext';
import useLocalize from '~/hooks/useLocalize';
import store from '~/store';
type KeyEvent = KeyboardEvent<HTMLTextAreaElement>;
@ -27,6 +29,7 @@ export default function useTextarea({
disabled?: boolean;
}) {
const assistantMap = useAssistantsMapContext();
const enterToSend = useRecoilValue(store.enterToSend);
const {
conversation,
isSubmitting,
@ -134,25 +137,34 @@ export default function useTextarea({
assistantMap,
]);
const handleKeyDown = (e: KeyEvent) => {
if (e.key === 'Enter' && isSubmitting) {
return;
}
const handleKeyDown = useCallback(
(e: KeyEvent) => {
if (e.key === 'Enter' && isSubmitting) {
return;
}
const isNonShiftEnter = e.key === 'Enter' && !e.shiftKey;
const isNonShiftEnter = e.key === 'Enter' && !e.shiftKey;
if (isNonShiftEnter && filesLoading) {
e.preventDefault();
}
if (isNonShiftEnter && filesLoading) {
e.preventDefault();
}
if (isNonShiftEnter) {
e.preventDefault();
}
if (isNonShiftEnter) {
e.preventDefault();
}
if (isNonShiftEnter && !isComposing?.current) {
submitButtonRef.current?.click();
}
};
if (e.key === 'Enter' && !enterToSend && textAreaRef.current) {
insertTextAtCursor(textAreaRef.current, '\n');
forceResize(textAreaRef);
return;
}
if (isNonShiftEnter && !isComposing?.current) {
submitButtonRef.current?.click();
}
},
[isSubmitting, filesLoading, enterToSend, textAreaRef, submitButtonRef],
);
const handleKeyUp = (e: KeyEvent) => {
const target = e.target as HTMLTextAreaElement;