mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
📋 feat: Accumulate Text Parts to Clipboard for Assistant Outputs (#1847)
This commit is contained in:
parent
64e81392f2
commit
542494fad6
1 changed files with 25 additions and 11 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import copy from 'copy-to-clipboard';
|
import copy from 'copy-to-clipboard';
|
||||||
import { useEffect, useRef, useCallback } from 'react';
|
import { useEffect, useRef, useCallback } from 'react';
|
||||||
import { EModelEndpoint } from 'librechat-data-provider';
|
import { EModelEndpoint, ContentTypes } from 'librechat-data-provider';
|
||||||
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
|
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
|
||||||
import type { TMessage } from 'librechat-data-provider';
|
import type { TMessage } from 'librechat-data-provider';
|
||||||
import type { TMessageProps } from '~/common';
|
import type { TMessageProps } from '~/common';
|
||||||
|
|
@ -25,7 +25,7 @@ export default function useMessageHelpers(props: TMessageProps) {
|
||||||
} = useChatContext();
|
} = useChatContext();
|
||||||
const assistantMap = useAssistantsMapContext();
|
const assistantMap = useAssistantsMapContext();
|
||||||
|
|
||||||
const { text, children, messageId = null, isCreatedByUser } = message ?? {};
|
const { text, content, children, messageId = null, isCreatedByUser } = message ?? {};
|
||||||
const edit = messageId === currentEditId;
|
const edit = messageId === currentEditId;
|
||||||
const isLast = !children?.length;
|
const isLast = !children?.length;
|
||||||
|
|
||||||
|
|
@ -46,8 +46,10 @@ export default function useMessageHelpers(props: TMessageProps) {
|
||||||
}
|
}
|
||||||
}, [isLast, message, setLatestMessage, conversation?.conversationId]);
|
}, [isLast, message, setLatestMessage, conversation?.conversationId]);
|
||||||
|
|
||||||
const enterEdit = (cancel?: boolean) =>
|
const enterEdit = useCallback(
|
||||||
setCurrentEditId && setCurrentEditId(cancel ? -1 : messageId);
|
(cancel?: boolean) => setCurrentEditId && setCurrentEditId(cancel ? -1 : messageId),
|
||||||
|
[messageId, setCurrentEditId],
|
||||||
|
);
|
||||||
|
|
||||||
const handleScroll = useCallback(() => {
|
const handleScroll = useCallback(() => {
|
||||||
if (isSubmitting) {
|
if (isSubmitting) {
|
||||||
|
|
@ -79,14 +81,26 @@ export default function useMessageHelpers(props: TMessageProps) {
|
||||||
regenerate(message);
|
regenerate(message);
|
||||||
};
|
};
|
||||||
|
|
||||||
const copyToClipboard = (setIsCopied: React.Dispatch<React.SetStateAction<boolean>>) => {
|
const copyToClipboard = useCallback(
|
||||||
|
(setIsCopied: React.Dispatch<React.SetStateAction<boolean>>) => {
|
||||||
setIsCopied(true);
|
setIsCopied(true);
|
||||||
copy(text ?? '');
|
let messageText = text ?? '';
|
||||||
|
if (content) {
|
||||||
|
messageText = content.reduce((acc, curr, i) => {
|
||||||
|
if (curr.type === ContentTypes.TEXT) {
|
||||||
|
return acc + curr.text.value + (i === content.length - 1 ? '' : '\n');
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, '');
|
||||||
|
}
|
||||||
|
copy(messageText ?? '');
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setIsCopied(false);
|
setIsCopied(false);
|
||||||
}, 3000);
|
}, 3000);
|
||||||
};
|
},
|
||||||
|
[text, content],
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ask,
|
ask,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue