From 5560546b4f1bea186759ba73bf50059f22e1b128 Mon Sep 17 00:00:00 2001 From: Koshik Debanath <48962097+kowshik24@users.noreply.github.com> Date: Sun, 30 Mar 2025 16:06:34 +0600 Subject: [PATCH] Add ability to copy references from Web App Related to #1021 Add a "Copy References" button to the references pane in the web app. * **ReferencePanel Component** - Import `Clipboard` icon and `Button` component. - Add a "Copy References" button to the `ReferencePanel` component. - Implement functionality to copy all references (notes, online, and code) as a markdown bullet list. - Update the `TeaserReferencesSection` component to include the "Copy References" button. * **ChatMessage Component** - Import `Clipboard` icon. - Add a "Copy References" button to the `ChatMessage` component. - Implement functionality to copy all references (notes, online, and code) as a markdown bullet list. --- .../components/chatMessage/chatMessage.tsx | 29 ++++++++++++++++++- .../referencePanel/referencePanel.tsx | 27 ++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/interface/web/app/components/chatMessage/chatMessage.tsx b/src/interface/web/app/components/chatMessage/chatMessage.tsx index 5d87f7ea2..8882ef233 100644 --- a/src/interface/web/app/components/chatMessage/chatMessage.tsx +++ b/src/interface/web/app/components/chatMessage/chatMessage.tsx @@ -31,11 +31,12 @@ import { Shapes, Trash, Toolbox, + Clipboard, } from "@phosphor-icons/react"; import DOMPurify from "dompurify"; import { InlineLoading } from "../loading/loading"; -import { convertColorToTextClass } from "@/app/common/colorUtils"; +import { convertColorToTextClass } from "@/app.common/colorUtils"; import { AgentData } from "@/app/components/agentCard/agentCard"; import renderMathInElement from "katex/contrib/auto-render"; @@ -678,6 +679,22 @@ const ChatMessage = forwardRef((props, ref) => props.chatMessage.codeContext, ); + const copyReferencesToClipboard = () => { + const allReferencesMarkdown = [ + ...allReferences.notesReferenceCardData.map( + (note) => `- [${note.title}](#)`, + ), + ...allReferences.onlineReferenceCardData.map( + (online) => `- [${online.title}](${online.link})`, + ), + ...allReferences.codeReferenceCardData.map( + (code) => `- [Code Reference](#)`, + ), + ].join("\n"); + + navigator.clipboard.writeText(allReferencesMarkdown); + }; + return (
((props, ref) => /> )} + {props.chatMessage.by === "khoj" && (props.chatMessage.intent ? ( { + const allReferences = [ + ...props.notesReferenceCardData.map( + (note) => `- [${note.title}](#)`, + ), + ...props.onlineReferenceCardData.map( + (online) => `- [${online.title}](${online.link})`, + ), + ...props.codeReferenceCardData.map( + (code) => `- [Code Reference](#)`, + ), + ].join("\n"); + + navigator.clipboard.writeText(allReferences); + }; + return ( @@ -642,6 +659,14 @@ export default function ReferencePanel(props: ReferencePanelDataProps) { References View all references for this response +
{props.codeReferenceCardData.map((code, index) => {