ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.
Python ai-agentsamdcomfyuidockerllama-cppllmlocal-ain8nnvidiaopen-webuiragself-hostedspeech-to-textstrix-halotext-to-speechworkflow-automation
import {useCallback, useLayoutEffect, useRef, useState} from 'react'
export function usePixelAutoScroll(messages, conversationId, endRef) {
const following = useRef(true)
const previousChat = useRef(conversationId)
const [showLatest, setShowLatest] = useState(false)
const onContentResize=useCallback(()=>{
const container=endRef.current?.parentElement
if(following.current && container)container.scrollTop=container.scrollHeight
},[endRef])
function jumpToLatest() {
const container = endRef.current?.parentElement
if (!container) return
following.current = true
container.scrollTop = container.scrollHeight
container.focus({preventScroll:true})
setShowLatest(false)
}
function onScroll(event) {
const container = event.currentTarget
following.current = container.scrollHeight - container.clientHeight - container.scrollTop <= 64
setShowLatest(!following.current)
}
useLayoutEffect(() => {
if (previousChat.current !== conversationId) {
previousChat.current = conversationId
following.current = true
setShowLatest(false)
}
const container = endRef.current?.parentElement
if (following.current && container) container.scrollTop = container.scrollHeight
}, [messages, conversationId, endRef])
return {onScroll, jumpToLatest, showLatest, onContentResize}
}