diff --git a/www/app/transcripts/scrollToBottom.tsx b/www/app/transcripts/scrollToBottom.tsx index a702ede9..5fa09039 100644 --- a/www/app/transcripts/scrollToBottom.tsx +++ b/www/app/transcripts/scrollToBottom.tsx @@ -9,15 +9,15 @@ type ScrollToBottomProps = { export default function ScrollToBottom(props: ScrollToBottomProps) { return (
{ props.handleScrollBottom(); return false; }} > - +
); } diff --git a/www/app/transcripts/topicList.tsx b/www/app/transcripts/topicList.tsx index 02bba6f7..ec78da9e 100644 --- a/www/app/transcripts/topicList.tsx +++ b/www/app/transcripts/topicList.tsx @@ -22,8 +22,7 @@ export function TopicList({ topics, useActiveTopic }: TopicListProps) { useEffect(() => { if (autoscrollEnabled) scrollToBottom(); - console.log(topics); - }, [topics.length]); + }, [topics]); const scrollToBottom = () => { const topicsDiv = document.getElementById("topics-div"); @@ -33,15 +32,28 @@ export function TopicList({ topics, useActiveTopic }: TopicListProps) { else topicsDiv.scrollTop = topicsDiv.scrollHeight; }; - const handleScroll = (e) => { + // 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 = - e.target.scrollHeight - e.target.scrollTop === e.target.clientHeight; + 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(() => { + const topicsDiv = document.getElementById("topics-div"); + + topicsDiv && toggleScroll(topicsDiv); + }, [activeTopic]); return (
@@ -60,7 +72,7 @@ export function TopicList({ topics, useActiveTopic }: TopicListProps) { {topics.map((topic, index) => (