import { useEffect, useRef, useState } from "react"; import { getClassOverride, twMerge } from "../utils"; import { ARTICLES_ID, ARTICLES_TITLE_ID, CHAT_ID, LAST_SEARCH_ID, SEE_MORE_BUTTON_BACKGROUND_ID, SEE_MORE_BUTTON_ID, } from "../utils/constants"; import Article from "../components/Article"; import SearchBar from "../components/SearchBar"; import LoadingSpinner from "../components/LoadingSpinner"; import { useConfiguration } from "../context/ConfigurationProvider"; import Shimmer from "../components/Shimmer"; import { useTracker } from "../context/TrackerProvider"; import Markdown from "react-markdown"; const Results = ({ shouldShow, chatResponse, articles, searchTerm, setSearchTerm, submitSearch, searchInputRef, lastSearchValue, isStreamActive, setStopStream, }: { shouldShow: boolean; chatResponse: string; articles: any[]; lastSearchValue: string; searchTerm: string; setSearchTerm: React.Dispatch>; submitSearch: (_value: string) => void; searchInputRef: React.RefObject; isStreamActive: boolean; setStopStream: (_: boolean) => void; }) => { const tracker = useTracker(); const configuration = useConfiguration(); const articlesRef = useRef(null); const [shouldShowMore, setShouldShowMore] = useState(false); const [articlesHeight, setArticlesHeight] = useState("180px"); useEffect(() => { if (articlesRef.current && articles.length > 0) { setArticlesHeight(articlesRef.current.scrollHeight + "px"); } }, [shouldShowMore, articles]); const filteredArticles = shouldShowMore ? articles : articles.slice(0, 3); return (

{lastSearchValue}

{configuration?.copy?.searchResultsTitle || "TOP RESULTS"}
{filteredArticles.length > 0 ? ( filteredArticles.map((article: any) => (
)) ) : ( )}
{!shouldShowMore && articles?.length > 0 && (
)}
{chatResponse?.length > 0 ? ( {chatResponse} ) : (
)}
) => setSearchTerm(e.target.value) } handleSubmit={(e: React.FormEvent) => { e.preventDefault(); if (!isStreamActive && searchTerm.length > 0) { submitSearch(searchTerm); } }} isStreamActive={isStreamActive} inputWrapClassNames="tb-sticky tb-bottom-6 tb-left-0 tb-bg-none" innerRef={searchInputRef} stopStream={(stop: boolean) => setStopStream(stop)} />
); }; export default Results;