Ver Fonte

fix(desktop): auto scroll

Adam há 3 meses atrás
pai
commit
62ffeb3987
1 ficheiros alterados com 7 adições e 1 exclusões
  1. 7 1
      packages/ui/src/components/session-turn.tsx

+ 7 - 1
packages/ui/src/components/session-turn.tsx

@@ -55,11 +55,13 @@ export function SessionTurn(
     userScrolled: false,
     userScrolled: false,
     stickyHeaderHeight: 0,
     stickyHeaderHeight: 0,
     scrollY: 0,
     scrollY: 0,
+    autoScrolling: false,
   })
   })
 
 
   function handleScroll() {
   function handleScroll() {
     if (!scrollRef) return
     if (!scrollRef) return
     setState("scrollY", scrollRef.scrollTop)
     setState("scrollY", scrollRef.scrollTop)
+    if (state.autoScrolling) return
     const { scrollTop, scrollHeight, clientHeight } = scrollRef
     const { scrollTop, scrollHeight, clientHeight } = scrollRef
     const atBottom = scrollHeight - scrollTop - clientHeight < 50
     const atBottom = scrollHeight - scrollTop - clientHeight < 50
     if (!atBottom && working()) {
     if (!atBottom && working()) {
@@ -74,9 +76,13 @@ export function SessionTurn(
   }
   }
 
 
   function scrollToBottom() {
   function scrollToBottom() {
-    if (!scrollRef || state.userScrolled || !working()) return
+    if (!scrollRef || state.userScrolled || !working() || state.autoScrolling) return
+    setState("autoScrolling", true)
     requestAnimationFrame(() => {
     requestAnimationFrame(() => {
       scrollRef?.scrollTo({ top: scrollRef.scrollHeight, behavior: "auto" })
       scrollRef?.scrollTo({ top: scrollRef.scrollHeight, behavior: "auto" })
+      requestAnimationFrame(() => {
+        setState("autoScrolling", false)
+      })
     })
     })
   }
   }