import React, { useState, useEffect } from "react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faChevronRight, faChevronDown, } from "@fortawesome/free-solid-svg-icons"; import { formatTime } from "../../lib/time"; import ScrollToBottom from "./scrollToBottom"; import { Topic } from "./webSocketTypes"; import { generateHighContrastColor } from "../../lib/utils"; type TopicListProps = { topics: Topic[]; useActiveTopic: [ Topic | null, React.Dispatch>, ]; autoscroll: boolean; }; export function TopicList({ topics, useActiveTopic, autoscroll, }: TopicListProps) { const [activeTopic, setActiveTopic] = useActiveTopic; const [autoscrollEnabled, setAutoscrollEnabled] = useState(true); useEffect(() => { if (autoscroll && autoscrollEnabled) scrollToBottom(); }, [topics.length]); const scrollToBottom = () => { const topicsDiv = document.getElementById("topics-div"); if (topicsDiv) topicsDiv.scrollTop = topicsDiv.scrollHeight; }; // scroll top is not rounded, heights are, so exact match won't work. // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#determine_if_an_element_has_been_totally_scrolled const toggleScroll = (element) => { const bottom = Math.abs( element.scrollHeight - element.clientHeight - element.scrollTop, ) < 2 || element.scrollHeight == element.clientHeight; if (!bottom && autoscrollEnabled) { setAutoscrollEnabled(false); } else if (bottom && !autoscrollEnabled) { setAutoscrollEnabled(true); } }; const handleScroll = (e) => { toggleScroll(e.target); }; useEffect(() => { if (autoscroll) { const topicsDiv = document.getElementById("topics-div"); topicsDiv && toggleScroll(topicsDiv); } }, [activeTopic, autoscroll]); return (
{topics.length > 0 ? ( <>

Topics

{autoscroll && ( )}
{topics.map((topic, index) => ( ))}
) : (
Discussion topics will appear here after you start recording.
It may take up to 5 minutes of conversation for the first topic to appear.
)}
); }