Skip to content

Commit

Permalink
Fix duplicate copy warning alert
Browse files Browse the repository at this point in the history
- It was being added to the whole page everytime an answer was returned
- This meant that if **any** content on the page was copied the alert was
  being shown multiple times based on how many answers there had been
- This change will mean the alert will now only be shown when an answer
  is copied and only once

Required by #215
  • Loading branch information
adamdougal committed Jan 23, 2024
1 parent ff9ff58 commit 5197f25
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions code/app/frontend/src/components/Answer/Answer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import supersub from 'remark-supersub'
interface Props {
answer: AskResponse;
onCitationClicked: (citedDocument: Citation) => void;
index: Number;
}

export const Answer = ({
answer,
onCitationClicked
onCitationClicked,
index,
}: Props) => {
const [isRefAccordionOpen, { toggle: toggleIsRefAccordionOpen }] = useBoolean(false);
const filePathTruncationLimit = 50;
Expand Down Expand Up @@ -57,15 +59,16 @@ export const Answer = ({
const handleCopy = () => {
alert("Please consider where you paste this content.");
};
document.addEventListener("copy", handleCopy);
var messageBox = document.getElementById("message-" + index);
messageBox?.addEventListener("copy", handleCopy);
return () => {
document.removeEventListener("copy", handleCopy);
messageBox?.removeEventListener("copy", handleCopy);
};
}, []);

return (
<>
<Stack className={styles.answerContainer}>
<Stack className={styles.answerContainer} id={"message-" + index}>
<Stack.Item grow>
<ReactMarkdown
remarkPlugins={[remarkGfm, supersub]}
Expand Down
1 change: 1 addition & 0 deletions code/app/frontend/src/pages/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ const Chat = () => {
: [],
}}
onCitationClicked={(c) => onShowCitation(c)}
index={index}
/>
</div>
) : null}
Expand Down

0 comments on commit 5197f25

Please sign in to comment.