-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): citations & sources (#2523)
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate): --------- Co-authored-by: Stan Girard <girard.stanislas@gmail.com>
- Loading branch information
1 parent
2ed446f
commit d2cab93
Showing
15 changed files
with
313 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...ponents/ChatItem/QADisplay/components/MessageRow/components/Citation/Citation.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
@use "@/styles/Radius.module.scss"; | ||
@use "@/styles/Spacings.module.scss"; | ||
@use "@/styles/Typography.module.scss"; | ||
|
||
.citation_wrapper { | ||
padding: Spacings.$spacing03; | ||
border-radius: Radius.$normal; | ||
background-color: var(--background-special-0); | ||
width: 100%; | ||
font-size: Typography.$tiny; | ||
font-style: italic; | ||
cursor: pointer; | ||
|
||
.citation_header { | ||
display: flex; | ||
justify-content: space-between; | ||
overflow: hidden; | ||
width: 100%; | ||
|
||
.citation { | ||
&.folded { | ||
@include Typography.EllipsisOverflow; | ||
} | ||
} | ||
|
||
.icon { | ||
visibility: hidden; | ||
} | ||
} | ||
|
||
&:hover { | ||
background-color: var(--background-special-1); | ||
|
||
.icon { | ||
visibility: visible; | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ogue/components/ChatItem/QADisplay/components/MessageRow/components/Citation/Citation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useState } from "react"; | ||
|
||
import Icon from "@/lib/components/ui/Icon/Icon"; | ||
|
||
import styles from "./Citation.module.scss"; | ||
|
||
type CitationProps = { | ||
citation: string; | ||
}; | ||
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:"); | ||
|
||
const handleIconClick = (event: React.MouseEvent) => { | ||
event.stopPropagation(); | ||
setIsExpanded(!isExpanded); | ||
}; | ||
|
||
return ( | ||
<div | ||
className={styles.citation_wrapper} | ||
onClick={(event) => handleIconClick(event)} | ||
> | ||
<div className={styles.citation_header}> | ||
<span | ||
className={`${styles.citation} ${!isExpanded ? styles.folded : ""}`} | ||
> | ||
{content} | ||
</span> | ||
<div className={styles.icon}> | ||
<Icon | ||
name={isExpanded ? "fold" : "unfold"} | ||
size="normal" | ||
color="black" | ||
handleHover={true} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.