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"; type TopicListProps = { topics: Topic[]; useActiveTopic: [ Topic | null, React.Dispatch>, ]; }; export function TopicList({ topics, useActiveTopic }: TopicListProps) { const [activeTopic, setActiveTopic] = useActiveTopic; const [autoscrollEnabled, setAutoscrollEnabled] = useState(true); useEffect(() => { if (autoscrollEnabled) scrollToBottom(); console.log(topics); }, [topics.length]); const scrollToBottom = () => { const topicsDiv = document.getElementById("topics-div"); if (!topicsDiv) console.error("Could not find topics div to scroll to bottom"); else topicsDiv.scrollTop = topicsDiv.scrollHeight; }; const handleScroll = (e) => { const bottom = e.target.scrollHeight - e.target.scrollTop === e.target.clientHeight; if (!bottom && autoscrollEnabled) { setAutoscrollEnabled(false); } else if (bottom && !autoscrollEnabled) { setAutoscrollEnabled(true); } }; return (
{topics.length > 0 ? ( <>
{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.
)}
); }