Fix: log scroll ux

This commit is contained in:
Dreamacro 2021-10-03 20:42:27 +08:00
parent df00d1c53d
commit 44dd8c6926

View File

@ -14,12 +14,14 @@ export default function Logs () {
const { translation } = useI18n() const { translation } = useI18n()
const { t } = translation('Logs') const { t } = translation('Logs')
const logsStreamReader = useLogsStreamReader() const logsStreamReader = useLogsStreamReader()
const scrollHeightRef = useRef(listRef.current?.scrollHeight ?? 0)
useLayoutEffect(() => { useLayoutEffect(() => {
const ul = listRef.current const ul = listRef.current
if (ul != null) { if (ul != null && scrollHeightRef.current === (ul.scrollTop + ul.clientHeight)) {
ul.scrollTop = ul.scrollHeight ul.scrollTop = ul.scrollHeight - ul.clientHeight
} }
scrollHeightRef.current = ul?.scrollHeight ?? 0
}) })
useEffect(() => { useEffect(() => {