Skip to content

Commit

Permalink
fix: The Web UX is intentionally not revealing references when clicke…
Browse files Browse the repository at this point in the history
…d to display (#974)

Co-authored-by: Arpit Gaur <gaurarpit@gmail.com>
  • Loading branch information
Rohini-Microsoft and gaurarpit authored May 29, 2024
1 parent c323d78 commit 70e2a50
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions code/frontend/src/components/Answer/Answer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo, useState } from "react";
import { useEffect, useMemo, useState, useRef } from "react";
import { useBoolean } from "@fluentui/react-hooks"
import { FontIcon, Stack, Text } from "@fluentui/react";

Expand Down Expand Up @@ -29,14 +29,17 @@ export const Answer = ({

const parsedAnswer = useMemo(() => parseAnswer(answer), [answer]);
const [chevronIsExpanded, setChevronIsExpanded] = useState(isRefAccordionOpen);

const refContainer = useRef<HTMLDivElement>(null);
const handleChevronClick = () => {
setChevronIsExpanded(!chevronIsExpanded);
toggleIsRefAccordionOpen();
};

useEffect(() => {
setChevronIsExpanded(isRefAccordionOpen);
if(chevronIsExpanded && refContainer.current){
refContainer.current.scrollIntoView({ behavior:'smooth'});
}
}, [isRefAccordionOpen]);

const createCitationFilepath = (citation: Citation, index: number, truncate: boolean = false) => {
Expand Down Expand Up @@ -104,11 +107,11 @@ export const Answer = ({

</Stack>
{chevronIsExpanded &&
<div style={{ marginTop: 8, display: "flex", flexDirection: "column", height: "100%", gap: "4px", maxWidth: "100%" }}>
<div ref={refContainer} style={{ marginTop: 8, display: "flex", flexDirection: "column", height: "100%", gap: "4px", maxWidth: "100%" }}>
{parsedAnswer.citations.map((citation, idx) => {
return (
<span title={createCitationFilepath(citation, ++idx)} key={idx} onClick={() => onCitationClicked(citation)} className={styles.citationContainer}>
<div className={styles.citation}>{idx}</div>
<div className={styles.citation} key={idx}>{idx}</div>
{createCitationFilepath(citation, idx, true)}
</span>);
})}
Expand Down

0 comments on commit 70e2a50

Please sign in to comment.