update search detail when results change

This commit is contained in:
Josh Hawkins 2024-09-24 07:03:14 -05:00
parent a298b395dd
commit aff5b3713d

View File

@ -23,6 +23,7 @@ import useKeyboardListener, {
import scrollIntoView from "scroll-into-view-if-needed";
import InputWithTags from "@/components/input/InputWithTags";
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
import { isEqual } from "lodash";
type SearchViewProps = {
search: string;
@ -140,6 +141,21 @@ export default function SearchView({
setSelectedIndex(index);
}, []);
// update search detail when results change
useEffect(() => {
if (searchDetail && searchResults) {
const flattenedResults = searchResults.flat();
const updatedSearchDetail = flattenedResults.find(
(result) => result.id === searchDetail.id,
);
if (updatedSearchDetail && !isEqual(updatedSearchDetail, searchDetail)) {
setSearchDetail(updatedSearchDetail);
}
}
}, [searchResults, searchDetail]);
// confidence score - probably needs tweaking
const zScoreToConfidence = (score: number, source: string) => {