Skip to content

Commit

Permalink
Fix message list not scrolling down if close to bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
Jikstra committed Jul 14, 2020
1 parent 74c41e6 commit d1ba348
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/renderer/components/message/MessageList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, useEffect } from 'react'
import React, { useRef, useEffect, useLayoutEffect } from 'react'
import { MessageWrapper } from './MessageWrapper'
import {
useChatStore,
Expand Down Expand Up @@ -68,8 +68,8 @@ export default function MessageList({

useEffect(() => {
if (scrollToBottomIfClose === false) return

const { scrollTop, scrollHeight, clientHeight } = messageListRef.current
const scrollHeight = lastKnownScrollHeight.current
const { scrollTop, clientHeight } = messageListRef.current
const scrollBottom = scrollTop + clientHeight

const shouldScrollToBottom = scrollBottom >= scrollHeight - 7
Expand Down Expand Up @@ -122,9 +122,9 @@ export default function MessageList({
)

const onScroll = (Event: React.UIEvent<HTMLDivElement>) => {
lastKnownScrollHeight.current = messageListRef.current.scrollHeight
if (messageListRef.current.scrollTop !== 0) return
if (isFetching.current === false) {
lastKnownScrollHeight.current = messageListRef.current.scrollHeight
isFetching.current = true
log.debug('Scrolled to top, fetching more messsages!')
fetchMore()
Expand Down

0 comments on commit d1ba348

Please sign in to comment.