Fix: citation handling in ChatItem component (#2524)

This pull request fixes the citation handling in the ChatItem component.
Previously, if the citation did not contain the word "Content:", the
component would throw an error. This PR adds a check for the presence of
"Content:" in the citation and handles it accordingly.
This commit is contained in:
Stan Girard 2024-05-01 14:40:20 +02:00 committed by GitHub
parent d2cab9332f
commit 365ac1ab87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,8 +11,14 @@ export const Citation = ({ citation }: CitationProps): JSX.Element => {
const [isExpanded, setIsExpanded] = useState<boolean>(false);
const contentIndex = citation.indexOf("Content:");
const cleanedCitation = citation.substring(contentIndex);
const [, content] = cleanedCitation.split("Content:");
let cleanedCitation, content;
if (contentIndex !== -1) {
cleanedCitation = citation.substring(contentIndex);
[, content] = cleanedCitation.split("Content:");
} else {
content = citation;
}
const handleIconClick = (event: React.MouseEvent) => {
event.stopPropagation();