From 106cd21215204f6042e8b2f1aba395643640b6fc Mon Sep 17 00:00:00 2001 From: ElementalAlchemist Date: Sun, 17 Nov 2024 18:47:59 -0600 Subject: [PATCH] Chat autoscroll --- thrimbletrimmer/src/restreamer/Restreamer.tsx | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/thrimbletrimmer/src/restreamer/Restreamer.tsx b/thrimbletrimmer/src/restreamer/Restreamer.tsx index 3cc5732..8be2858 100644 --- a/thrimbletrimmer/src/restreamer/Restreamer.tsx +++ b/thrimbletrimmer/src/restreamer/Restreamer.tsx @@ -4,6 +4,7 @@ import { createResource, createSignal, For, + onCleanup, onMount, Setter, Show, @@ -100,6 +101,8 @@ const RestreamerWithDefaults: Component = (props) => { const [playerTime, setPlayerTime] = createSignal(0); const [mediaPlayer, setMediaPlayer] = createSignal(); const [videoFragments, setVideoFragments] = createSignal([]); + const [chatContainerElement, setChatContainerElement] = createSignal(); + const [chatScrolledToBottom, setChatScrolledToBottom] = createSignal(true); onMount(() => { const player = mediaPlayer(); @@ -110,6 +113,18 @@ const RestreamerWithDefaults: Component = (props) => { } }); + const chatScrollTimer = setInterval(() => { + const chatContainer = chatContainerElement(); + if (!chatContainer) { + return; + } + const autoscroll = chatScrolledToBottom(); + if (autoscroll) { + chatContainer.scrollTop = chatContainer.scrollHeight; + } + }, 100); + onCleanup(() => clearInterval(chatScrollTimer)); + const videoURL = () => { const streamInfo = streamVideoInfo(); const startTime = wubloaderTimeFromDateTime(streamInfo.streamStartTime); @@ -172,7 +187,17 @@ const RestreamerWithDefaults: Component = (props) => { Download Video Download Current Frame as Image -
+
{ + const chatContainer = event.currentTarget; + // Allow a 20 pixel buffer at the bottom of the element + setChatScrolledToBottom( + chatContainer.scrollTop + chatContainer.offsetHeight + 20 >= chatContainer.scrollHeight, + ); + }} + >